settings: Instanciate only a single instance of the ServiceHandler/Store

Share the same instance between the HTTP and the GRPC service. This is
in preparation for moving the cache of the metadata storage backend to a
go-micro/store based implementation. By sharing the same service instance in
the HTTP and GRPC services we can avoid the usage of global variables for the
caches, which will make the move to the go-micro/store implementation simpler.
This commit is contained in:
Ralf Haferkamp
2023-05-09 14:30:35 +02:00
committed by Ralf Haferkamp
parent 3e92e409f7
commit 18bb3dbaca
6 changed files with 46 additions and 22 deletions
+12 -1
View File
@@ -15,6 +15,7 @@ import (
"github.com/owncloud/ocis/v2/services/settings/pkg/server/debug"
"github.com/owncloud/ocis/v2/services/settings/pkg/server/grpc"
"github.com/owncloud/ocis/v2/services/settings/pkg/server/http"
svc "github.com/owncloud/ocis/v2/services/settings/pkg/service/v0"
"github.com/owncloud/ocis/v2/services/settings/pkg/tracing"
"github.com/urfave/cli/v2"
)
@@ -51,6 +52,8 @@ func Server(cfg *config.Config) *cli.Command {
mtrcs := metrics.New()
mtrcs.BuildInfo.WithLabelValues(version.GetString()).Set(1)
handle := svc.NewService(cfg, logger)
// prepare an HTTP server and add it to the group run.
httpServer, err := http.Server(
http.Name(cfg.Service.Name),
@@ -58,6 +61,7 @@ func Server(cfg *config.Config) *cli.Command {
http.Context(ctx),
http.Config(cfg),
http.Metrics(mtrcs),
http.ServiceHandler(handle),
)
if err != nil {
logger.Error().
@@ -71,7 +75,14 @@ func Server(cfg *config.Config) *cli.Command {
})
// prepare a gRPC server and add it to the group run.
grpcServer := grpc.Server(grpc.Name(cfg.Service.Name), grpc.Logger(logger), grpc.Context(ctx), grpc.Config(cfg), grpc.Metrics(mtrcs))
grpcServer := grpc.Server(
grpc.Name(cfg.Service.Name),
grpc.Logger(logger),
grpc.Context(ctx),
grpc.Config(cfg),
grpc.Metrics(mtrcs),
grpc.ServiceHandler(handle),
)
servers.Add(grpcServer.Run, func(_ error) {
logger.Info().Str("server", "grpc").Msg("Shutting down server")
cancel()