Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Cai <jcai@gitlab.com>2020-04-09 19:57:32 +0300
committerJohn Cai <jcai@gitlab.com>2020-04-09 19:57:32 +0300
commited0edf396da0d62aeec607ee4988e19bec36ea30 (patch)
tree2cb1a2958bebd00a6e1bb1b4b95fdcf1605a0991
parentc8d2d381229efea2a095ece2b970ec27678bf5f2 (diff)
parenta72a71e3715ca6498adb4a22ef06d360f664ba21 (diff)
Merge branch 'jc-fix-praefect-server-info' into 'master'
Modify Praefect's server info implementation Closes #2596 See merge request gitlab-org/gitaly!1991
-rw-r--r--changelogs/unreleased/jc-fix-praefect-server-info.yml5
-rw-r--r--cmd/gitaly-ssh/auth_test.go10
-rw-r--r--cmd/gitaly-ssh/upload_pack_test.go3
-rw-r--r--internal/bootstrap/server_factory.go5
-rw-r--r--internal/praefect/helper_test.go14
-rw-r--r--internal/praefect/replicator_test.go2
-rw-r--r--internal/praefect/server_test.go3
-rw-r--r--internal/praefect/service/server/info.go82
-rw-r--r--internal/server/auth_test.go4
-rw-r--r--internal/server/server.go12
-rw-r--r--internal/service/conflicts/resolve_conflicts_test.go3
-rw-r--r--internal/service/operations/cherry_pick_test.go3
-rw-r--r--internal/service/register.go4
-rw-r--r--internal/service/remote/fetch_internal_remote_test.go3
-rw-r--r--internal/service/repository/fetch_test.go4
-rw-r--r--internal/service/server/disk_stats_test.go2
-rw-r--r--internal/service/server/info.go3
-rw-r--r--internal/service/server/info_test.go19
-rw-r--r--internal/service/server/server.go10
19 files changed, 121 insertions, 70 deletions
diff --git a/changelogs/unreleased/jc-fix-praefect-server-info.yml b/changelogs/unreleased/jc-fix-praefect-server-info.yml
new file mode 100644
index 000000000..828390ca6
--- /dev/null
+++ b/changelogs/unreleased/jc-fix-praefect-server-info.yml
@@ -0,0 +1,5 @@
+---
+title: Modify Praefect's server info implementation
+merge_request: 1991
+author:
+type: fixed
diff --git a/cmd/gitaly-ssh/auth_test.go b/cmd/gitaly-ssh/auth_test.go
index 55bac2e2f..1956400f2 100644
--- a/cmd/gitaly-ssh/auth_test.go
+++ b/cmd/gitaly-ssh/auth_test.go
@@ -39,13 +39,13 @@ func TestConnectivity(t *testing.T) {
require.NoError(t, os.RemoveAll(relativeSocketPath))
require.NoError(t, os.Symlink(socketPath, relativeSocketPath))
- tcpServer, tcpPort := runServer(t, server.NewInsecure, "tcp", "localhost:0")
+ tcpServer, tcpPort := runServer(t, server.NewInsecure, config.Config, "tcp", "localhost:0")
defer tcpServer.Stop()
- tlsServer, tlsPort := runServer(t, server.NewSecure, "tcp", "localhost:0")
+ tlsServer, tlsPort := runServer(t, server.NewSecure, config.Config, "tcp", "localhost:0")
defer tlsServer.Stop()
- unixServer, _ := runServer(t, server.NewInsecure, "unix", socketPath)
+ unixServer, _ := runServer(t, server.NewInsecure, config.Config, "unix", socketPath)
defer unixServer.Stop()
testCases := []struct {
@@ -116,8 +116,8 @@ func TestConnectivity(t *testing.T) {
}
}
-func runServer(t *testing.T, newServer func(rubyServer *rubyserver.Server) *grpc.Server, connectionType string, addr string) (*grpc.Server, int) {
- srv := newServer(nil)
+func runServer(t *testing.T, newServer func(rubyServer *rubyserver.Server, cfg config.Cfg) *grpc.Server, cfg config.Cfg, connectionType string, addr string) (*grpc.Server, int) {
+ srv := newServer(nil, cfg)
listener, err := net.Listen(connectionType, addr)
require.NoError(t, err)
diff --git a/cmd/gitaly-ssh/upload_pack_test.go b/cmd/gitaly-ssh/upload_pack_test.go
index 80c12e9e9..8d528cd87 100644
--- a/cmd/gitaly-ssh/upload_pack_test.go
+++ b/cmd/gitaly-ssh/upload_pack_test.go
@@ -8,6 +8,7 @@ import (
"github.com/golang/protobuf/jsonpb"
"github.com/stretchr/testify/require"
+ "gitlab.com/gitlab-org/gitaly/internal/config"
"gitlab.com/gitlab-org/gitaly/internal/git"
"gitlab.com/gitlab-org/gitaly/internal/git/updateref"
"gitlab.com/gitlab-org/gitaly/internal/server"
@@ -41,7 +42,7 @@ func TestVisibilityOfHiddenRefs(t *testing.T) {
socketPath := testhelper.GetTemporaryGitalySocketFileName()
- unixServer, _ := runServer(t, server.NewInsecure, "unix", socketPath)
+ unixServer, _ := runServer(t, server.NewInsecure, config.Config, "unix", socketPath)
defer unixServer.Stop()
wd, err := os.Getwd()
diff --git a/internal/bootstrap/server_factory.go b/internal/bootstrap/server_factory.go
index c754fbf53..30bfea16b 100644
--- a/internal/bootstrap/server_factory.go
+++ b/internal/bootstrap/server_factory.go
@@ -4,6 +4,7 @@ import (
"net"
"sync"
+ "gitlab.com/gitlab-org/gitaly/internal/config"
"gitlab.com/gitlab-org/gitaly/internal/rubyserver"
"gitlab.com/gitlab-org/gitaly/internal/server"
"google.golang.org/grpc"
@@ -68,14 +69,14 @@ func (s *GitalyServerFactory) Serve(l net.Listener, secure bool) error {
func (s *GitalyServerFactory) get(secure bool) *grpc.Server {
if secure {
if s.secure == nil {
- s.secure = server.NewSecure(s.ruby)
+ s.secure = server.NewSecure(s.ruby, config.Config)
}
return s.secure
}
if s.insecure == nil {
- s.insecure = server.NewInsecure(s.ruby)
+ s.insecure = server.NewInsecure(s.ruby, config.Config)
}
return s.insecure
diff --git a/internal/praefect/helper_test.go b/internal/praefect/helper_test.go
index 080308fb8..28fe74ce2 100644
--- a/internal/praefect/helper_test.go
+++ b/internal/praefect/helper_test.go
@@ -167,7 +167,15 @@ func runPraefectServerWithGitaly(t *testing.T, conf config.Config) (*grpc.Client
require.Len(t, conf.VirtualStorages, 1)
var cleanups []testhelper.Cleanup
- _, backendAddr, cleanupGitaly := runInternalGitalyServer(t, conf.VirtualStorages[0].Nodes[0].Token)
+ var storages []gconfig.Storage
+ for _, node := range conf.VirtualStorages[0].Nodes {
+ storages = append(storages, gconfig.Storage{
+ Name: node.Storage,
+ Path: testhelper.GitlabTestStoragePath(),
+ })
+ }
+
+ _, backendAddr, cleanupGitaly := runInternalGitalyServer(t, storages, conf.VirtualStorages[0].Nodes[0].Token)
cleanups = append(cleanups, cleanupGitaly)
for i, node := range conf.VirtualStorages[0].Nodes {
@@ -233,7 +241,7 @@ func runPraefectServerWithGitaly(t *testing.T, conf config.Config) (*grpc.Client
return cc, prf, cleanup
}
-func runInternalGitalyServer(t *testing.T, token string) (*grpc.Server, string, func()) {
+func runInternalGitalyServer(t *testing.T, storages []gconfig.Storage, token string) (*grpc.Server, string, func()) {
streamInt := []grpc.StreamServerInterceptor{auth.StreamServerInterceptor(internalauth.Config{Token: token})}
unaryInt := []grpc.UnaryServerInterceptor{auth.UnaryServerInterceptor(internalauth.Config{Token: token})}
@@ -247,7 +255,7 @@ func runInternalGitalyServer(t *testing.T, token string) (*grpc.Server, string,
internalListener, err := net.Listen("unix", internalSocket)
require.NoError(t, err)
- gitalypb.RegisterServerServiceServer(server, gitalyserver.NewServer())
+ gitalypb.RegisterServerServiceServer(server, gitalyserver.NewServer(storages))
gitalypb.RegisterRepositoryServiceServer(server, repository.NewServer(RubyServer, internalSocket))
gitalypb.RegisterInternalGitalyServer(server, internalgitaly.NewServer(gconfig.Config.Storages))
healthpb.RegisterHealthServer(server, health.NewServer())
diff --git a/internal/praefect/replicator_test.go b/internal/praefect/replicator_test.go
index 3a03440de..0a2830a4e 100644
--- a/internal/praefect/replicator_test.go
+++ b/internal/praefect/replicator_test.go
@@ -706,7 +706,7 @@ func TestBackoff(t *testing.T) {
}
func runFullGitalyServer(t *testing.T) (*grpc.Server, string) {
- server := serverPkg.NewInsecure(RubyServer)
+ server := serverPkg.NewInsecure(RubyServer, gitaly_config.Config)
serverSocketPath := testhelper.GetTemporaryGitalySocketFileName()
diff --git a/internal/praefect/server_test.go b/internal/praefect/server_test.go
index 5dc429c80..f0f3fac88 100644
--- a/internal/praefect/server_test.go
+++ b/internal/praefect/server_test.go
@@ -105,7 +105,8 @@ func TestGitalyServerInfo(t *testing.T) {
metadata, err := client.ServerInfo(ctx, &gitalypb.ServerInfoRequest{})
require.NoError(t, err)
- require.Len(t, metadata.GetStorageStatuses(), len(conf.VirtualStorages[0].Nodes))
+ require.Len(t, metadata.GetStorageStatuses(), len(conf.VirtualStorages))
+ require.Equal(t, conf.VirtualStorages[0].Name, metadata.GetStorageStatuses()[0].StorageName)
require.Equal(t, version.GetVersion(), metadata.GetServerVersion())
gitVersion, err := git.Version()
diff --git a/internal/praefect/service/server/info.go b/internal/praefect/service/server/info.go
index 5ec8a2c4e..27a7f6c2b 100644
--- a/internal/praefect/service/server/info.go
+++ b/internal/praefect/service/server/info.go
@@ -6,7 +6,6 @@ import (
"github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus"
"gitlab.com/gitlab-org/gitaly/internal/helper"
- "gitlab.com/gitlab-org/gitaly/internal/praefect/nodes"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
"golang.org/x/sync/errgroup"
)
@@ -16,8 +15,13 @@ import (
func (s *Server) ServerInfo(ctx context.Context, in *gitalypb.ServerInfoRequest) (*gitalypb.ServerInfoResponse, error) {
var once sync.Once
- var nodes []nodes.Node
- for _, virtualStorage := range s.conf.VirtualStorages {
+ var gitVersion, serverVersion string
+
+ g, ctx := errgroup.WithContext(ctx)
+
+ storageStatuses := make([]*gitalypb.ServerInfoResponse_StorageStatus, len(s.conf.VirtualStorages))
+
+ for i, virtualStorage := range s.conf.VirtualStorages {
shard, err := s.nodeMgr.GetShard(virtualStorage.Name)
if err != nil {
return nil, err
@@ -28,32 +32,48 @@ func (s *Server) ServerInfo(ctx context.Context, in *gitalypb.ServerInfoRequest)
return nil, err
}
- secondaries, err := shard.GetSecondaries()
- if err != nil {
- return nil, err
- }
-
- nodes = append(append(nodes, primary), secondaries...)
- }
- var gitVersion, serverVersion string
-
- g, ctx := errgroup.WithContext(ctx)
-
- storageStatuses := make([][]*gitalypb.ServerInfoResponse_StorageStatus, len(nodes))
-
- for i, node := range nodes {
i := i
- node := node
+ virtualStorage := virtualStorage
g.Go(func() error {
- client := gitalypb.NewServerServiceClient(node.GetConnection())
+ client := gitalypb.NewServerServiceClient(primary.GetConnection())
resp, err := client.ServerInfo(ctx, &gitalypb.ServerInfoRequest{})
if err != nil {
- ctxlogrus.Extract(ctx).WithField("storage", node.GetStorage()).WithError(err).Error("error getting sever info")
+ ctxlogrus.Extract(ctx).WithField("storage", primary.GetStorage()).WithError(err).Error("error getting server info")
return nil
}
- storageStatuses[i] = resp.GetStorageStatuses()
+ // From the perspective of the praefect client, a server info call should result in the server infos
+ // of virtual storages. Each virtual storage has one or more nodes, but only the primary node's server info
+ // needs to be returned. It's a common pattern in gitaly configs for all gitaly nodes in a fleet to use the same config.toml
+ // whereby there are many storage names but only one of them is actually used by any given gitaly node:
+ //
+ // below is the config.toml for all three internal gitaly nodes
+ // [[storage]]
+ // name = "internal-gitaly-0"
+ // path = "/var/opt/gitlab/git-data"
+ //
+ // [storage]]
+ // name = "internal-gitaly-1"
+ // path = "/var/opt/gitlab/git-data"
+ //
+ // [[storage]]
+ // name = "internal-gitaly-2"
+ // path = "/var/opt/gitlab/git-data"
+ //
+ // technically, any storage's storage status can be returned in the virtual storage's server info,
+ // but to be consistent we will choose the storage with the same name as the internal gitaly storage name.
+ for _, storageStatus := range resp.GetStorageStatuses() {
+ if storageStatus.StorageName == primary.GetStorage() {
+ storageStatuses[i] = storageStatus
+ // the storage name in the response needs to be rewritten to be the virtual storage name
+ // because the praefect client has no concept of internal gitaly nodes that are behind praefect.
+ // From the perspective of the praefect client, the primary internal gitaly node's storage status is equivalent
+ // to the virtual storage's storage status.
+ storageStatuses[i].StorageName = virtualStorage.Name
+ break
+ }
+ }
once.Do(func() {
gitVersion, serverVersion = resp.GetGitVersion(), resp.GetServerVersion()
@@ -67,13 +87,21 @@ func (s *Server) ServerInfo(ctx context.Context, in *gitalypb.ServerInfoRequest)
return nil, helper.ErrInternal(err)
}
- var response gitalypb.ServerInfoResponse
+ return &gitalypb.ServerInfoResponse{
+ ServerVersion: serverVersion,
+ GitVersion: gitVersion,
+ StorageStatuses: filterEmptyStorageStatuses(storageStatuses),
+ }, nil
+}
+
+func filterEmptyStorageStatuses(storageStatuses []*gitalypb.ServerInfoResponse_StorageStatus) []*gitalypb.ServerInfoResponse_StorageStatus {
+ var n int
for _, storageStatus := range storageStatuses {
- response.StorageStatuses = append(response.StorageStatuses, storageStatus...)
+ if storageStatus != nil {
+ storageStatuses[n] = storageStatus
+ n++
+ }
}
-
- response.GitVersion, response.ServerVersion = gitVersion, serverVersion
-
- return &response, nil
+ return storageStatuses[:n]
}
diff --git a/internal/server/auth_test.go b/internal/server/auth_test.go
index 9366d2ada..1c34ebb43 100644
--- a/internal/server/auth_test.go
+++ b/internal/server/auth_test.go
@@ -187,7 +187,7 @@ func healthCheck(conn *grpc.ClientConn) error {
}
func runServer(t *testing.T) (*grpc.Server, string) {
- srv := NewInsecure(nil)
+ srv := NewInsecure(nil, config.Config)
serverSocketPath := testhelper.GetTemporaryGitalySocketFileName()
@@ -204,7 +204,7 @@ func runSecureServer(t *testing.T) (*grpc.Server, string) {
KeyPath: "testdata/gitalykey.pem",
}
- srv := NewSecure(nil)
+ srv := NewSecure(nil, config.Config)
listener, err := net.Listen("tcp", "localhost:9999")
require.NoError(t, err)
diff --git a/internal/server/server.go b/internal/server/server.go
index e4f4896b4..2240a4442 100644
--- a/internal/server/server.go
+++ b/internal/server/server.go
@@ -69,7 +69,7 @@ func init() {
// createNewServer returns a GRPC server with all Gitaly services and interceptors set up.
// allows for specifying secure = true to enable tls credentials
-func createNewServer(rubyServer *rubyserver.Server, secure bool) *grpc.Server {
+func createNewServer(rubyServer *rubyserver.Server, cfg config.Cfg, secure bool) *grpc.Server {
ctxTagOpts := []grpc_ctxtags.Option{
grpc_ctxtags.WithFieldExtractorForInitialReq(fieldextractors.FieldExtractor),
}
@@ -123,7 +123,7 @@ func createNewServer(rubyServer *rubyserver.Server, secure bool) *grpc.Server {
server := grpc.NewServer(opts...)
- service.RegisterAll(server, rubyServer)
+ service.RegisterAll(server, cfg, rubyServer)
reflection.Register(server)
grpc_prometheus.Register(server)
@@ -132,13 +132,13 @@ func createNewServer(rubyServer *rubyserver.Server, secure bool) *grpc.Server {
}
// NewInsecure returns a GRPC server with all Gitaly services and interceptors set up.
-func NewInsecure(rubyServer *rubyserver.Server) *grpc.Server {
- return createNewServer(rubyServer, false)
+func NewInsecure(rubyServer *rubyserver.Server, cfg config.Cfg) *grpc.Server {
+ return createNewServer(rubyServer, cfg, false)
}
// NewSecure returns a GRPC server enabling TLS credentials
-func NewSecure(rubyServer *rubyserver.Server) *grpc.Server {
- return createNewServer(rubyServer, true)
+func NewSecure(rubyServer *rubyserver.Server, cfg config.Cfg) *grpc.Server {
+ return createNewServer(rubyServer, cfg, true)
}
// CleanupInternalSocketDir will clean up the directory for internal sockets if it is a generated temp dir
diff --git a/internal/service/conflicts/resolve_conflicts_test.go b/internal/service/conflicts/resolve_conflicts_test.go
index 8c92b3a0e..7dea2b29a 100644
--- a/internal/service/conflicts/resolve_conflicts_test.go
+++ b/internal/service/conflicts/resolve_conflicts_test.go
@@ -6,6 +6,7 @@ import (
"testing"
"github.com/stretchr/testify/require"
+ "gitlab.com/gitlab-org/gitaly/internal/config"
"gitlab.com/gitlab-org/gitaly/internal/git/log"
serverPkg "gitlab.com/gitlab-org/gitaly/internal/server"
"gitlab.com/gitlab-org/gitaly/internal/service/conflicts"
@@ -308,7 +309,7 @@ func TestFailedResolveConflictsRequestDueToValidation(t *testing.T) {
}
func runFullServer(t *testing.T) (*grpc.Server, string) {
- server := serverPkg.NewInsecure(conflicts.RubyServer)
+ server := serverPkg.NewInsecure(conflicts.RubyServer, config.Config)
serverSocketPath := testhelper.GetTemporaryGitalySocketFileName()
listener, err := net.Listen("unix", serverSocketPath)
diff --git a/internal/service/operations/cherry_pick_test.go b/internal/service/operations/cherry_pick_test.go
index 509a28327..ab829a2e4 100644
--- a/internal/service/operations/cherry_pick_test.go
+++ b/internal/service/operations/cherry_pick_test.go
@@ -5,6 +5,7 @@ import (
"testing"
"github.com/stretchr/testify/require"
+ "gitlab.com/gitlab-org/gitaly/internal/config"
"gitlab.com/gitlab-org/gitaly/internal/git/log"
serverPkg "gitlab.com/gitlab-org/gitaly/internal/server"
"gitlab.com/gitlab-org/gitaly/internal/service/operations"
@@ -411,7 +412,7 @@ func TestFailedUserCherryPickRequestDueToCommitError(t *testing.T) {
}
func runFullServerWithHooks(t *testing.T) (*grpc.Server, string) {
- server := serverPkg.NewInsecure(operations.RubyServer)
+ server := serverPkg.NewInsecure(operations.RubyServer, config.Config)
serverSocketPath := testhelper.GetTemporaryGitalySocketFileName()
listener, err := net.Listen("unix", serverSocketPath)
diff --git a/internal/service/register.go b/internal/service/register.go
index 412defcf3..4015f99fc 100644
--- a/internal/service/register.go
+++ b/internal/service/register.go
@@ -52,7 +52,7 @@ var (
// RegisterAll will register all the known grpc services with
// the specified grpc service instance
-func RegisterAll(grpcServer *grpc.Server, rubyServer *rubyserver.Server) {
+func RegisterAll(grpcServer *grpc.Server, cfg config.Cfg, rubyServer *rubyserver.Server) {
gitalypb.RegisterBlobServiceServer(grpcServer, blob.NewServer(rubyServer))
gitalypb.RegisterCleanupServiceServer(grpcServer, cleanup.NewServer())
gitalypb.RegisterCommitServiceServer(grpcServer, commit.NewServer())
@@ -70,7 +70,7 @@ func RegisterAll(grpcServer *grpc.Server, rubyServer *rubyserver.Server) {
gitalypb.RegisterWikiServiceServer(grpcServer, wiki.NewServer(rubyServer))
gitalypb.RegisterConflictsServiceServer(grpcServer, conflicts.NewServer(rubyServer))
gitalypb.RegisterRemoteServiceServer(grpcServer, remote.NewServer(rubyServer))
- gitalypb.RegisterServerServiceServer(grpcServer, server.NewServer())
+ gitalypb.RegisterServerServiceServer(grpcServer, server.NewServer(cfg.Storages))
gitalypb.RegisterObjectPoolServiceServer(grpcServer, objectpool.NewServer())
gitalypb.RegisterHookServiceServer(grpcServer, hook.NewServer())
gitalypb.RegisterInternalGitalyServer(grpcServer, internalgitaly.NewServer(config.Config.Storages))
diff --git a/internal/service/remote/fetch_internal_remote_test.go b/internal/service/remote/fetch_internal_remote_test.go
index e752bffb3..09a89b06b 100644
--- a/internal/service/remote/fetch_internal_remote_test.go
+++ b/internal/service/remote/fetch_internal_remote_test.go
@@ -6,6 +6,7 @@ import (
"testing"
"github.com/stretchr/testify/require"
+ "gitlab.com/gitlab-org/gitaly/internal/config"
serverPkg "gitlab.com/gitlab-org/gitaly/internal/server"
"gitlab.com/gitlab-org/gitaly/internal/service/remote"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
@@ -114,7 +115,7 @@ func TestFailedFetchInternalRemoteDueToValidations(t *testing.T) {
}
func runFullServer(t *testing.T) (*grpc.Server, string) {
- server := serverPkg.NewInsecure(remote.RubyServer)
+ server := serverPkg.NewInsecure(remote.RubyServer, config.Config)
serverSocketPath := testhelper.GetTemporaryGitalySocketFileName()
listener, err := net.Listen("unix", serverSocketPath)
diff --git a/internal/service/repository/fetch_test.go b/internal/service/repository/fetch_test.go
index 43500dc2e..1f586c4d4 100644
--- a/internal/service/repository/fetch_test.go
+++ b/internal/service/repository/fetch_test.go
@@ -184,7 +184,7 @@ func newTestRepo(t *testing.T, relativePath string) (*gitalypb.Repository, strin
}
func runFullServer(t *testing.T) (*grpc.Server, string) {
- server := serverPkg.NewInsecure(repository.RubyServer)
+ server := serverPkg.NewInsecure(repository.RubyServer, config.Config)
serverSocketPath := testhelper.GetTemporaryGitalySocketFileName()
listener, err := net.Listen("unix", serverSocketPath)
@@ -201,7 +201,7 @@ func runFullServer(t *testing.T) (*grpc.Server, string) {
}
func runFullSecureServer(t *testing.T) (*grpc.Server, string, testhelper.Cleanup) {
- server := serverPkg.NewSecure(repository.RubyServer)
+ server := serverPkg.NewSecure(repository.RubyServer, config.Config)
listener, addr := testhelper.GetLocalhostListener(t)
errQ := make(chan error)
diff --git a/internal/service/server/disk_stats_test.go b/internal/service/server/disk_stats_test.go
index 2ba75bbd5..d2842b186 100644
--- a/internal/service/server/disk_stats_test.go
+++ b/internal/service/server/disk_stats_test.go
@@ -12,7 +12,7 @@ import (
)
func TestStorageDiskStatistics(t *testing.T) {
- server, serverSocketPath := runServer(t)
+ server, serverSocketPath := runServer(t, config.Config.Storages)
defer server.Stop()
client, conn := newServerClient(t, serverSocketPath)
diff --git a/internal/service/server/info.go b/internal/service/server/info.go
index 93cbe8516..9218be54e 100644
--- a/internal/service/server/info.go
+++ b/internal/service/server/info.go
@@ -7,7 +7,6 @@ import (
"path"
"github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus"
- "gitlab.com/gitlab-org/gitaly/internal/config"
"gitlab.com/gitlab-org/gitaly/internal/git"
"gitlab.com/gitlab-org/gitaly/internal/helper"
"gitlab.com/gitlab-org/gitaly/internal/helper/fstype"
@@ -23,7 +22,7 @@ func (s *server) ServerInfo(ctx context.Context, in *gitalypb.ServerInfoRequest)
}
var storageStatuses []*gitalypb.ServerInfoResponse_StorageStatus
- for _, shard := range config.Config.Storages {
+ for _, shard := range s.storages {
readable, writeable := shardCheck(shard.Path)
fsType := fstype.FileSystem(shard.Path)
diff --git a/internal/service/server/info_test.go b/internal/service/server/info_test.go
index 9a2d636ef..7a571374e 100644
--- a/internal/service/server/info_test.go
+++ b/internal/service/server/info_test.go
@@ -21,7 +21,13 @@ import (
)
func TestGitalyServerInfo(t *testing.T) {
- server, serverSocketPath := runServer(t)
+ // Setup storage paths
+ testStorages := []config.Storage{
+ {Name: "default", Path: testhelper.GitlabTestStoragePath()},
+ {Name: "broken", Path: "/does/not/exist"},
+ }
+
+ server, serverSocketPath := runServer(t, testStorages)
defer server.Stop()
client, conn := newServerClient(t, serverSocketPath)
@@ -30,11 +36,6 @@ func TestGitalyServerInfo(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- // Setup storage paths
- testStorages := []config.Storage{
- {Name: "default", Path: testhelper.GitlabTestStoragePath()},
- {Name: "broken", Path: "/does/not/exist"},
- }
defer func(oldStorages []config.Storage) {
config.Config.Storages = oldStorages
}(config.Config.Storages)
@@ -68,7 +69,7 @@ func TestGitalyServerInfo(t *testing.T) {
require.Equal(t, metadata.GitalyFilesystemID, c.GetStorageStatuses()[0].FilesystemId)
}
-func runServer(t *testing.T) (*grpc.Server, string) {
+func runServer(t *testing.T, storages []config.Storage) (*grpc.Server, string) {
authConfig := internalauth.Config{Token: testhelper.RepositoryAuthToken}
streamInt := []grpc.StreamServerInterceptor{auth.StreamServerInterceptor(authConfig)}
unaryInt := []grpc.UnaryServerInterceptor{auth.UnaryServerInterceptor(authConfig)}
@@ -81,7 +82,7 @@ func runServer(t *testing.T) (*grpc.Server, string) {
t.Fatal(err)
}
- gitalypb.RegisterServerServiceServer(server, NewServer())
+ gitalypb.RegisterServerServiceServer(server, NewServer(storages))
reflection.Register(server)
go server.Serve(listener)
@@ -90,7 +91,7 @@ func runServer(t *testing.T) (*grpc.Server, string) {
}
func TestServerNoAuth(t *testing.T) {
- srv, path := runServer(t)
+ srv, path := runServer(t, config.Config.Storages)
defer srv.Stop()
connOpts := []grpc.DialOption{
diff --git a/internal/service/server/server.go b/internal/service/server/server.go
index 182803fe6..d80631a0b 100644
--- a/internal/service/server/server.go
+++ b/internal/service/server/server.go
@@ -1,12 +1,16 @@
package server
-import "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
+import (
+ "gitlab.com/gitlab-org/gitaly/internal/config"
+ "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
+)
type server struct {
+ storages []config.Storage
gitalypb.UnimplementedServerServiceServer
}
// NewServer creates a new instance of a grpc ServerServiceServer
-func NewServer() gitalypb.ServerServiceServer {
- return &server{}
+func NewServer(storages []config.Storage) gitalypb.ServerServiceServer {
+ return &server{storages: storages}
}