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:
authorPavlo Strokov <pstrokov@gitlab.com>2020-05-18 14:42:19 +0300
committerPavlo Strokov <pstrokov@gitlab.com>2020-05-19 14:27:51 +0300
commita6c5bfb562d6dd7c41657634f26b17764e4fec3c (patch)
tree1189fbd3be81d2436c7f9f193ad4176c4d5dcb67
parent6d6b8db3b76f57d5a459cc64fd3ac583e6d96bf7 (diff)
Include Praefect usage in the usage ping
With introduction of praefect between GitLab and Gitaly it is required to include info about Praefect into Usage Ping. As Praefect is a transparent proxy between two listed above the new parameter is added to the response and will be filled by the Praefect after gathering info from Gitalies behind it. Later it will be used to calculate the number of storages to send statistics into Usage Ping. Part of: https://gitlab.com/gitlab-org/gitaly/-/issues/2664
-rw-r--r--changelogs/unreleased/ps-group-for-storage-info.yml5
-rw-r--r--internal/praefect/server_test.go62
-rw-r--r--internal/praefect/service/server/info.go4
-rw-r--r--internal/service/server/info.go11
-rw-r--r--internal/service/server/info_test.go2
-rw-r--r--proto/go/gitalypb/server.pb.go67
-rw-r--r--proto/server.proto1
-rw-r--r--ruby/proto/gitaly/server_pb.rb1
8 files changed, 91 insertions, 62 deletions
diff --git a/changelogs/unreleased/ps-group-for-storage-info.yml b/changelogs/unreleased/ps-group-for-storage-info.yml
new file mode 100644
index 000000000..0c6db3e7a
--- /dev/null
+++ b/changelogs/unreleased/ps-group-for-storage-info.yml
@@ -0,0 +1,5 @@
+---
+title: Include Praefect usage in the usage ping
+merge_request: 2180
+author:
+type: changed
diff --git a/internal/praefect/server_test.go b/internal/praefect/server_test.go
index c9cd4fdce..47d38f75d 100644
--- a/internal/praefect/server_test.go
+++ b/internal/praefect/server_test.go
@@ -77,9 +77,13 @@ func TestServerRouteServerAccessor(t *testing.T) {
}
func TestGitalyServerInfo(t *testing.T) {
+ gitVersion, err := git.Version()
+ require.NoError(t, err)
+
conf := config.Config{
VirtualStorages: []*config.VirtualStorage{
&config.VirtualStorage{
+ Name: "virtual-storage-1",
Nodes: []*models.Node{
&models.Node{
Storage: "praefect-internal-1",
@@ -95,41 +99,45 @@ func TestGitalyServerInfo(t *testing.T) {
},
}
- cc, _, cleanup := runPraefectServerWithGitaly(t, conf)
- defer cleanup()
-
- client := gitalypb.NewServerServiceClient(cc)
-
ctx, cancel := testhelper.Context()
defer cancel()
- metadata, err := client.ServerInfo(ctx, &gitalypb.ServerInfoRequest{})
- require.NoError(t, err)
- 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())
+ t.Run("gitaly responds with ok", func(t *testing.T) {
+ cc, _, cleanup := runPraefectServerWithGitaly(t, conf)
+ defer cleanup()
- gitVersion, err := git.Version()
- require.NoError(t, err)
- require.Equal(t, gitVersion, metadata.GetGitVersion())
+ expected := &gitalypb.ServerInfoResponse{
+ ServerVersion: version.GetVersion(),
+ GitVersion: gitVersion,
+ StorageStatuses: []*gitalypb.ServerInfoResponse_StorageStatus{
+ {StorageName: "virtual-storage-1", Readable: true, Writeable: true, ReplicationFactor: 2},
+ },
+ }
- // use mock gitaly backends. The ServerInfo call to Gitaly will fail with an error.
- for _, storageStatus := range metadata.GetStorageStatuses() {
- require.NotNil(t, storageStatus, "none of the storage statuses should be nil")
- }
+ client := gitalypb.NewServerServiceClient(cc)
+ actual, err := client.ServerInfo(ctx, &gitalypb.ServerInfoRequest{})
+ require.NoError(t, err)
+ for _, ss := range actual.StorageStatuses {
+ ss.FsType = ""
+ ss.FilesystemId = ""
+ }
+ require.True(t, proto.Equal(expected, actual), "expected: %v, got: %v", expected, actual)
+ })
- backends := map[string]mock.SimpleServiceServer{
- conf.VirtualStorages[0].Nodes[0].Storage: &mockSvc{},
- conf.VirtualStorages[0].Nodes[1].Storage: &mockSvc{},
- }
+ t.Run("gitaly responds with error", func(t *testing.T) {
+ backends := map[string]mock.SimpleServiceServer{
+ conf.VirtualStorages[0].Nodes[0].Storage: &mockSvc{},
+ conf.VirtualStorages[0].Nodes[1].Storage: &mockSvc{},
+ }
- cc, _, cleanup = runPraefectServerWithMock(t, conf, datastore.Datastore{}, backends)
- defer cleanup()
+ cc, _, cleanup := runPraefectServerWithMock(t, conf, datastore.Datastore{}, backends)
+ defer cleanup()
- client = gitalypb.NewServerServiceClient(cc)
- metadata, err = client.ServerInfo(ctx, &gitalypb.ServerInfoRequest{})
- require.NoError(t, err, "we expect praefect's server info to fail open even if the gitaly calls result in an error")
- require.Empty(t, metadata.StorageStatuses)
+ client := gitalypb.NewServerServiceClient(cc)
+ actual, err := client.ServerInfo(ctx, &gitalypb.ServerInfoRequest{})
+ require.NoError(t, err, "we expect praefect's server info to fail open even if the gitaly calls result in an error")
+ require.Empty(t, actual.StorageStatuses, "got: %v", actual)
+ })
}
func TestGitalyServerInfoBadNode(t *testing.T) {
diff --git a/internal/praefect/service/server/info.go b/internal/praefect/service/server/info.go
index 9c084cc33..d72c14a25 100644
--- a/internal/praefect/service/server/info.go
+++ b/internal/praefect/service/server/info.go
@@ -29,6 +29,7 @@ func (s *Server) ServerInfo(ctx context.Context, in *gitalypb.ServerInfoRequest)
wg.Add(1)
i := i
virtualStorage := virtualStorage
+ replicas := uint32(1 + len(shard.Secondaries)) // 1 - is primary + N secondaries
go func() {
defer wg.Done()
@@ -50,7 +51,7 @@ func (s *Server) ServerInfo(ctx context.Context, in *gitalypb.ServerInfoRequest)
// name = "internal-gitaly-0"
// path = "/var/opt/gitlab/git-data"
//
- // [storage]]
+ // [[storage]]
// name = "internal-gitaly-1"
// path = "/var/opt/gitlab/git-data"
//
@@ -69,6 +70,7 @@ func (s *Server) ServerInfo(ctx context.Context, in *gitalypb.ServerInfoRequest)
// to the virtual storage's storage status.
storageStatuses[i].StorageName = virtualStorage.Name
storageStatuses[i].Writeable = !shard.IsReadOnly && storageStatus.Writeable
+ storageStatuses[i].ReplicationFactor = replicas
break
}
}
diff --git a/internal/service/server/info.go b/internal/service/server/info.go
index 9218be54e..86cef6b6b 100644
--- a/internal/service/server/info.go
+++ b/internal/service/server/info.go
@@ -32,11 +32,12 @@ func (s *server) ServerInfo(ctx context.Context, in *gitalypb.ServerInfoRequest)
}
storageStatuses = append(storageStatuses, &gitalypb.ServerInfoResponse_StorageStatus{
- StorageName: shard.Name,
- Readable: readable,
- Writeable: writeable,
- FsType: fsType,
- FilesystemId: gitalyMetadata.GitalyFilesystemID,
+ StorageName: shard.Name,
+ ReplicationFactor: 1, // gitaly is always treated as a single replica
+ Readable: readable,
+ Writeable: writeable,
+ FsType: fsType,
+ FilesystemId: gitalyMetadata.GitalyFilesystemID,
})
}
diff --git a/internal/service/server/info_test.go b/internal/service/server/info_test.go
index 817bd0967..a2c1153a9 100644
--- a/internal/service/server/info_test.go
+++ b/internal/service/server/info_test.go
@@ -63,10 +63,12 @@ func TestGitalyServerInfo(t *testing.T) {
require.True(t, c.GetStorageStatuses()[0].Readable)
require.True(t, c.GetStorageStatuses()[0].Writeable)
require.NotEmpty(t, c.GetStorageStatuses()[0].FsType)
+ require.Equal(t, uint32(1), c.GetStorageStatuses()[0].ReplicationFactor)
require.False(t, c.GetStorageStatuses()[1].Readable)
require.False(t, c.GetStorageStatuses()[1].Writeable)
require.Equal(t, metadata.GitalyFilesystemID, c.GetStorageStatuses()[0].FilesystemId)
+ require.Equal(t, uint32(1), c.GetStorageStatuses()[1].ReplicationFactor)
}
func runServer(t *testing.T, storages []config.Storage) (*grpc.Server, string) {
diff --git a/proto/go/gitalypb/server.pb.go b/proto/go/gitalypb/server.pb.go
index c46834dda..1c5f6ec5a 100644
--- a/proto/go/gitalypb/server.pb.go
+++ b/proto/go/gitalypb/server.pb.go
@@ -116,6 +116,7 @@ type ServerInfoResponse_StorageStatus struct {
Writeable bool `protobuf:"varint,3,opt,name=writeable,proto3" json:"writeable,omitempty"`
FsType string `protobuf:"bytes,4,opt,name=fs_type,json=fsType,proto3" json:"fs_type,omitempty"`
FilesystemId string `protobuf:"bytes,5,opt,name=filesystem_id,json=filesystemId,proto3" json:"filesystem_id,omitempty"`
+ ReplicationFactor uint32 `protobuf:"varint,6,opt,name=replication_factor,json=replicationFactor,proto3" json:"replication_factor,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
@@ -181,6 +182,13 @@ func (m *ServerInfoResponse_StorageStatus) GetFilesystemId() string {
return ""
}
+func (m *ServerInfoResponse_StorageStatus) GetReplicationFactor() uint32 {
+ if m != nil {
+ return m.ReplicationFactor
+ }
+ return 0
+}
+
type DiskStatisticsRequest struct {
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
@@ -320,35 +328,36 @@ func init() {
func init() { proto.RegisterFile("server.proto", fileDescriptor_ad098daeda4239f7) }
var fileDescriptor_ad098daeda4239f7 = []byte{
- // 434 bytes of a gzipped FileDescriptorProto
- 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x93, 0xc1, 0x8e, 0xd3, 0x30,
- 0x10, 0x86, 0x95, 0xa6, 0x94, 0x76, 0xda, 0x2e, 0x8b, 0x11, 0x6c, 0x89, 0x16, 0x58, 0x8a, 0x90,
- 0x7a, 0x80, 0x14, 0x2d, 0x6f, 0x80, 0xb8, 0xec, 0x01, 0x0e, 0x29, 0x02, 0xc1, 0x25, 0x72, 0x9a,
- 0x49, 0x64, 0x91, 0xc4, 0xc1, 0xe3, 0x16, 0xe5, 0x49, 0x78, 0x07, 0xde, 0x80, 0x27, 0xe1, 0xc6,
- 0x83, 0x70, 0x42, 0xb1, 0x93, 0x66, 0x17, 0x5a, 0x90, 0xb8, 0x44, 0x9e, 0x7f, 0xfe, 0x19, 0x4f,
- 0xbe, 0x49, 0x60, 0x42, 0xa8, 0xb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3, 0x2e,
+ 0xc1, 0xea, 0x2b, 0x13, 0xc2, 0xd7, 0x00, 0xcd, 0x56, 0xe0, 0xbd, 0x7d, 0x9b, 0x62, 0x4d, 0xf1,
+ 0xfd, 0xab, 0x97, 0x68, 0xd4, 0xf9, 0xf5, 0x2d, 0x68, 0x75, 0x0e, 0x8e, 0x1c, 0xfc, 0x00, 0x87,
+ 0x97, 0xdf, 0x8f, 0xf7, 0xaf, 0xf2, 0xa5, 0x2e, 0xfb, 0xe0, 0xdf, 0xb6, 0x35, 0xa5, 0x5f, 0x3c,
+ 0xfb, 0xb8, 0x92, 0x16, 0x62, 0x1a, 0x26, 0x6a, 0x36, 0xae, 0x8f, 0x67, 0x4a, 0xe7, 0xe3, 0xba,
+ 0xc0, 0xd8, 0xfe, 0x79, 0xe3, 0x5c, 0xad, 0xe3, 0x6a, 0x3a, 0x6d, 0x5b, 0xe8, 0xf9, 0xef, 0x00,
+ 0x00, 0x00, 0xff, 0xff, 0x7c, 0x52, 0xb9, 0x17, 0xb0, 0x03, 0x00, 0x00,
}
// Reference imports to suppress errors if they are not otherwise used.
diff --git a/proto/server.proto b/proto/server.proto
index 07941752e..29fbc55ff 100644
--- a/proto/server.proto
+++ b/proto/server.proto
@@ -30,6 +30,7 @@ message ServerInfoResponse {
bool writeable = 3;
string fs_type = 4;
string filesystem_id = 5;
+ uint32 replication_factor = 6;
}
string server_version = 1;
diff --git a/ruby/proto/gitaly/server_pb.rb b/ruby/proto/gitaly/server_pb.rb
index d4662040c..ed4237e2b 100644
--- a/ruby/proto/gitaly/server_pb.rb
+++ b/ruby/proto/gitaly/server_pb.rb
@@ -18,6 +18,7 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
optional :writeable, :bool, 3
optional :fs_type, :string, 4
optional :filesystem_id, :string, 5
+ optional :replication_factor, :uint32, 6
end
add_message "gitaly.DiskStatisticsRequest" do
end