Skip to content

Commit

Permalink
register services when they are ready
Browse files Browse the repository at this point in the history
Signed-off-by: Jörn Friedrich Dreyer <[email protected]>
  • Loading branch information
butonic committed Nov 7, 2024
1 parent 75cba42 commit 6db15f0
Show file tree
Hide file tree
Showing 19 changed files with 40 additions and 24 deletions.
3 changes: 3 additions & 0 deletions changelog/unreleased/register-when-ready.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Bugfix: wait for services to be ready before registering them

https://github.com/owncloud/ocis/pull/10498
13 changes: 11 additions & 2 deletions ocis-pkg/registry/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion services/app-registry/pkg/command/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
2 changes: 1 addition & 1 deletion services/auth-app/pkg/command/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
2 changes: 1 addition & 1 deletion services/auth-basic/pkg/command/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
2 changes: 1 addition & 1 deletion services/auth-bearer/pkg/command/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
2 changes: 1 addition & 1 deletion services/auth-machine/pkg/command/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
2 changes: 1 addition & 1 deletion services/auth-service/pkg/command/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
3 changes: 2 additions & 1 deletion services/collaboration/pkg/helpers/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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.
Expand Down
5 changes: 3 additions & 2 deletions services/frontend/pkg/command/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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.
Expand Down Expand Up @@ -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")
}

Expand Down
2 changes: 1 addition & 1 deletion services/gateway/pkg/command/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
2 changes: 1 addition & 1 deletion services/groups/pkg/command/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
4 changes: 2 additions & 2 deletions services/ocm/pkg/command/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
2 changes: 1 addition & 1 deletion services/sharing/pkg/command/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
2 changes: 1 addition & 1 deletion services/storage-publiclink/pkg/command/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
2 changes: 1 addition & 1 deletion services/storage-shares/pkg/command/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
9 changes: 5 additions & 4 deletions services/storage-system/pkg/command/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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.
Expand Down Expand Up @@ -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")
}

Expand Down
2 changes: 1 addition & 1 deletion services/storage-users/pkg/command/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
3 changes: 2 additions & 1 deletion services/users/pkg/command/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down

0 comments on commit 6db15f0

Please sign in to comment.