diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2023-09-18 11:36:35 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2023-09-19 09:48:58 +0300 |
commit | aa8dfbd189afbde91dccbd779bf367c7cf50fc05 (patch) | |
tree | d0c88d2960fe46cf443a2796fe99ef17437127d1 /internal | |
parent | 1724766e9e11c60992a07c023757b6935a74114e (diff) |
service: Simplify injection of dependencies for SmartHTTP server
While we already have a `service.Dependencies` type around for quite a
long time, we still pass in dependencies explicitly when constructing
the actual server. This makes it harder than necessary to make a server
require more dependencies as you will have to adjust all callsites where
the server is currently getting constructed.
Simplify the code to instead inject the `service.Dependencies` type into
the server directly. This will allow us to propagate dependencies more
readily in the future.
Diffstat (limited to 'internal')
-rw-r--r-- | internal/gitaly/service/setup/register.go | 6 | ||||
-rw-r--r-- | internal/gitaly/service/smarthttp/server.go | 18 | ||||
-rw-r--r-- | internal/gitaly/service/smarthttp/testhelper_test.go | 8 |
3 files changed, 8 insertions, 24 deletions
diff --git a/internal/gitaly/service/setup/register.go b/internal/gitaly/service/setup/register.go index 46d460189..9bb678bf7 100644 --- a/internal/gitaly/service/setup/register.go +++ b/internal/gitaly/service/setup/register.go @@ -63,11 +63,7 @@ func RegisterAll(srv *grpc.Server, deps *service.Dependencies) { gitalypb.RegisterSSHServiceServer(srv, ssh.NewServer(deps, ssh.WithPackfileNegotiationMetrics(sshPackfileNegotiationMetrics), )) - gitalypb.RegisterSmartHTTPServiceServer(srv, smarthttp.NewServer( - deps.GetLocator(), - deps.GetGitCmdFactory(), - deps.GetTxManager(), - deps.GetDiskCache(), + gitalypb.RegisterSmartHTTPServiceServer(srv, smarthttp.NewServer(deps, smarthttp.WithPackfileNegotiationMetrics(smarthttpPackfileNegotiationMetrics), )) gitalypb.RegisterConflictsServiceServer(srv, conflicts.NewServer( diff --git a/internal/gitaly/service/smarthttp/server.go b/internal/gitaly/service/smarthttp/server.go index c0733ae28..c58167abb 100644 --- a/internal/gitaly/service/smarthttp/server.go +++ b/internal/gitaly/service/smarthttp/server.go @@ -2,8 +2,8 @@ package smarthttp import ( "github.com/prometheus/client_golang/prometheus" - "gitlab.com/gitlab-org/gitaly/v16/internal/cache" "gitlab.com/gitlab-org/gitaly/v16/internal/git" + "gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/service" "gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/storage" "gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/transaction" "gitlab.com/gitlab-org/gitaly/v16/proto/go/gitalypb" @@ -19,22 +19,16 @@ type server struct { } // NewServer creates a new instance of a grpc SmartHTTPServer -func NewServer( - locator storage.Locator, - gitCmdFactory git.CommandFactory, - txManager transaction.Manager, - cache cache.Streamer, - serverOpts ...ServerOpt, -) gitalypb.SmartHTTPServiceServer { +func NewServer(deps *service.Dependencies, serverOpts ...ServerOpt) gitalypb.SmartHTTPServiceServer { s := &server{ - locator: locator, - gitCmdFactory: gitCmdFactory, - txManager: txManager, + locator: deps.GetLocator(), + gitCmdFactory: deps.GetGitCmdFactory(), + txManager: deps.GetTxManager(), packfileNegotiationMetrics: prometheus.NewCounterVec( prometheus.CounterOpts{}, []string{"git_negotiation_feature"}, ), - infoRefCache: newInfoRefCache(cache), + infoRefCache: newInfoRefCache(deps.GetDiskCache()), } for _, serverOpt := range serverOpts { diff --git a/internal/gitaly/service/smarthttp/testhelper_test.go b/internal/gitaly/service/smarthttp/testhelper_test.go index c3f1f9bd6..7627e21ef 100644 --- a/internal/gitaly/service/smarthttp/testhelper_test.go +++ b/internal/gitaly/service/smarthttp/testhelper_test.go @@ -26,13 +26,7 @@ func TestMain(m *testing.M) { func startSmartHTTPServerWithOptions(t *testing.T, cfg config.Cfg, opts []ServerOpt, serverOpts []testserver.GitalyServerOpt) testserver.GitalyServer { return testserver.StartGitalyServer(t, cfg, func(srv *grpc.Server, deps *service.Dependencies) { - gitalypb.RegisterSmartHTTPServiceServer(srv, NewServer( - deps.GetLocator(), - deps.GetGitCmdFactory(), - deps.GetTxManager(), - deps.GetDiskCache(), - opts..., - )) + gitalypb.RegisterSmartHTTPServiceServer(srv, NewServer(deps, opts...)) gitalypb.RegisterRepositoryServiceServer(srv, repository.NewServer(deps)) gitalypb.RegisterObjectPoolServiceServer(srv, objectpool.NewServer( deps.GetLocator(), |