Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

register services after they are ready #10498

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
5 changes: 3 additions & 2 deletions services/app-provider/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/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.
Expand Down Expand Up @@ -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")
}

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