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 00000000000..f7733438266 --- /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 14ffbee949b..926fd351a64 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 73b7045c651..8267ed8ea69 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 4758411a55c..651b96c65c9 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 e337309beb1..6debb8a1159 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 0a8d8bf0cb8..d451083b1fa 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 3ca39dc70e4..7e5e0b447d5 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 108948fd61a..21e8e3ccddc 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 192dc7576a0..69681fc7558 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 a6609fe20e0..33430a5d177 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 bd4a05c545b..263cb0a5672 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 2c909601f74..44e1bfa7093 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 ae4f7a045db..3e3a911c96b 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 370d419185b..3b8dd053b04 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 7e12a76729b..6d69dd9bd8e 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 9bc1283ad03..0da457507e5 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 6de970d0e45..9dd2c525cb8 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 2f9ba7e5dea..6afe0878c1c 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 a2aa036ceca..1673e301324 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 71d2d47129e..b12b0e5aca5 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") }