diff --git a/changelog/unreleased/set-service-transport.md b/changelog/unreleased/set-service-transport.md new file mode 100644 index 00000000000..48b6346c373 --- /dev/null +++ b/changelog/unreleased/set-service-transport.md @@ -0,0 +1,6 @@ +Enhancement: We now set the configured protocol transport for service metadata + +This allows using `dns` or `unix` as the grpc protocol for services. Requires reva changes to have an effect + +https://github.com/owncloud/ocis/pull/9490 +https://github.com/cs3org/reva/pull/4744 \ No newline at end of file diff --git a/ocis-pkg/registry/service.go b/ocis-pkg/registry/service.go index da80a891223..c527f6f82a1 100644 --- a/ocis-pkg/registry/service.go +++ b/ocis-pkg/registry/service.go @@ -8,9 +8,10 @@ import ( mRegistry "go-micro.dev/v4/registry" "go-micro.dev/v4/util/addr" + maddr "go-micro.dev/v4/util/addr" ) -func BuildGRPCService(serviceID, uuid, address string, version string) *mRegistry.Service { +func BuildGRPCService(serviceID, uuid, transport, address string, version string) *mRegistry.Service { var host string var port int @@ -22,20 +23,25 @@ func BuildGRPCService(serviceID, uuid, address string, version string) *mRegistr host = parts[0] } - addr, err := addr.Extract(host) - if err != nil { - addr = host + addr := host + if transport != "unix" { + var err error + addr, err = maddr.Extract(host) + if err != nil { + addr = host + } + addr = net.JoinHostPort(addr, fmt.Sprint(port)) } node := &mRegistry.Node{ Id: serviceID + "-" + uuid, - Address: net.JoinHostPort(addr, fmt.Sprint(port)), + Address: addr, Metadata: make(map[string]string), } node.Metadata["registry"] = GetRegistry().String() node.Metadata["server"] = "grpc" - node.Metadata["transport"] = "grpc" + node.Metadata["transport"] = transport node.Metadata["protocol"] = "grpc" return &mRegistry.Service{ diff --git a/services/app-provider/pkg/command/server.go b/services/app-provider/pkg/command/server.go index 6259e7b8498..156fc970988 100644 --- a/services/app-provider/pkg/command/server.go +++ b/services/app-provider/pkg/command/server.go @@ -82,7 +82,7 @@ func Server(cfg *config.Config) *cli.Command { sync.Trap(&gr, cancel) } - grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, uuid.Must(uuid.NewV4()).String(), cfg.GRPC.Addr, version.GetString()) + grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, uuid.Must(uuid.NewV4()).String(), cfg.GRPC.Protocol, cfg.GRPC.Addr, version.GetString()) if err := registry.RegisterService(ctx, grpcSvc, logger); err != nil { logger.Fatal().Err(err).Msg("failed to register the grpc service") } diff --git a/services/app-registry/pkg/command/server.go b/services/app-registry/pkg/command/server.go index 54bf5241035..6e73578c7aa 100644 --- a/services/app-registry/pkg/command/server.go +++ b/services/app-registry/pkg/command/server.go @@ -77,7 +77,7 @@ func Server(cfg *config.Config) *cli.Command { cancel() }) - grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, uuid.Must(uuid.NewV4()).String(), cfg.GRPC.Addr, version.GetString()) + grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, uuid.Must(uuid.NewV4()).String(), cfg.GRPC.Protocol, cfg.GRPC.Addr, version.GetString()) if err := registry.RegisterService(ctx, grpcSvc, logger); err != nil { logger.Fatal().Err(err).Msg("failed to register the grpc service") } diff --git a/services/auth-basic/pkg/command/server.go b/services/auth-basic/pkg/command/server.go index 3a7aaf312a7..8da469c7174 100644 --- a/services/auth-basic/pkg/command/server.go +++ b/services/auth-basic/pkg/command/server.go @@ -95,7 +95,7 @@ func Server(cfg *config.Config) *cli.Command { sync.Trap(&gr, cancel) } - grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, uuid.Must(uuid.NewV4()).String(), cfg.GRPC.Addr, version.GetString()) + grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, uuid.Must(uuid.NewV4()).String(), cfg.GRPC.Protocol, cfg.GRPC.Addr, version.GetString()) if err := registry.RegisterService(ctx, grpcSvc, logger); err != nil { logger.Fatal().Err(err).Msg("failed to register the grpc service") } diff --git a/services/auth-bearer/pkg/command/server.go b/services/auth-bearer/pkg/command/server.go index 5646f639914..1f5bc479d1e 100644 --- a/services/auth-bearer/pkg/command/server.go +++ b/services/auth-bearer/pkg/command/server.go @@ -82,7 +82,7 @@ func Server(cfg *config.Config) *cli.Command { sync.Trap(&gr, cancel) } - grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, uuid.Must(uuid.NewV4()).String(), cfg.GRPC.Addr, version.GetString()) + grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, uuid.Must(uuid.NewV4()).String(), cfg.GRPC.Protocol, cfg.GRPC.Addr, version.GetString()) if err := registry.RegisterService(ctx, grpcSvc, logger); err != nil { logger.Fatal().Err(err).Msg("failed to register the grpc service") } diff --git a/services/auth-machine/pkg/command/server.go b/services/auth-machine/pkg/command/server.go index e19fb45f69b..e0765a4ddb5 100644 --- a/services/auth-machine/pkg/command/server.go +++ b/services/auth-machine/pkg/command/server.go @@ -82,7 +82,7 @@ func Server(cfg *config.Config) *cli.Command { sync.Trap(&gr, cancel) } - grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, uuid.Must(uuid.NewV4()).String(), cfg.GRPC.Addr, version.GetString()) + grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, uuid.Must(uuid.NewV4()).String(), cfg.GRPC.Protocol, cfg.GRPC.Addr, version.GetString()) if err := registry.RegisterService(ctx, grpcSvc, logger); err != nil { logger.Fatal().Err(err).Msg("failed to register the grpc service") } diff --git a/services/auth-service/pkg/command/server.go b/services/auth-service/pkg/command/server.go index 565f6757476..b9e46014266 100644 --- a/services/auth-service/pkg/command/server.go +++ b/services/auth-service/pkg/command/server.go @@ -83,7 +83,7 @@ func Server(cfg *config.Config) *cli.Command { sync.Trap(&gr, cancel) } - grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, uuid.Must(uuid.NewV4()).String(), cfg.GRPC.Addr, version.GetString()) + grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, uuid.Must(uuid.NewV4()).String(), cfg.GRPC.Protocol, cfg.GRPC.Addr, version.GetString()) if err := registry.RegisterService(ctx, grpcSvc, logger); err != nil { logger.Fatal().Err(err).Msg("failed to register the grpc service") } diff --git a/services/collaboration/pkg/config/defaults/defaultconfig.go b/services/collaboration/pkg/config/defaults/defaultconfig.go index 1fd0e4e7189..3c0e64165e4 100644 --- a/services/collaboration/pkg/config/defaults/defaultconfig.go +++ b/services/collaboration/pkg/config/defaults/defaultconfig.go @@ -29,6 +29,7 @@ func DefaultConfig() *config.Config { }, GRPC: config.GRPC{ Addr: "127.0.0.1:9301", + Protocol: "tcp", Namespace: "com.owncloud.api", }, HTTP: config.HTTP{ diff --git a/services/collaboration/pkg/config/grpc.go b/services/collaboration/pkg/config/grpc.go index cf66901b724..d52d16228de 100644 --- a/services/collaboration/pkg/config/grpc.go +++ b/services/collaboration/pkg/config/grpc.go @@ -2,6 +2,8 @@ package config // GRPC defines the available grpc configuration. type GRPC struct { - Addr string `yaml:"addr" env:"COLLABORATION_GRPC_ADDR" desc:"The bind address of the GRPC service." introductionVersion:"6.0.0"` + Addr string `yaml:"addr" env:"COLLABORATION_GRPC_ADDR" desc:"The bind address of the GRPC service." introductionVersion:"6.0.0"` + Protocol string `yaml:"protocol" env:"COLLABORATION_GRPC_PROTOCOL" desc:"The transport protocol of the GRPC service." introductionVersion:"%%NEXT%%"` + Namespace string `yaml:"-"` } diff --git a/services/collaboration/pkg/helpers/registration.go b/services/collaboration/pkg/helpers/registration.go index c4967dac7d2..06c1b0d8053 100644 --- a/services/collaboration/pkg/helpers/registration.go +++ b/services/collaboration/pkg/helpers/registration.go @@ -19,7 +19,7 @@ import ( // There are no explicit requirements for the context, and it will be passed // without changes to the underlying RegisterService method. func RegisterOcisService(ctx context.Context, cfg *config.Config, logger log.Logger) error { - svc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name+"."+cfg.App.Name, uuid.Must(uuid.NewV4()).String(), cfg.GRPC.Addr, version.GetString()) + svc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name+"."+cfg.App.Name, uuid.Must(uuid.NewV4()).String(), cfg.GRPC.Protocol, cfg.GRPC.Addr, version.GetString()) return registry.RegisterService(ctx, svc, logger) } diff --git a/services/gateway/pkg/command/server.go b/services/gateway/pkg/command/server.go index ebbc7f7eb4a..ad574cbfdf5 100644 --- a/services/gateway/pkg/command/server.go +++ b/services/gateway/pkg/command/server.go @@ -77,7 +77,7 @@ func Server(cfg *config.Config) *cli.Command { cancel() }) - grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, uuid.Must(uuid.NewV4()).String(), cfg.GRPC.Addr, version.GetString()) + grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, uuid.Must(uuid.NewV4()).String(), cfg.GRPC.Protocol, cfg.GRPC.Addr, version.GetString()) if err := registry.RegisterService(ctx, grpcSvc, logger); err != nil { logger.Fatal().Err(err).Msg("failed to register the grpc service") } diff --git a/services/graph/pkg/service/v0/graph_suite_test.go b/services/graph/pkg/service/v0/graph_suite_test.go index 70dfcce1450..4234d829f9d 100644 --- a/services/graph/pkg/service/v0/graph_suite_test.go +++ b/services/graph/pkg/service/v0/graph_suite_test.go @@ -12,7 +12,7 @@ import ( func init() { r := registry.GetRegistry(registry.Inmemory()) - service := registry.BuildGRPCService("com.owncloud.api.gateway", "", "", "") + service := registry.BuildGRPCService("com.owncloud.api.gateway", "", "", "", "") service.Nodes = []*mRegistry.Node{{ Address: "any", }} diff --git a/services/groups/pkg/command/server.go b/services/groups/pkg/command/server.go index 6690ebbb118..76ae1f49fe3 100644 --- a/services/groups/pkg/command/server.go +++ b/services/groups/pkg/command/server.go @@ -95,7 +95,7 @@ func Server(cfg *config.Config) *cli.Command { sync.Trap(&gr, cancel) } - grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, uuid.Must(uuid.NewV4()).String(), cfg.GRPC.Addr, version.GetString()) + grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, uuid.Must(uuid.NewV4()).String(), cfg.GRPC.Protocol, cfg.GRPC.Addr, version.GetString()) if err := registry.RegisterService(ctx, grpcSvc, logger); err != nil { logger.Fatal().Err(err).Msg("failed to register the grpc service") } diff --git a/services/notifications/pkg/service/notification_suite_test.go b/services/notifications/pkg/service/notification_suite_test.go index 7f282054fb6..5b03187c1e3 100644 --- a/services/notifications/pkg/service/notification_suite_test.go +++ b/services/notifications/pkg/service/notification_suite_test.go @@ -12,7 +12,7 @@ import ( func init() { r := registry.GetRegistry(registry.Inmemory()) - service := registry.BuildGRPCService("com.owncloud.api.gateway", "", "", "") + service := registry.BuildGRPCService("com.owncloud.api.gateway", "", "", "", "") service.Nodes = []*mRegistry.Node{{ Address: "any", }} diff --git a/services/ocm/pkg/command/server.go b/services/ocm/pkg/command/server.go index 1025d1ce735..d3b49cfdb5b 100644 --- a/services/ocm/pkg/command/server.go +++ b/services/ocm/pkg/command/server.go @@ -83,7 +83,7 @@ func Server(cfg *config.Config) *cli.Command { sync.Trap(&gr, cancel) } - grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, uuid.Must(uuid.NewV4()).String(), cfg.GRPC.Addr, version.GetString()) + grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, uuid.Must(uuid.NewV4()).String(), cfg.GRPC.Protocol, cfg.GRPC.Addr, version.GetString()) if err := registry.RegisterService(ctx, grpcSvc, logger); err != nil { logger.Fatal().Err(err).Msg("failed to register the grpc service") } diff --git a/services/search/pkg/search/search_suite_test.go b/services/search/pkg/search/search_suite_test.go index 9422179fc53..22d772146aa 100644 --- a/services/search/pkg/search/search_suite_test.go +++ b/services/search/pkg/search/search_suite_test.go @@ -12,7 +12,7 @@ import ( func init() { r := registry.GetRegistry(registry.Inmemory()) - service := registry.BuildGRPCService("com.owncloud.api.gateway", "", "", "") + service := registry.BuildGRPCService("com.owncloud.api.gateway", "", "", "", "") service.Nodes = []*mRegistry.Node{{ Address: "any", }} diff --git a/services/sharing/pkg/command/server.go b/services/sharing/pkg/command/server.go index c0a89bfb974..a1e60957f4d 100644 --- a/services/sharing/pkg/command/server.go +++ b/services/sharing/pkg/command/server.go @@ -99,7 +99,7 @@ func Server(cfg *config.Config) *cli.Command { sync.Trap(&gr, cancel) } - grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, uuid.Must(uuid.NewV4()).String(), cfg.GRPC.Addr, version.GetString()) + grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, uuid.Must(uuid.NewV4()).String(), cfg.GRPC.Protocol, cfg.GRPC.Addr, version.GetString()) if err := registry.RegisterService(ctx, grpcSvc, logger); err != nil { logger.Fatal().Err(err).Msg("failed to register the grpc service") } diff --git a/services/storage-publiclink/pkg/command/server.go b/services/storage-publiclink/pkg/command/server.go index b0829d4728c..7173f4a5c5f 100644 --- a/services/storage-publiclink/pkg/command/server.go +++ b/services/storage-publiclink/pkg/command/server.go @@ -82,7 +82,7 @@ func Server(cfg *config.Config) *cli.Command { sync.Trap(&gr, cancel) } - grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, uuid.Must(uuid.NewV4()).String(), cfg.GRPC.Addr, version.GetString()) + grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, uuid.Must(uuid.NewV4()).String(), cfg.GRPC.Protocol, cfg.GRPC.Addr, version.GetString()) if err := registry.RegisterService(ctx, grpcSvc, logger); err != nil { logger.Fatal().Err(err).Msg("failed to register the grpc service") } diff --git a/services/storage-shares/pkg/command/server.go b/services/storage-shares/pkg/command/server.go index d7c186a1f12..5712a9a8a7f 100644 --- a/services/storage-shares/pkg/command/server.go +++ b/services/storage-shares/pkg/command/server.go @@ -82,7 +82,7 @@ func Server(cfg *config.Config) *cli.Command { sync.Trap(&gr, cancel) } - grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, uuid.Must(uuid.NewV4()).String(), cfg.GRPC.Addr, version.GetString()) + grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, uuid.Must(uuid.NewV4()).String(), cfg.GRPC.Protocol, cfg.GRPC.Addr, version.GetString()) if err := registry.RegisterService(ctx, grpcSvc, logger); err != nil { logger.Fatal().Err(err).Msg("failed to register the grpc service") } diff --git a/services/storage-system/pkg/command/server.go b/services/storage-system/pkg/command/server.go index 5424a456e9e..0d4e05e0540 100644 --- a/services/storage-system/pkg/command/server.go +++ b/services/storage-system/pkg/command/server.go @@ -82,7 +82,7 @@ func Server(cfg *config.Config) *cli.Command { sync.Trap(&gr, cancel) } - grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, uuid.Must(uuid.NewV4()).String(), cfg.GRPC.Addr, version.GetString()) + grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, uuid.Must(uuid.NewV4()).String(), cfg.GRPC.Protocol, cfg.GRPC.Addr, version.GetString()) if err := registry.RegisterService(ctx, grpcSvc, logger); err != nil { logger.Fatal().Err(err).Msg("failed to register the grpc service") } diff --git a/services/storage-users/pkg/command/server.go b/services/storage-users/pkg/command/server.go index 8a13bc78e55..fecf65338db 100644 --- a/services/storage-users/pkg/command/server.go +++ b/services/storage-users/pkg/command/server.go @@ -93,7 +93,7 @@ func Server(cfg *config.Config) *cli.Command { sync.Trap(&gr, cancel) } - grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, uuid.Must(uuid.NewV4()).String(), cfg.GRPC.Addr, version.GetString()) + grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, uuid.Must(uuid.NewV4()).String(), cfg.GRPC.Protocol, cfg.GRPC.Addr, version.GetString()) if err := registry.RegisterService(ctx, grpcSvc, logger); err != nil { logger.Fatal().Err(err).Msg("failed to register the grpc service") } diff --git a/services/storage-users/pkg/task/task_suite_test.go b/services/storage-users/pkg/task/task_suite_test.go index ac0c8a44b9d..ac5e269876d 100644 --- a/services/storage-users/pkg/task/task_suite_test.go +++ b/services/storage-users/pkg/task/task_suite_test.go @@ -12,7 +12,7 @@ import ( func init() { r := registry.GetRegistry(registry.Inmemory()) - service := registry.BuildGRPCService("com.owncloud.api.gateway", "", "", "") + service := registry.BuildGRPCService("com.owncloud.api.gateway", "", "", "", "") service.Nodes = []*mRegistry.Node{{ Address: "any", }} diff --git a/services/userlog/pkg/service/service_suit_test.go b/services/userlog/pkg/service/service_suit_test.go index 9da9654d4e9..81a91c123c4 100644 --- a/services/userlog/pkg/service/service_suit_test.go +++ b/services/userlog/pkg/service/service_suit_test.go @@ -12,7 +12,7 @@ import ( func init() { r := registry.GetRegistry(registry.Inmemory()) - service := registry.BuildGRPCService("com.owncloud.api.gateway", "", "", "") + service := registry.BuildGRPCService("com.owncloud.api.gateway", "", "", "", "") service.Nodes = []*mRegistry.Node{{ Address: "any", }} diff --git a/services/users/pkg/command/server.go b/services/users/pkg/command/server.go index 100dea31b7b..1fa8e497e83 100644 --- a/services/users/pkg/command/server.go +++ b/services/users/pkg/command/server.go @@ -95,7 +95,7 @@ func Server(cfg *config.Config) *cli.Command { sync.Trap(&gr, cancel) } - grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, uuid.Must(uuid.NewV4()).String(), cfg.GRPC.Addr, version.GetString()) + grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, uuid.Must(uuid.NewV4()).String(), cfg.GRPC.Protocol, cfg.GRPC.Addr, version.GetString()) if err := registry.RegisterService(ctx, grpcSvc, logger); err != nil { logger.Fatal().Err(err).Msg("failed to register the grpc service") }