Default to in-memory registry in single-binary mode
This avoids various issues of the old "mdns" default. At least for the simple single process setup (#3134, #4597). When starting the services individually we still default to "mdns".
This commit is contained in:
committed by
Ralf Haferkamp
parent
01650a5023
commit
8f2bf0ed9c
@@ -27,6 +27,7 @@ require (
|
|||||||
github.com/go-micro/plugins/v4/registry/etcd v1.1.0
|
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/kubernetes v1.1.0
|
||||||
github.com/go-micro/plugins/v4/registry/mdns 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/registry/nats v1.1.0
|
||||||
github.com/go-micro/plugins/v4/server/grpc v1.1.1
|
github.com/go-micro/plugins/v4/server/grpc v1.1.1
|
||||||
github.com/go-micro/plugins/v4/server/http v1.1.0
|
github.com/go-micro/plugins/v4/server/http v1.1.0
|
||||||
|
|||||||
@@ -440,6 +440,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/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 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/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 h1:oqQzP5P2FkfoYZiBRuCWsKqh4BCJG6MQkxYmLw2lNrU=
|
||||||
github.com/go-micro/plugins/v4/registry/nats v1.1.0/go.mod h1:4tTfa958PiYUOZNBBNoY1awmgfxFcqQOmix8cR3UM+E=
|
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=
|
github.com/go-micro/plugins/v4/server/grpc v1.1.1 h1:7V5K8RTQhzzFsJCPkKXTJr4YrWyIw5xebUTtDY27l3k=
|
||||||
|
|||||||
@@ -3,52 +3,77 @@ package registry
|
|||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
consulr "github.com/go-micro/plugins/v4/registry/consul"
|
consulr "github.com/go-micro/plugins/v4/registry/consul"
|
||||||
etcdr "github.com/go-micro/plugins/v4/registry/etcd"
|
etcdr "github.com/go-micro/plugins/v4/registry/etcd"
|
||||||
kubernetesr "github.com/go-micro/plugins/v4/registry/kubernetes"
|
kubernetesr "github.com/go-micro/plugins/v4/registry/kubernetes"
|
||||||
mdnsr "github.com/go-micro/plugins/v4/registry/mdns"
|
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"
|
natsr "github.com/go-micro/plugins/v4/registry/nats"
|
||||||
|
|
||||||
"go-micro.dev/v4/registry"
|
"go-micro.dev/v4/registry"
|
||||||
"go-micro.dev/v4/registry/cache"
|
"go-micro.dev/v4/registry/cache"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
const (
|
||||||
registryEnv = "MICRO_REGISTRY"
|
registryEnv = "MICRO_REGISTRY"
|
||||||
registryAddressEnv = "MICRO_REGISTRY_ADDRESS"
|
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.
|
// 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
|
// 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.
|
// 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 {
|
func GetRegistry() registry.Registry {
|
||||||
addresses := strings.Split(os.Getenv(registryAddressEnv), ",")
|
once.Do(func() {
|
||||||
|
addresses := strings.Split(os.Getenv(registryAddressEnv), ",")
|
||||||
var r registry.Registry
|
// prefer env of setting from Configure()
|
||||||
switch os.Getenv(registryEnv) {
|
plugin := os.Getenv(registryEnv)
|
||||||
case "nats":
|
if plugin == "" {
|
||||||
r = natsr.NewRegistry(
|
plugin = regPlugin
|
||||||
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()
|
|
||||||
}
|
|
||||||
|
|
||||||
|
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
|
// always use cached registry to prevent registry
|
||||||
// lookup for every request
|
// lookup for every request
|
||||||
return cache.New(r, cache.WithTTL(20*time.Second))
|
return reg
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"github.com/owncloud/ocis/v2/ocis-pkg/config"
|
"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/configlog"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/config/parser"
|
"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/register"
|
||||||
"github.com/owncloud/ocis/v2/ocis/pkg/runtime"
|
"github.com/owncloud/ocis/v2/ocis/pkg/runtime"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
@@ -19,6 +20,8 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
return configlog.ReturnError(parser.ParseConfig(cfg, false))
|
return configlog.ReturnError(parser.ParseConfig(cfg, false))
|
||||||
},
|
},
|
||||||
Action: func(c *cli.Context) error {
|
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)
|
r := runtime.New(cfg)
|
||||||
return r.Start()
|
return r.Start()
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user