rely on MICRO_REGISTRY to swap registries

This commit is contained in:
A.Unger
2020-11-11 15:08:47 +01:00
parent 4c1f14fc47
commit d0e28b6345
8 changed files with 69 additions and 19 deletions

View File

@@ -1,7 +1,7 @@
package grpc
import (
"fmt"
"os"
"strings"
"time"
@@ -10,6 +10,9 @@ import (
"github.com/micro/go-micro/v2/client/grpc"
etcdr "github.com/micro/go-micro/v2/registry/etcd"
mdnsr "github.com/micro/go-micro/v2/registry/mdns"
"github.com/micro/go-micro/v2/registry"
"github.com/micro/go-plugins/wrapper/trace/opencensus/v2"
"github.com/owncloud/ocis/ocis-pkg/wrapper/prometheus"
@@ -18,9 +21,17 @@ import (
var DefaultClient = newGrpcClient()
func newGrpcClient() mclient.Client {
var r registry.Registry
switch os.Getenv("MICRO_REGISTRY") {
case "etcd":
r = etcdr.NewRegistry()
default:
r = mdnsr.NewRegistry()
}
c := grpc.NewClient(
mclient.RequestTimeout(10*time.Second),
mclient.Registry(etcdr.NewRegistry()), // this is a workaround and will force clients to ONLY use etcd as the registry. This needs to be configurable
mclient.Registry(r), // this is a workaround and will force clients to ONLY use etcd as the registry. This needs to be configurable
)
return c
}
@@ -33,7 +44,6 @@ type Service struct {
// NewService initializes a new grpc service.
func NewService(opts ...Option) Service {
sopts := newOptions(opts...)
fmt.Printf("\n\n%v\n\n", sopts.Name)
sopts.Logger.Info().
Str("transport", "grpc").

View File

@@ -10,6 +10,8 @@ require (
github.com/go-test/deep v1.0.6 // indirect
github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00 // indirect
github.com/micro/cli/v2 v2.1.2
github.com/micro/go-micro v1.18.0
github.com/micro/go-micro/v2 v2.9.1
github.com/micro/micro/v2 v2.8.0
github.com/openzipkin/zipkin-go v0.2.5
github.com/owncloud/flaex v0.2.0

View File

@@ -193,6 +193,7 @@ github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghf
github.com/cespare/xxhash/v2 v2.1.0/go.mod h1:dgIUBU3pDso/gPgZ1osOZ0iQf77oPR28Tjxl5dIMyVM=
github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY=
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cheekybits/genny v1.0.0 h1:uGGa4nei+j20rOSeDeP5Of12XVm7TGUd4dJA9RDitfE=
github.com/cheekybits/genny v1.0.0/go.mod h1:+tQajlRqAUrPI7DOSpB0XAqZYtQakVtB7wXkRAgjxjQ=
github.com/cheggaaa/pb v1.0.28/go.mod h1:pQciLPpbU0oxA0h+VJYYLxO+XeDQb5pZijXscXHm81s=
github.com/cheggaaa/pb v1.0.29/go.mod h1:W40334L7FMC5JKWldsTWbdGjLo0RxUKK73K+TuPxX30=
@@ -393,6 +394,7 @@ github.com/go-ldap/ldap/v3 v3.1.7/go.mod h1:5Zun81jBTabRaI8lzN7E1JjyEl1g6zI6u9pd
github.com/go-ldap/ldap/v3 v3.2.3/go.mod h1:iYS1MdmrmceOJ1QOTnRXrIs7i3kloqtmGQjRvjKpyMg=
github.com/go-ldap/ldap/v3 v3.2.4 h1:PFavAq2xTgzo/loE8qNXcQaofAaqIpI4WgaLdv+1l3E=
github.com/go-ldap/ldap/v3 v3.2.4/go.mod h1:iYS1MdmrmceOJ1QOTnRXrIs7i3kloqtmGQjRvjKpyMg=
github.com/go-log/log v0.1.0 h1:wudGTNsiGzrD5ZjgIkVZ517ugi2XRe9Q/xRCzwEO4/U=
github.com/go-log/log v0.1.0/go.mod h1:4mBwpdRMFLiuXZDCwU2lKQFsoSCo72j3HqBK9d81N2M=
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
@@ -842,6 +844,7 @@ github.com/longsleep/go-metrics v0.0.0-20191013204616-cddea569b0ea h1:Q5nKuCPF/m
github.com/longsleep/go-metrics v0.0.0-20191013204616-cddea569b0ea/go.mod h1:w6QO1LBkVla70FZrrF6XcB0YN+jTEYugjkn3+6RYTSM=
github.com/lucas-clemente/quic-go v0.12.1/go.mod h1:UXJJPE4RfFef/xPO5wQm0tITK8gNfqwTxjbE7s3Vb8s=
github.com/lucas-clemente/quic-go v0.13.1/go.mod h1:Vn3/Fb0/77b02SGhQk36KzOUmXgVpFfizUfW5WMaqyU=
github.com/lucas-clemente/quic-go v0.14.1 h1:c1aKoBZKOPA+49q96B1wGkibyPP0AxYh45WuAoq+87E=
github.com/lucas-clemente/quic-go v0.14.1/go.mod h1:Vn3/Fb0/77b02SGhQk36KzOUmXgVpFfizUfW5WMaqyU=
github.com/luna-duclos/instrumentedsql v1.1.2/go.mod h1:4LGbEqDnopzNAiyxPPDXhLspyunZxgPTMJBKtC6U0BQ=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
@@ -865,9 +868,11 @@ github.com/markbates/safe v1.0.0/go.mod h1:nAqgmRi7cY2nqMc92/bSEeQA+R4OheNU2T1kN
github.com/markbates/safe v1.0.1/go.mod h1:nAqgmRi7cY2nqMc92/bSEeQA+R4OheNU2T1kNSCBdG0=
github.com/markbates/sigtx v1.0.0/go.mod h1:QF1Hv6Ic6Ca6W+T+DL0Y/ypborFKyvUY9HmuCD4VeTc=
github.com/markbates/willie v1.0.9/go.mod h1:fsrFVWl91+gXpx/6dv715j7i11fYPfZ9ZGfH0DQzY7w=
github.com/marten-seemann/chacha20 v0.2.0 h1:f40vqzzx+3GdOmzQoItkLX5WLvHgPgyYqFFIO5Gh4hQ=
github.com/marten-seemann/chacha20 v0.2.0/go.mod h1:HSdjFau7GzYRj+ahFNwsO3ouVJr1HFkWoEwNDb4TMtE=
github.com/marten-seemann/qpack v0.1.0/go.mod h1:LFt1NU/Ptjip0C2CPkhimBz5CGE3WGDAUWqna+CNTrI=
github.com/marten-seemann/qtls v0.3.2/go.mod h1:xzjG7avBwGGbdZ8dTGxlBnLArsVKLvwmjgmPuiQEcYk=
github.com/marten-seemann/qtls v0.4.1 h1:YlT8QP3WCCvvok7MGEZkMldXbyqgr8oFg5/n8Gtbkks=
github.com/marten-seemann/qtls v0.4.1/go.mod h1:pxVXcHHw1pNIt8Qo0pwSYQEoZ8yYOOPXTCZLQQunvRc=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
@@ -927,6 +932,7 @@ github.com/micro/go-plugins v1.5.1 h1:swcFD7ynCTUo98APqIEIbPu2XMd6yVGTnI8PqdnCwO
github.com/micro/go-plugins/wrapper/trace/opencensus/v2 v2.0.1/go.mod h1:QrkcwcDtIs2hIJpIEhozekyf6Rfz5C36kFI8+zzCpX0=
github.com/micro/go-plugins/wrapper/trace/opencensus/v2 v2.9.1 h1:IaZUsLp0Omb/ozDnRKEvVY56C0UocBdPxxg2S2Pk2j0=
github.com/micro/go-plugins/wrapper/trace/opencensus/v2 v2.9.1/go.mod h1:26UmOLM/I487NqTg3n6zJiBrYmIb684M2Zp4WH98XzU=
github.com/micro/mdns v0.3.0 h1:bYycYe+98AXR3s8Nq5qvt6C573uFTDPIYzJemWON0QE=
github.com/micro/mdns v0.3.0/go.mod h1:KJ0dW7KmicXU2BV++qkLlmHYcVv7/hHnbtguSWt9Aoc=
github.com/micro/micro/v2 v2.8.0 h1:AMqpnKsOBnuGHjU0jVmTL17BRdsOx0FbvI/Gkl2uLrA=
github.com/micro/micro/v2 v2.8.0/go.mod h1:VTIGqEBLAMh22q72DnGd95iJSQY/3yvXd9GIIooQ69c=

View File

@@ -4,6 +4,12 @@ import (
"os"
"strings"
etcdr "github.com/micro/go-micro/v2/registry/etcd"
mdnsr "github.com/micro/go-micro/v2/registry/mdns"
"github.com/micro/go-micro/v2"
"github.com/micro/go-micro/v2/registry"
"github.com/micro/cli/v2"
"github.com/owncloud/ocis/ocis-pkg/log"
"github.com/owncloud/ocis/ocis/pkg/config"
@@ -14,7 +20,7 @@ import (
"github.com/spf13/viper"
)
// Execute is the entry point for the ocis-ocis command.
// Execute is the entry point for the ocis command.
func Execute() error {
cfg := config.New()
@@ -44,7 +50,19 @@ func Execute() error {
)
}
runtime.AddMicroPlatform(app)
var r registry.Registry
switch os.Getenv("MICRO_REGISTRY") {
case "etcd":
r = etcdr.NewRegistry()
default:
r = mdnsr.NewRegistry()
}
opts := micro.Options{
Registry: r,
}
runtime.AddMicroPlatform(app, opts)
cli.HelpFlag = &cli.BoolFlag{
Name: "help,h",

View File

@@ -32,7 +32,7 @@ func Server(cfg *config.Config) *cli.Command {
return err
}
r := runtime.New()
r := runtime.New(cfg)
return r.Start()
},
}

View File

@@ -55,12 +55,13 @@ type Tracing struct {
// Config combines all available configuration parts.
type Config struct {
File string
Log Log
Debug Debug
HTTP HTTP
GRPC GRPC
Tracing Tracing
File string
Registry string
Log Log
Debug Debug
HTTP HTTP
GRPC GRPC
Tracing Tracing
Accounts *accounts.Config
Graph *graph.Config

View File

@@ -55,6 +55,12 @@ func HealthWithConfig(cfg *config.Config) []cli.Flag {
// ServerWithConfig applies cfg to the root flagset
func ServerWithConfig(cfg *config.Config) []cli.Flag {
return []cli.Flag{
&cli.StringFlag{
Name: "registry",
Usage: "Enable sending traces",
EnvVars: []string{"OCIS_REGISTRY"},
Destination: &cfg.Registry,
},
&cli.BoolFlag{
Name: "tracing-enabled",
Usage: "Enable sending traces",

View File

@@ -7,6 +7,9 @@ import (
"os"
"time"
"github.com/micro/go-micro/v2"
"github.com/owncloud/ocis/ocis/pkg/config"
cli "github.com/micro/cli/v2"
"github.com/micro/micro/v2/client/api"
@@ -63,11 +66,15 @@ var (
)
// Runtime represents an oCIS runtime environment.
type Runtime struct{}
type Runtime struct {
c *config.Config
}
// New creates a new ocis + micro runtime
func New() Runtime {
return Runtime{}
func New(cfg *config.Config) Runtime {
return Runtime{
c: cfg,
}
}
// Start rpc runtime
@@ -129,12 +136,12 @@ func RunService(client *rpc.Client, service string) int {
}
// AddMicroPlatform adds the micro subcommands to the cli app
func AddMicroPlatform(app *cli.App) {
func AddMicroPlatform(app *cli.App, opts micro.Options) {
setDefaults()
app.Commands = append(app.Commands, api.Commands()...)
app.Commands = append(app.Commands, web.Commands()...)
app.Commands = append(app.Commands, registry.Commands()...)
app.Commands = append(app.Commands, api.Commands(micro.Registry(opts.Registry))...)
app.Commands = append(app.Commands, web.Commands(micro.Registry(opts.Registry))...)
app.Commands = append(app.Commands, registry.Commands(micro.Registry(opts.Registry))...)
}
// provide a config.Config with default values?