From 1a429115c2190775b88a5796fe72bd577a477c73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Thu, 7 Nov 2024 10:34:58 +0100 Subject: [PATCH] register services after they are ready MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- changelog/unreleased/register-when-ready.md | 3 +++ ocis-pkg/registry/register.go | 13 +++++++++++-- services/app-provider/pkg/command/server.go | 5 +++-- services/app-registry/pkg/command/server.go | 2 +- services/auth-app/pkg/command/server.go | 2 +- services/auth-basic/pkg/command/server.go | 2 +- services/auth-bearer/pkg/command/server.go | 2 +- services/auth-machine/pkg/command/server.go | 2 +- services/auth-service/pkg/command/server.go | 2 +- services/collaboration/pkg/helpers/registration.go | 3 ++- services/frontend/pkg/command/server.go | 5 +++-- services/gateway/pkg/command/server.go | 2 +- services/groups/pkg/command/server.go | 2 +- services/ocm/pkg/command/server.go | 4 ++-- services/sharing/pkg/command/server.go | 2 +- services/storage-publiclink/pkg/command/server.go | 2 +- services/storage-shares/pkg/command/server.go | 2 +- services/storage-system/pkg/command/server.go | 9 +++++---- services/storage-users/pkg/command/server.go | 2 +- services/users/pkg/command/server.go | 3 ++- 20 files changed, 43 insertions(+), 26 deletions(-) create mode 100644 changelog/unreleased/register-when-ready.md diff --git a/changelog/unreleased/register-when-ready.md b/changelog/unreleased/register-when-ready.md new file mode 100644 index 0000000000..f773343826 --- /dev/null +++ b/changelog/unreleased/register-when-ready.md @@ -0,0 +1,3 @@ +Bugfix: wait for services to be ready before registering them + +https://github.com/owncloud/ocis/pull/10498 diff --git a/ocis-pkg/registry/register.go b/ocis-pkg/registry/register.go index 14ffbee949..926fd351a6 100644 --- a/ocis-pkg/registry/register.go +++ b/ocis-pkg/registry/register.go @@ -2,15 +2,17 @@ package registry import ( "context" + "net/http" "time" - "github.com/owncloud/ocis/v2/ocis-pkg/log" mRegistry "go-micro.dev/v4/registry" + + "github.com/owncloud/ocis/v2/ocis-pkg/log" ) // RegisterService publishes an arbitrary endpoint to the service-registry. This allows querying nodes of // non-micro services like reva. No health-checks are done, thus the caller is responsible for canceling. -func RegisterService(ctx context.Context, service *mRegistry.Service, logger log.Logger) error { +func RegisterService(ctx context.Context, logger log.Logger, service *mRegistry.Service, debugAddr string) error { registry := GetRegistry() node := service.Nodes[0] @@ -24,6 +26,13 @@ func RegisterService(ctx context.Context, service *mRegistry.Service, logger log t := time.NewTicker(GetRegisterInterval()) go func() { + // check if the service is ready + for { + resp, err := http.DefaultClient.Get("http://" + debugAddr + "/readyz") + if err == nil && resp.StatusCode == http.StatusOK { + break + } + } for { select { case <-t.C: diff --git a/services/app-provider/pkg/command/server.go b/services/app-provider/pkg/command/server.go index 73b7045c65..8267ed8ea6 100644 --- a/services/app-provider/pkg/command/server.go +++ b/services/app-provider/pkg/command/server.go @@ -9,6 +9,8 @@ import ( "github.com/cs3org/reva/v2/cmd/revad/runtime" "github.com/gofrs/uuid" "github.com/oklog/run" + "github.com/urfave/cli/v2" + "github.com/owncloud/ocis/v2/ocis-pkg/config/configlog" "github.com/owncloud/ocis/v2/ocis-pkg/registry" "github.com/owncloud/ocis/v2/ocis-pkg/tracing" @@ -18,7 +20,6 @@ import ( "github.com/owncloud/ocis/v2/services/app-provider/pkg/logging" "github.com/owncloud/ocis/v2/services/app-provider/pkg/revaconfig" "github.com/owncloud/ocis/v2/services/app-provider/pkg/server/debug" - "github.com/urfave/cli/v2" ) // Server is the entry point for the server command. @@ -91,7 +92,7 @@ func Server(cfg *config.Config) *cli.Command { }) 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 { + if err := registry.RegisterService(ctx, logger, grpcSvc, cfg.Debug.Addr); 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 4758411a55..651b96c65c 100644 --- a/services/app-registry/pkg/command/server.go +++ b/services/app-registry/pkg/command/server.go @@ -92,7 +92,7 @@ func Server(cfg *config.Config) *cli.Command { }) 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 { + if err := registry.RegisterService(ctx, logger, grpcSvc, cfg.Debug.Addr); 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 e337309beb..6debb8a115 100644 --- a/services/auth-app/pkg/command/server.go +++ b/services/auth-app/pkg/command/server.go @@ -100,7 +100,7 @@ func Server(cfg *config.Config) *cli.Command { }) 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 { + if err := registry.RegisterService(ctx, logger, grpcSvc, cfg.Debug.Addr); 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 0a8d8bf0cb..d451083b1f 100644 --- a/services/auth-basic/pkg/command/server.go +++ b/services/auth-basic/pkg/command/server.go @@ -105,7 +105,7 @@ func Server(cfg *config.Config) *cli.Command { }) 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 { + if err := registry.RegisterService(ctx, logger, grpcSvc, cfg.Debug.Addr); 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 3ca39dc70e..7e5e0b447d 100644 --- a/services/auth-bearer/pkg/command/server.go +++ b/services/auth-bearer/pkg/command/server.go @@ -92,7 +92,7 @@ func Server(cfg *config.Config) *cli.Command { }) 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 { + if err := registry.RegisterService(ctx, logger, grpcSvc, cfg.Debug.Addr); 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 108948fd61..21e8e3ccdd 100644 --- a/services/auth-machine/pkg/command/server.go +++ b/services/auth-machine/pkg/command/server.go @@ -92,7 +92,7 @@ func Server(cfg *config.Config) *cli.Command { }) 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 { + if err := registry.RegisterService(ctx, logger, grpcSvc, cfg.Debug.Addr); 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 192dc7576a..69681fc755 100644 --- a/services/auth-service/pkg/command/server.go +++ b/services/auth-service/pkg/command/server.go @@ -93,7 +93,7 @@ func Server(cfg *config.Config) *cli.Command { }) 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 { + if err := registry.RegisterService(ctx, logger, grpcSvc, cfg.Debug.Addr); err != nil { logger.Fatal().Err(err).Msg("failed to register the grpc service") } diff --git a/services/collaboration/pkg/helpers/registration.go b/services/collaboration/pkg/helpers/registration.go index a6609fe20e..33430a5d17 100644 --- a/services/collaboration/pkg/helpers/registration.go +++ b/services/collaboration/pkg/helpers/registration.go @@ -9,6 +9,7 @@ import ( rpcv1beta1 "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" "github.com/cs3org/reva/v2/pkg/mime" "github.com/cs3org/reva/v2/pkg/rgrpc/todo/pool" + "github.com/owncloud/ocis/v2/ocis-pkg/log" "github.com/owncloud/ocis/v2/ocis-pkg/registry" "github.com/owncloud/ocis/v2/ocis-pkg/version" @@ -20,7 +21,7 @@ import ( // 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.Protocol, cfg.GRPC.Addr, version.GetString()) - return registry.RegisterService(ctx, svc, logger) + return registry.RegisterService(ctx, logger, svc, cfg.Debug.Addr) } // RegisterAppProvider will register this service as app provider in REVA. diff --git a/services/frontend/pkg/command/server.go b/services/frontend/pkg/command/server.go index bd4a05c545..263cb0a567 100644 --- a/services/frontend/pkg/command/server.go +++ b/services/frontend/pkg/command/server.go @@ -9,6 +9,8 @@ import ( "github.com/cs3org/reva/v2/cmd/revad/runtime" "github.com/gofrs/uuid" "github.com/oklog/run" + "github.com/urfave/cli/v2" + "github.com/owncloud/ocis/v2/ocis-pkg/config/configlog" "github.com/owncloud/ocis/v2/ocis-pkg/registry" "github.com/owncloud/ocis/v2/ocis-pkg/tracing" @@ -18,7 +20,6 @@ import ( "github.com/owncloud/ocis/v2/services/frontend/pkg/logging" "github.com/owncloud/ocis/v2/services/frontend/pkg/revaconfig" "github.com/owncloud/ocis/v2/services/frontend/pkg/server/debug" - "github.com/urfave/cli/v2" ) // Server is the entry point for the server command. @@ -96,7 +97,7 @@ func Server(cfg *config.Config) *cli.Command { }) httpSvc := registry.BuildHTTPService(cfg.HTTP.Namespace+"."+cfg.Service.Name, cfg.HTTP.Addr, version.GetString()) - if err := registry.RegisterService(ctx, httpSvc, logger); err != nil { + if err := registry.RegisterService(ctx, logger, httpSvc, cfg.Debug.Addr); err != nil { logger.Fatal().Err(err).Msg("failed to register the http service") } diff --git a/services/gateway/pkg/command/server.go b/services/gateway/pkg/command/server.go index 2c909601f7..44e1bfa709 100644 --- a/services/gateway/pkg/command/server.go +++ b/services/gateway/pkg/command/server.go @@ -94,7 +94,7 @@ func Server(cfg *config.Config) *cli.Command { }) 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 { + if err := registry.RegisterService(ctx, logger, grpcSvc, cfg.Debug.Addr); err != nil { logger.Fatal().Err(err).Msg("failed to register the grpc service") } diff --git a/services/groups/pkg/command/server.go b/services/groups/pkg/command/server.go index ae4f7a045d..3e3a911c96 100644 --- a/services/groups/pkg/command/server.go +++ b/services/groups/pkg/command/server.go @@ -105,7 +105,7 @@ func Server(cfg *config.Config) *cli.Command { }) 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 { + if err := registry.RegisterService(ctx, logger, grpcSvc, cfg.Debug.Addr); err != nil { logger.Fatal().Err(err).Msg("failed to register the grpc service") } diff --git a/services/ocm/pkg/command/server.go b/services/ocm/pkg/command/server.go index 370d419185..3b8dd053b0 100644 --- a/services/ocm/pkg/command/server.go +++ b/services/ocm/pkg/command/server.go @@ -93,12 +93,12 @@ func Server(cfg *config.Config) *cli.Command { }) 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 { + if err := registry.RegisterService(ctx, logger, grpcSvc, cfg.Debug.Addr); err != nil { logger.Fatal().Err(err).Msg("failed to register the grpc service") } httpSvc := registry.BuildHTTPService(cfg.HTTP.Namespace+"."+cfg.Service.Name, cfg.HTTP.Addr, version.GetString()) - if err := registry.RegisterService(ctx, httpSvc, logger); err != nil { + if err := registry.RegisterService(ctx, logger, httpSvc, cfg.Debug.Addr); err != nil { logger.Fatal().Err(err).Msg("failed to register the http service") } diff --git a/services/sharing/pkg/command/server.go b/services/sharing/pkg/command/server.go index 7e12a76729..6d69dd9bd8 100644 --- a/services/sharing/pkg/command/server.go +++ b/services/sharing/pkg/command/server.go @@ -108,7 +108,7 @@ func Server(cfg *config.Config) *cli.Command { }) 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 { + if err := registry.RegisterService(ctx, logger, grpcSvc, cfg.Debug.Addr); 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 9bc1283ad0..0da457507e 100644 --- a/services/storage-publiclink/pkg/command/server.go +++ b/services/storage-publiclink/pkg/command/server.go @@ -92,7 +92,7 @@ func Server(cfg *config.Config) *cli.Command { }) 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 { + if err := registry.RegisterService(ctx, logger, grpcSvc, cfg.Debug.Addr); 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 6de970d0e4..9dd2c525cb 100644 --- a/services/storage-shares/pkg/command/server.go +++ b/services/storage-shares/pkg/command/server.go @@ -92,7 +92,7 @@ func Server(cfg *config.Config) *cli.Command { }) 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 { + if err := registry.RegisterService(ctx, logger, grpcSvc, cfg.Debug.Addr); 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 2f9ba7e5de..6afe0878c1 100644 --- a/services/storage-system/pkg/command/server.go +++ b/services/storage-system/pkg/command/server.go @@ -9,6 +9,8 @@ import ( "github.com/cs3org/reva/v2/cmd/revad/runtime" "github.com/gofrs/uuid" "github.com/oklog/run" + "github.com/urfave/cli/v2" + "github.com/owncloud/ocis/v2/ocis-pkg/config/configlog" "github.com/owncloud/ocis/v2/ocis-pkg/registry" "github.com/owncloud/ocis/v2/ocis-pkg/tracing" @@ -18,7 +20,6 @@ import ( "github.com/owncloud/ocis/v2/services/storage-system/pkg/logging" "github.com/owncloud/ocis/v2/services/storage-system/pkg/revaconfig" "github.com/owncloud/ocis/v2/services/storage-system/pkg/server/debug" - "github.com/urfave/cli/v2" ) // Server is the entry point for the server command. @@ -92,12 +93,12 @@ func Server(cfg *config.Config) *cli.Command { }) 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 { + if err := registry.RegisterService(ctx, logger, grpcSvc, cfg.Debug.Addr); err != nil { logger.Fatal().Err(err).Msg("failed to register the grpc service") } - httpScv := registry.BuildHTTPService(cfg.HTTP.Namespace+"."+cfg.Service.Name, cfg.HTTP.Addr, version.GetString()) - if err := registry.RegisterService(ctx, httpScv, logger); err != nil { + httpSvc := registry.BuildHTTPService(cfg.HTTP.Namespace+"."+cfg.Service.Name, cfg.HTTP.Addr, version.GetString()) + if err := registry.RegisterService(ctx, logger, httpSvc, cfg.Debug.Addr); err != nil { logger.Fatal().Err(err).Msg("failed to register the http service") } diff --git a/services/storage-users/pkg/command/server.go b/services/storage-users/pkg/command/server.go index a2aa036cec..1673e30132 100644 --- a/services/storage-users/pkg/command/server.go +++ b/services/storage-users/pkg/command/server.go @@ -94,7 +94,7 @@ func Server(cfg *config.Config) *cli.Command { }) 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 { + if err := registry.RegisterService(ctx, logger, grpcSvc, cfg.Debug.Addr); err != nil { logger.Fatal().Err(err).Msg("failed to register the grpc service") } diff --git a/services/users/pkg/command/server.go b/services/users/pkg/command/server.go index 71d2d47129..b12b0e5aca 100644 --- a/services/users/pkg/command/server.go +++ b/services/users/pkg/command/server.go @@ -104,8 +104,9 @@ func Server(cfg *config.Config) *cli.Command { cancel() }) + // FIXME we should defer registering the service until we are sure that reva is running 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 { + if err := registry.RegisterService(ctx, logger, grpcSvc, cfg.Debug.Addr); err != nil { logger.Fatal().Err(err).Msg("failed to register the grpc service") }