diff --git a/changelog/unreleased/set-service-transport.md b/changelog/unreleased/set-service-transport.md new file mode 100644 index 0000000000..48b6346c37 --- /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 aebccc7520..b6f84c4442 100644 --- a/ocis-pkg/registry/service.go +++ b/ocis-pkg/registry/service.go @@ -8,10 +8,10 @@ import ( mRegistry "go-micro.dev/v4/registry" "go-micro.dev/v4/server" - "go-micro.dev/v4/util/addr" + mAddr "go-micro.dev/v4/util/addr" ) -func BuildGRPCService(serviceID, address string, version string) *mRegistry.Service { +func BuildGRPCService(serviceID, transport, address, version string) *mRegistry.Service { var host string var port int @@ -23,20 +23,25 @@ func BuildGRPCService(serviceID, address string, version string) *mRegistry.Serv 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, strconv.Itoa(port)) } node := &mRegistry.Node{ Id: serviceID + "-" + server.DefaultId, - 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{ @@ -59,7 +64,7 @@ func BuildHTTPService(serviceID, address string, version string) *mRegistry.Serv host = parts[0] } - addr, err := addr.Extract(host) + addr, err := mAddr.Extract(host) if err != nil { addr = host } diff --git a/services/app-provider/pkg/command/server.go b/services/app-provider/pkg/command/server.go index 450bb2d7ab..6d0a044ae6 100644 --- a/services/app-provider/pkg/command/server.go +++ b/services/app-provider/pkg/command/server.go @@ -81,7 +81,7 @@ func Server(cfg *config.Config) *cli.Command { sync.Trap(&gr, cancel) } - grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, cfg.GRPC.Addr, version.GetString()) + grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, 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 b8d1a790bf..0a85ce0346 100644 --- a/services/app-registry/pkg/command/server.go +++ b/services/app-registry/pkg/command/server.go @@ -76,7 +76,7 @@ func Server(cfg *config.Config) *cli.Command { cancel() }) - grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, cfg.GRPC.Addr, version.GetString()) + grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, 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-app/pkg/command/server.go b/services/auth-app/pkg/command/server.go index 77cb36431a..f70aa4e8c9 100644 --- a/services/auth-app/pkg/command/server.go +++ b/services/auth-app/pkg/command/server.go @@ -89,7 +89,7 @@ func Server(cfg *config.Config) *cli.Command { sync.Trap(&gr, cancel) } - grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, cfg.GRPC.Addr, version.GetString()) + grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, 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 a89ccb5326..084fce012f 100644 --- a/services/auth-basic/pkg/command/server.go +++ b/services/auth-basic/pkg/command/server.go @@ -94,7 +94,7 @@ func Server(cfg *config.Config) *cli.Command { sync.Trap(&gr, cancel) } - grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, cfg.GRPC.Addr, version.GetString()) + grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, 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 1c8e239b3a..00652d312f 100644 --- a/services/auth-bearer/pkg/command/server.go +++ b/services/auth-bearer/pkg/command/server.go @@ -81,7 +81,7 @@ func Server(cfg *config.Config) *cli.Command { sync.Trap(&gr, cancel) } - grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, cfg.GRPC.Addr, version.GetString()) + grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, 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 0a4dcbb59b..d90e68b763 100644 --- a/services/auth-machine/pkg/command/server.go +++ b/services/auth-machine/pkg/command/server.go @@ -81,7 +81,7 @@ func Server(cfg *config.Config) *cli.Command { sync.Trap(&gr, cancel) } - grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, cfg.GRPC.Addr, version.GetString()) + grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, 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 58ab0dde1d..2f013c8295 100644 --- a/services/auth-service/pkg/command/server.go +++ b/services/auth-service/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, cfg.GRPC.Addr, version.GetString()) + grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, 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 19e5618f23..7ff01181f8 100644 --- a/services/collaboration/pkg/config/defaults/defaultconfig.go +++ b/services/collaboration/pkg/config/defaults/defaultconfig.go @@ -33,6 +33,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 cf66901b72..d52d16228d 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 321a1947c1..d9ea9459c2 100644 --- a/services/collaboration/pkg/helpers/registration.go +++ b/services/collaboration/pkg/helpers/registration.go @@ -18,7 +18,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, cfg.GRPC.Addr, version.GetString()) + svc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name+"."+cfg.App.Name, 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 9f556d556e..01b2742599 100644 --- a/services/gateway/pkg/command/server.go +++ b/services/gateway/pkg/command/server.go @@ -81,7 +81,7 @@ func Server(cfg *config.Config) *cli.Command { cancel() }) - grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, cfg.GRPC.Addr, version.GetString()) + grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, 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 8446bc9b69..70dfcce145 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 cd6dffcb6d..cdd3db0ec2 100644 --- a/services/groups/pkg/command/server.go +++ b/services/groups/pkg/command/server.go @@ -94,7 +94,7 @@ func Server(cfg *config.Config) *cli.Command { sync.Trap(&gr, cancel) } - grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, cfg.GRPC.Addr, version.GetString()) + grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, 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 e045e43981..7f282054fb 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 6dc234fda9..2e28cccedc 100644 --- a/services/ocm/pkg/command/server.go +++ b/services/ocm/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, cfg.GRPC.Addr, version.GetString()) + grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, 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 ace85d9294..9422179fc5 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 5fc2bf58c5..73292fd3c2 100644 --- a/services/sharing/pkg/command/server.go +++ b/services/sharing/pkg/command/server.go @@ -98,7 +98,7 @@ func Server(cfg *config.Config) *cli.Command { sync.Trap(&gr, cancel) } - grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, cfg.GRPC.Addr, version.GetString()) + grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, 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 64551f0366..184254cb9f 100644 --- a/services/storage-publiclink/pkg/command/server.go +++ b/services/storage-publiclink/pkg/command/server.go @@ -81,7 +81,7 @@ func Server(cfg *config.Config) *cli.Command { sync.Trap(&gr, cancel) } - grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, cfg.GRPC.Addr, version.GetString()) + grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, 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 4cc258a84a..bdeabf0e2d 100644 --- a/services/storage-shares/pkg/command/server.go +++ b/services/storage-shares/pkg/command/server.go @@ -81,7 +81,7 @@ func Server(cfg *config.Config) *cli.Command { sync.Trap(&gr, cancel) } - grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, cfg.GRPC.Addr, version.GetString()) + grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, 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 369f2a5ad7..5195280e41 100644 --- a/services/storage-system/pkg/command/server.go +++ b/services/storage-system/pkg/command/server.go @@ -81,7 +81,7 @@ func Server(cfg *config.Config) *cli.Command { sync.Trap(&gr, cancel) } - grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, cfg.GRPC.Addr, version.GetString()) + grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, 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 c4b4137910..df7fca8a4b 100644 --- a/services/storage-users/pkg/command/server.go +++ b/services/storage-users/pkg/command/server.go @@ -92,7 +92,7 @@ func Server(cfg *config.Config) *cli.Command { sync.Trap(&gr, cancel) } - grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, cfg.GRPC.Addr, version.GetString()) + grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, 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 3837277808..ac0c8a44b9 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 d049672b76..9da9654d4e 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 92094a627a..95a899873d 100644 --- a/services/users/pkg/command/server.go +++ b/services/users/pkg/command/server.go @@ -94,7 +94,7 @@ func Server(cfg *config.Config) *cli.Command { sync.Trap(&gr, cancel) } - grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, cfg.GRPC.Addr, version.GetString()) + grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, 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") }