Skip to content

Commit

Permalink
Default to in-memory registry in single-binary mode
Browse files Browse the repository at this point in the history
This avoids various issues of the old "mdns" default. At least for the simple
single process setup (owncloud#3258, owncloud#4597). When starting the services individually we
still default to "mdns".
  • Loading branch information
rhafer committed Sep 21, 2022
1 parent 628de0f commit 9d63d04
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 27 deletions.
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ require (
github.com/go-micro/plugins/v4/registry/etcd v1.1.0
github.com/go-micro/plugins/v4/registry/kubernetes v1.1.0
github.com/go-micro/plugins/v4/registry/mdns v1.1.0
github.com/go-micro/plugins/v4/registry/memory v1.1.0
github.com/go-micro/plugins/v4/registry/nats v1.1.0
github.com/go-micro/plugins/v4/server/grpc v1.1.1
github.com/go-micro/plugins/v4/server/http v1.1.0
Expand Down Expand Up @@ -279,3 +280,6 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
stash.kopano.io/kgol/kcc-go/v5 v5.0.1 // indirect
)

// https://github.com/cs3org/reva/pull/3258
replace github.com/cs3org/reva/v2 => github.com/rhafer/reva/v2 v2.0.0-20220921153127-9b2a5ce8d544
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,6 @@ github.com/crewjam/saml v0.4.6 h1:XCUFPkQSJLvzyl4cW9OvpWUbRf0gE7VUpU8ZnilbeM4=
github.com/crewjam/saml v0.4.6/go.mod h1:ZBOXnNPFzB3CgOkRm7Nd6IVdkG+l/wF+0ZXLqD96t1A=
github.com/cs3org/go-cs3apis v0.0.0-20220818202316-e92afdddac6d h1:toyZ7IsXlUdEPZ/IG8fg7hbM8HcLPY0bkX4FKBmgLVI=
github.com/cs3org/go-cs3apis v0.0.0-20220818202316-e92afdddac6d/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY=
github.com/cs3org/reva/v2 v2.10.1-0.20220921105358-a098879574c0 h1:imOxcw4kha2WlNGOyBN7FbiAL4zQSlrdeqaNh5ZbeJ4=
github.com/cs3org/reva/v2 v2.10.1-0.20220921105358-a098879574c0/go.mod h1:+BYVpRV8g1hL8wF3+3BunL9BKPsXVyJYmH8COxq/V7Y=
github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8 h1:Z9lwXumT5ACSmJ7WGnFl+OMLLjpz5uR2fyz7dC255FI=
github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8/go.mod h1:4abs/jPXcmJzYoYGF91JF9Uq9s/KL5n1jvFDix8KcqY=
github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4=
Expand Down Expand Up @@ -434,6 +432,8 @@ github.com/go-micro/plugins/v4/registry/kubernetes v1.1.0 h1:JfkrimhACDviPtKT7Fh
github.com/go-micro/plugins/v4/registry/kubernetes v1.1.0/go.mod h1:6SNUr4g/JTzmR8OWU1KaIOS+lCFaqDnCRvbH3L5uUro=
github.com/go-micro/plugins/v4/registry/mdns v1.1.0 h1:qRB93cviMeY4n3/r9T/5zJF3PF+Ol5tw/VW5e6TSG4s=
github.com/go-micro/plugins/v4/registry/mdns v1.1.0/go.mod h1:k71V05hytGwaO3jqKKf8NmBPo07NFlCLmeIwPNr6n50=
github.com/go-micro/plugins/v4/registry/memory v1.1.0 h1:omyL8l12mzNCjNSDxMkAReEWOiv58j62X7sIa6aRCj8=
github.com/go-micro/plugins/v4/registry/memory v1.1.0/go.mod h1:7gsV2dwpFr+1rFhncmnxA9Tjv/NjQr9Zy8KpVKS7/jQ=
github.com/go-micro/plugins/v4/registry/nats v1.1.0 h1:oqQzP5P2FkfoYZiBRuCWsKqh4BCJG6MQkxYmLw2lNrU=
github.com/go-micro/plugins/v4/registry/nats v1.1.0/go.mod h1:4tTfa958PiYUOZNBBNoY1awmgfxFcqQOmix8cR3UM+E=
github.com/go-micro/plugins/v4/server/grpc v1.1.1 h1:7V5K8RTQhzzFsJCPkKXTJr4YrWyIw5xebUTtDY27l3k=
Expand Down Expand Up @@ -1071,6 +1071,8 @@ github.com/prometheus/statsd_exporter v0.22.4/go.mod h1:N4Z1+iSqc9rnxlT1N8Qn3l65
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
github.com/rainycape/memcache v0.0.0-20150622160815-1031fa0ce2f2/go.mod h1:7tZKcyumwBO6qip7RNQ5r77yrssm9bfCowcLEBcU5IA=
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
github.com/rhafer/reva/v2 v2.0.0-20220921153127-9b2a5ce8d544 h1:9jfeOrWevcoML8QU193bTH2PStOaLCxzhUmxzmIo3h8=
github.com/rhafer/reva/v2 v2.0.0-20220921153127-9b2a5ce8d544/go.mod h1:+BYVpRV8g1hL8wF3+3BunL9BKPsXVyJYmH8COxq/V7Y=
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
Expand Down
75 changes: 50 additions & 25 deletions ocis-pkg/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,77 @@ package registry
import (
"os"
"strings"
"sync"
"time"

consulr "github.com/go-micro/plugins/v4/registry/consul"
etcdr "github.com/go-micro/plugins/v4/registry/etcd"
kubernetesr "github.com/go-micro/plugins/v4/registry/kubernetes"
mdnsr "github.com/go-micro/plugins/v4/registry/mdns"
memr "github.com/go-micro/plugins/v4/registry/memory"
natsr "github.com/go-micro/plugins/v4/registry/nats"

"go-micro.dev/v4/registry"
"go-micro.dev/v4/registry/cache"
)

var (
const (
registryEnv = "MICRO_REGISTRY"
registryAddressEnv = "MICRO_REGISTRY_ADDRESS"
)

var (
once sync.Once
regPlugin string
reg registry.Registry
)

func Configure(plugin string) {
if reg == nil {
regPlugin = plugin
}
}

// GetRegistry returns a configured micro registry based on Micro env vars.
// It defaults to mDNS, so mind that systems with mDNS disabled by default (i.e SUSE) will have a hard time
// and it needs to explicitly use etcd. Os awareness for providing a working registry out of the box should be done.
func GetRegistry() registry.Registry {
addresses := strings.Split(os.Getenv(registryAddressEnv), ",")

var r registry.Registry
switch os.Getenv(registryEnv) {
case "nats":
r = natsr.NewRegistry(
registry.Addrs(addresses...),
)
case "kubernetes":
r = kubernetesr.NewRegistry(
registry.Addrs(addresses...),
)
case "etcd":
r = etcdr.NewRegistry(
registry.Addrs(addresses...),
)
case "consul":
r = consulr.NewRegistry(
registry.Addrs(addresses...),
)
default:
r = mdnsr.NewRegistry()
}
once.Do(func() {
addresses := strings.Split(os.Getenv(registryAddressEnv), ",")
// prefer env of setting from Configure()
plugin := os.Getenv(registryEnv)
if plugin == "" {
plugin = regPlugin
}

switch plugin {
case "nats":
reg = natsr.NewRegistry(
registry.Addrs(addresses...),
)
case "kubernetes":
reg = kubernetesr.NewRegistry(
registry.Addrs(addresses...),
)
case "etcd":
reg = etcdr.NewRegistry(
registry.Addrs(addresses...),
)
case "consul":
reg = consulr.NewRegistry(
registry.Addrs(addresses...),
)
case "memory":
reg = memr.NewRegistry()
default:
reg = mdnsr.NewRegistry()
}
// No cache needed for in-memory registry
if plugin == "memory" {
reg = cache.New(reg, cache.WithTTL(20*time.Second))
}
})
// always use cached registry to prevent registry
// lookup for every request
return cache.New(r, cache.WithTTL(20*time.Second))
return reg
}
3 changes: 3 additions & 0 deletions ocis/pkg/command/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/owncloud/ocis/v2/ocis-pkg/config"
"github.com/owncloud/ocis/v2/ocis-pkg/config/configlog"
"github.com/owncloud/ocis/v2/ocis-pkg/config/parser"
"github.com/owncloud/ocis/v2/ocis-pkg/registry"
"github.com/owncloud/ocis/v2/ocis/pkg/register"
"github.com/owncloud/ocis/v2/ocis/pkg/runtime"
"github.com/urfave/cli/v2"
Expand All @@ -19,6 +20,8 @@ func Server(cfg *config.Config) *cli.Command {
return configlog.ReturnError(parser.ParseConfig(cfg, false))
},
Action: func(c *cli.Context) error {
// Prefer the in-memory registry as the default when running in single-binary mode
registry.Configure("memory")
r := runtime.New(cfg)
return r.Start()
},
Expand Down

0 comments on commit 9d63d04

Please sign in to comment.