diff options
author | Zeger-Jan van de Weg <git@zjvandeweg.nl> | 2019-11-25 11:48:51 +0300 |
---|---|---|
committer | Zeger-Jan van de Weg <git@zjvandeweg.nl> | 2019-11-25 11:48:51 +0300 |
commit | 7a1a97cfe553f9856082e4e108ffa300667b0498 (patch) | |
tree | 3af606230b6f0d34aab81d758515e79f653bb697 | |
parent | 9000ea32a8fa2ee8e82f36380cba2c063f9cf570 (diff) | |
parent | 8b47ed719adb404e89f6b9aabdf21597dca0c989 (diff) |
Merge branch 'disk-statistics' into 'master'
Add DiskStatistics grpc method to ServerService
Closes #2146
See merge request gitlab-org/gitaly!1620
-rw-r--r-- | changelogs/unreleased/disk-statistics.yml | 5 | ||||
-rw-r--r-- | internal/praefect/server_test.go | 32 | ||||
-rw-r--r-- | internal/praefect/service/server/disk_stats.go | 51 | ||||
-rw-r--r-- | internal/service/server/disk_stats.go | 46 | ||||
-rw-r--r-- | internal/service/server/disk_stats_test.go | 65 | ||||
-rw-r--r-- | proto/go/gitalypb/server.pb.go | 218 | ||||
-rw-r--r-- | proto/server.proto | 20 | ||||
-rw-r--r-- | ruby/proto/gitaly/server_pb.rb | 13 | ||||
-rw-r--r-- | ruby/proto/gitaly/server_services_pb.rb | 1 |
9 files changed, 428 insertions, 23 deletions
diff --git a/changelogs/unreleased/disk-statistics.yml b/changelogs/unreleased/disk-statistics.yml new file mode 100644 index 000000000..fc384258d --- /dev/null +++ b/changelogs/unreleased/disk-statistics.yml @@ -0,0 +1,5 @@ +--- +title: Add DiskStatistics grpc method to ServerService +merge_request: 1620 +author: maxmati +type: added diff --git a/internal/praefect/server_test.go b/internal/praefect/server_test.go index 7f1b9d767..b75aa3c59 100644 --- a/internal/praefect/server_test.go +++ b/internal/praefect/server_test.go @@ -110,6 +110,38 @@ func TestGitalyServerInfo(t *testing.T) { } } +func TestGitalyDiskStatistics(t *testing.T) { + conf := config.Config{ + Nodes: []*models.Node{ + { + ID: 1, + Storage: "praefect-internal-1", + DefaultPrimary: true, + Token: "abc", + }, + { + ID: 2, + Storage: "praefect-internal-2", + Token: "xyz", + }}, + } + cc, _, cleanup := runPraefectServerWithGitaly(t, conf) + defer cleanup() + + client := gitalypb.NewServerServiceClient(cc) + + ctx, cancel := testhelper.Context() + defer cancel() + + metadata, err := client.DiskStatistics(ctx, &gitalypb.DiskStatisticsRequest{}) + require.NoError(t, err) + require.Len(t, metadata.GetStorageStatuses(), len(conf.Nodes)) + + for _, storageStatus := range metadata.GetStorageStatuses() { + require.NotNil(t, storageStatus, "none of the storage statuses should be nil") + } +} + func TestHealthCheck(t *testing.T) { cc, _, cleanup := runPraefectServerWithGitaly(t, testConfig(1)) defer cleanup() diff --git a/internal/praefect/service/server/disk_stats.go b/internal/praefect/service/server/disk_stats.go new file mode 100644 index 000000000..745817826 --- /dev/null +++ b/internal/praefect/service/server/disk_stats.go @@ -0,0 +1,51 @@ +package server + +import ( + "context" + "fmt" + + "gitlab.com/gitlab-org/gitaly/internal/helper" + "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" + "golang.org/x/sync/errgroup" +) + +// DiskStatistics sends DiskStatisticsRequest to all of a praefect server's internal gitaly nodes and aggregates the +// results into a response +func (s *Server) DiskStatistics(ctx context.Context, _ *gitalypb.DiskStatisticsRequest) (*gitalypb.DiskStatisticsResponse, error) { + storageStatuses := make([][]*gitalypb.DiskStatisticsResponse_StorageStatus, len(s.conf.Nodes)) + + g, ctx := errgroup.WithContext(ctx) + + for i, node := range s.conf.Nodes { + i := i // necessary since it will be used in a goroutine below + node := node + cc, err := s.clientCC.GetConnection(node.Storage) + if err != nil { + return nil, helper.ErrInternalf("error getting client connection for %s: %v", node.Storage, err) + } + + g.Go(func() error { + client := gitalypb.NewServerServiceClient(cc) + resp, err := client.DiskStatistics(ctx, &gitalypb.DiskStatisticsRequest{}) + if err != nil { + return fmt.Errorf("error when requesting disk statistics from internal storage %v", node.Storage) + } + + storageStatuses[i] = resp.GetStorageStatuses() + + return nil + }) + } + + if err := g.Wait(); err != nil { + return nil, helper.ErrInternal(err) + } + + var response gitalypb.DiskStatisticsResponse + + for _, storageStatus := range storageStatuses { + response.StorageStatuses = append(response.StorageStatuses, storageStatus...) + } + + return &response, nil +} diff --git a/internal/service/server/disk_stats.go b/internal/service/server/disk_stats.go new file mode 100644 index 000000000..f4f6b09a3 --- /dev/null +++ b/internal/service/server/disk_stats.go @@ -0,0 +1,46 @@ +package server + +import ( + "context" + + "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus" + "gitlab.com/gitlab-org/gitaly/internal/config" + "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" + "golang.org/x/sys/unix" +) + +func (s *server) DiskStatistics(ctx context.Context, _ *gitalypb.DiskStatisticsRequest) (*gitalypb.DiskStatisticsResponse, error) { + var results []*gitalypb.DiskStatisticsResponse_StorageStatus + for _, shard := range config.Config.Storages { + shardInfo, err := getStorageStatus(shard) + if err != nil { + ctxlogrus.Extract(ctx).WithField("storage", shard).WithError(err).Error("to retrieve shard disk statistics") + results = append(results, &gitalypb.DiskStatisticsResponse_StorageStatus{StorageName: shard.Name}) + continue + } + + results = append(results, shardInfo) + } + + return &gitalypb.DiskStatisticsResponse{ + StorageStatuses: results, + }, nil +} + +func getStorageStatus(shard config.Storage) (*gitalypb.DiskStatisticsResponse_StorageStatus, error) { + var stats unix.Statfs_t + err := unix.Statfs(shard.Path, &stats) + if err != nil { + return nil, err + } + + // Redundant conversions to handle differences between unix families + available := int64(stats.Bavail) * int64(stats.Bsize) + used := (int64(stats.Blocks) - int64(stats.Bfree)) * int64(stats.Bsize) + + return &gitalypb.DiskStatisticsResponse_StorageStatus{ + StorageName: shard.Name, + Available: available, + Used: used, + }, nil +} diff --git a/internal/service/server/disk_stats_test.go b/internal/service/server/disk_stats_test.go new file mode 100644 index 000000000..4ad8966c3 --- /dev/null +++ b/internal/service/server/disk_stats_test.go @@ -0,0 +1,65 @@ +package server + +import ( + "math" + "testing" + + "golang.org/x/sys/unix" + + "github.com/stretchr/testify/require" + "gitlab.com/gitlab-org/gitaly/internal/config" + "gitlab.com/gitlab-org/gitaly/internal/testhelper" + "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" +) + +func TestStorageDiskStatistics(t *testing.T) { + server, serverSocketPath := runServer(t) + defer server.Stop() + + client, conn := newServerClient(t, serverSocketPath) + defer conn.Close() + + 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) + config.Config.Storages = testStorages + + c, err := client.DiskStatistics(ctx, &gitalypb.DiskStatisticsRequest{}) + require.NoError(t, err) + + require.Len(t, c.GetStorageStatuses(), len(testStorages)) + + //used and available space may change so we check if it roughly matches (+/- 1GB) + avail, used := getSpaceStats(t, testStorages[0].Path) + approxEqual(t, c.GetStorageStatuses()[0].Available, avail) + approxEqual(t, c.GetStorageStatuses()[0].Used, used) + require.Equal(t, testStorages[0].Name, c.GetStorageStatuses()[0].StorageName) + + require.Equal(t, int64(0), c.GetStorageStatuses()[1].Available) + require.Equal(t, int64(0), c.GetStorageStatuses()[1].Used) + require.Equal(t, testStorages[1].Name, c.GetStorageStatuses()[1].StorageName) +} + +func approxEqual(t *testing.T, a, b int64) { + const eps = 1024 * 1024 * 1024 + require.Truef(t, math.Abs(float64(a-b)) < eps, "expected %d to be equal %d with epsilon %d", a, b, eps) +} + +func getSpaceStats(t *testing.T, path string) (available int64, used int64) { + var stats unix.Statfs_t + err := unix.Statfs(path, &stats) + require.NoError(t, err) + + // Redundant conversions to handle differences between unix families + available = int64(stats.Bavail) * int64(stats.Bsize) + used = (int64(stats.Blocks) - int64(stats.Bfree)) * int64(stats.Bsize) + return +} diff --git a/proto/go/gitalypb/server.pb.go b/proto/go/gitalypb/server.pb.go index 879be71b0..f463b119e 100644 --- a/proto/go/gitalypb/server.pb.go +++ b/proto/go/gitalypb/server.pb.go @@ -181,38 +181,174 @@ func (m *ServerInfoResponse_StorageStatus) GetFilesystemId() string { return "" } +type DiskStatisticsRequest struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *DiskStatisticsRequest) Reset() { *m = DiskStatisticsRequest{} } +func (m *DiskStatisticsRequest) String() string { return proto.CompactTextString(m) } +func (*DiskStatisticsRequest) ProtoMessage() {} +func (*DiskStatisticsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_ad098daeda4239f7, []int{2} +} + +func (m *DiskStatisticsRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_DiskStatisticsRequest.Unmarshal(m, b) +} +func (m *DiskStatisticsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_DiskStatisticsRequest.Marshal(b, m, deterministic) +} +func (m *DiskStatisticsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_DiskStatisticsRequest.Merge(m, src) +} +func (m *DiskStatisticsRequest) XXX_Size() int { + return xxx_messageInfo_DiskStatisticsRequest.Size(m) +} +func (m *DiskStatisticsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_DiskStatisticsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_DiskStatisticsRequest proto.InternalMessageInfo + +type DiskStatisticsResponse struct { + StorageStatuses []*DiskStatisticsResponse_StorageStatus `protobuf:"bytes,1,rep,name=storage_statuses,json=storageStatuses,proto3" json:"storage_statuses,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *DiskStatisticsResponse) Reset() { *m = DiskStatisticsResponse{} } +func (m *DiskStatisticsResponse) String() string { return proto.CompactTextString(m) } +func (*DiskStatisticsResponse) ProtoMessage() {} +func (*DiskStatisticsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_ad098daeda4239f7, []int{3} +} + +func (m *DiskStatisticsResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_DiskStatisticsResponse.Unmarshal(m, b) +} +func (m *DiskStatisticsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_DiskStatisticsResponse.Marshal(b, m, deterministic) +} +func (m *DiskStatisticsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_DiskStatisticsResponse.Merge(m, src) +} +func (m *DiskStatisticsResponse) XXX_Size() int { + return xxx_messageInfo_DiskStatisticsResponse.Size(m) +} +func (m *DiskStatisticsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_DiskStatisticsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_DiskStatisticsResponse proto.InternalMessageInfo + +func (m *DiskStatisticsResponse) GetStorageStatuses() []*DiskStatisticsResponse_StorageStatus { + if m != nil { + return m.StorageStatuses + } + return nil +} + +type DiskStatisticsResponse_StorageStatus struct { + // When both available and used fields are equal 0 that means that + // Gitaly was unable to determine storage stats. + StorageName string `protobuf:"bytes,1,opt,name=storage_name,json=storageName,proto3" json:"storage_name,omitempty"` + Available int64 `protobuf:"varint,2,opt,name=available,proto3" json:"available,omitempty"` + Used int64 `protobuf:"varint,3,opt,name=used,proto3" json:"used,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *DiskStatisticsResponse_StorageStatus) Reset() { *m = DiskStatisticsResponse_StorageStatus{} } +func (m *DiskStatisticsResponse_StorageStatus) String() string { return proto.CompactTextString(m) } +func (*DiskStatisticsResponse_StorageStatus) ProtoMessage() {} +func (*DiskStatisticsResponse_StorageStatus) Descriptor() ([]byte, []int) { + return fileDescriptor_ad098daeda4239f7, []int{3, 0} +} + +func (m *DiskStatisticsResponse_StorageStatus) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_DiskStatisticsResponse_StorageStatus.Unmarshal(m, b) +} +func (m *DiskStatisticsResponse_StorageStatus) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_DiskStatisticsResponse_StorageStatus.Marshal(b, m, deterministic) +} +func (m *DiskStatisticsResponse_StorageStatus) XXX_Merge(src proto.Message) { + xxx_messageInfo_DiskStatisticsResponse_StorageStatus.Merge(m, src) +} +func (m *DiskStatisticsResponse_StorageStatus) XXX_Size() int { + return xxx_messageInfo_DiskStatisticsResponse_StorageStatus.Size(m) +} +func (m *DiskStatisticsResponse_StorageStatus) XXX_DiscardUnknown() { + xxx_messageInfo_DiskStatisticsResponse_StorageStatus.DiscardUnknown(m) +} + +var xxx_messageInfo_DiskStatisticsResponse_StorageStatus proto.InternalMessageInfo + +func (m *DiskStatisticsResponse_StorageStatus) GetStorageName() string { + if m != nil { + return m.StorageName + } + return "" +} + +func (m *DiskStatisticsResponse_StorageStatus) GetAvailable() int64 { + if m != nil { + return m.Available + } + return 0 +} + +func (m *DiskStatisticsResponse_StorageStatus) GetUsed() int64 { + if m != nil { + return m.Used + } + return 0 +} + func init() { proto.RegisterType((*ServerInfoRequest)(nil), "gitaly.ServerInfoRequest") proto.RegisterType((*ServerInfoResponse)(nil), "gitaly.ServerInfoResponse") proto.RegisterType((*ServerInfoResponse_StorageStatus)(nil), "gitaly.ServerInfoResponse.StorageStatus") + proto.RegisterType((*DiskStatisticsRequest)(nil), "gitaly.DiskStatisticsRequest") + proto.RegisterType((*DiskStatisticsResponse)(nil), "gitaly.DiskStatisticsResponse") + proto.RegisterType((*DiskStatisticsResponse_StorageStatus)(nil), "gitaly.DiskStatisticsResponse.StorageStatus") } func init() { proto.RegisterFile("server.proto", fileDescriptor_ad098daeda4239f7) } var fileDescriptor_ad098daeda4239f7 = []byte{ - // 344 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x91, 0xcd, 0xae, 0x93, 0x40, - 0x14, 0xc7, 0x43, 0x5b, 0x2b,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, 0x1f, 0xd9, 0x17, 0xde, 0x22, - 0x0b, 0xc1, 0x55, 0xc8, 0x4b, 0x5e, 0x34, 0x68, 0xfa, 0x74, 0xd3, 0xb3, 0xcd, 0x5e, 0xc1, 0xec, - 0xb7, 0x12, 0x1a, 0x8d, 0x73, 0x6c, 0x9c, 0x17, 0xc0, 0x5e, 0xc0, 0xe3, 0x8a, 0x72, 0x3d, 0xf4, - 0x18, 0x4c, 0x4c, 0xde, 0x69, 0x45, 0x5f, 0x87, 0x1e, 0xd9, 0x5b, 0xf0, 0x2b, 0xd1, 0x20, 0x0d, - 0xa4, 0xb1, 0xcd, 0x45, 0x19, 0x3c, 0x32, 0x6e, 0xef, 0x02, 0x37, 0xe5, 0xfa, 0x07, 0xf8, 0x76, - 0xc2, 0xc3, 0x2b, 0xb6, 0xc8, 0x3e, 0x03, 0x5c, 0x46, 0x66, 0x2f, 0xef, 0x5b, 0x83, 0x39, 0x4d, - 0x18, 0x3e, 0xbc, 0xa1, 0x95, 0xfb, 0xff, 0x4f, 0x34, 0x71, 0x47, 0x0b, 0xe7, 0xd3, 0x87, 0xef, - 0x07, 0x59, 0xc3, 0x8b, 0x78, 0x2b, 0xdb, 0xc4, 0x7e, 0xdf, 0x4b, 0x55, 0x27, 0x36, 0x38, 0x31, - 0xb7, 0x4f, 0x6a, 0x79, 0xb4, 0xfb, 0xa2, 0x98, 0x1a, 0xf4, 0xf1, 0x26, 0x00, 0x00, 0xff, 0xff, - 0xc2, 0x16, 0x0b, 0xdd, 0x34, 0x02, 0x00, 0x00, + // 436 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x93, 0xc1, 0x6e, 0xd3, 0x40, + 0x10, 0x86, 0xe5, 0x38, 0x84, 0x64, 0x92, 0x94, 0xb2, 0x08, 0x1a, 0xac, 0x02, 0x25, 0x08, 0x29, + 0x07, 0x70, 0x50, 0x79, 0x03, 0xc4, 0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+ 0xf3, 0xa5, 0x3d, 0x3e, 0x95, 0x2a, 0x5d, 0xda, 0x06, 0x4b, 0xf3, 0x2b, 0x2d, 0x53, 0xd9, 0xc4, + 0x65, 0x14, 0x0d, 0x8c, 0xf4, 0xfc, 0x77, 0x00, 0x00, 0x00, 0xff, 0xff, 0x2d, 0xba, 0x46, 0xb9, + 0x83, 0x03, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -228,6 +364,7 @@ const _ = grpc.SupportPackageIsVersion4 // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type ServerServiceClient interface { ServerInfo(ctx context.Context, in *ServerInfoRequest, opts ...grpc.CallOption) (*ServerInfoResponse, error) + DiskStatistics(ctx context.Context, in *DiskStatisticsRequest, opts ...grpc.CallOption) (*DiskStatisticsResponse, error) } type serverServiceClient struct { @@ -247,9 +384,19 @@ func (c *serverServiceClient) ServerInfo(ctx context.Context, in *ServerInfoRequ return out, nil } +func (c *serverServiceClient) DiskStatistics(ctx context.Context, in *DiskStatisticsRequest, opts ...grpc.CallOption) (*DiskStatisticsResponse, error) { + out := new(DiskStatisticsResponse) + err := c.cc.Invoke(ctx, "/gitaly.ServerService/DiskStatistics", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // ServerServiceServer is the server API for ServerService service. type ServerServiceServer interface { ServerInfo(context.Context, *ServerInfoRequest) (*ServerInfoResponse, error) + DiskStatistics(context.Context, *DiskStatisticsRequest) (*DiskStatisticsResponse, error) } // UnimplementedServerServiceServer can be embedded to have forward compatible implementations. @@ -259,6 +406,9 @@ type UnimplementedServerServiceServer struct { func (*UnimplementedServerServiceServer) ServerInfo(ctx context.Context, req *ServerInfoRequest) (*ServerInfoResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method ServerInfo not implemented") } +func (*UnimplementedServerServiceServer) DiskStatistics(ctx context.Context, req *DiskStatisticsRequest) (*DiskStatisticsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method DiskStatistics not implemented") +} func RegisterServerServiceServer(s *grpc.Server, srv ServerServiceServer) { s.RegisterService(&_ServerService_serviceDesc, srv) @@ -282,6 +432,24 @@ func _ServerService_ServerInfo_Handler(srv interface{}, ctx context.Context, dec return interceptor(ctx, in, info, handler) } +func _ServerService_DiskStatistics_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(DiskStatisticsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ServerServiceServer).DiskStatistics(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/gitaly.ServerService/DiskStatistics", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ServerServiceServer).DiskStatistics(ctx, req.(*DiskStatisticsRequest)) + } + return interceptor(ctx, in, info, handler) +} + var _ServerService_serviceDesc = grpc.ServiceDesc{ ServiceName: "gitaly.ServerService", HandlerType: (*ServerServiceServer)(nil), @@ -290,6 +458,10 @@ var _ServerService_serviceDesc = grpc.ServiceDesc{ MethodName: "ServerInfo", Handler: _ServerService_ServerInfo_Handler, }, + { + MethodName: "DiskStatistics", + Handler: _ServerService_DiskStatistics_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "server.proto", diff --git a/proto/server.proto b/proto/server.proto index 6774eeae4..68e39f2fe 100644 --- a/proto/server.proto +++ b/proto/server.proto @@ -13,6 +13,12 @@ service ServerService { scope_level: SERVER }; } + rpc DiskStatistics(DiskStatisticsRequest) returns (DiskStatisticsResponse) { + option (op_type) = { + op: ACCESSOR + scope_level: SERVER + }; + } } message ServerInfoRequest {} @@ -30,3 +36,17 @@ message ServerInfoResponse { string git_version = 2; repeated StorageStatus storage_statuses = 3; } + +message DiskStatisticsRequest {} + +message DiskStatisticsResponse { + message StorageStatus { +// When both available and used fields are equal 0 that means that +// Gitaly was unable to determine storage stats. + string storage_name = 1; + int64 available = 2; + int64 used = 3; + } + + repeated StorageStatus storage_statuses = 1; +} diff --git a/ruby/proto/gitaly/server_pb.rb b/ruby/proto/gitaly/server_pb.rb index e977d209f..c156f6e88 100644 --- a/ruby/proto/gitaly/server_pb.rb +++ b/ruby/proto/gitaly/server_pb.rb @@ -19,10 +19,23 @@ Google::Protobuf::DescriptorPool.generated_pool.build do optional :fs_type, :string, 4 optional :filesystem_id, :string, 5 end + add_message "gitaly.DiskStatisticsRequest" do + end + add_message "gitaly.DiskStatisticsResponse" do + repeated :storage_statuses, :message, 1, "gitaly.DiskStatisticsResponse.StorageStatus" + end + add_message "gitaly.DiskStatisticsResponse.StorageStatus" do + optional :storage_name, :string, 1 + optional :available, :int64, 2 + optional :used, :int64, 3 + end end module Gitaly ServerInfoRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("gitaly.ServerInfoRequest").msgclass ServerInfoResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("gitaly.ServerInfoResponse").msgclass ServerInfoResponse::StorageStatus = Google::Protobuf::DescriptorPool.generated_pool.lookup("gitaly.ServerInfoResponse.StorageStatus").msgclass + DiskStatisticsRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("gitaly.DiskStatisticsRequest").msgclass + DiskStatisticsResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("gitaly.DiskStatisticsResponse").msgclass + DiskStatisticsResponse::StorageStatus = Google::Protobuf::DescriptorPool.generated_pool.lookup("gitaly.DiskStatisticsResponse.StorageStatus").msgclass end diff --git a/ruby/proto/gitaly/server_services_pb.rb b/ruby/proto/gitaly/server_services_pb.rb index 67c68f99e..df3e29b1e 100644 --- a/ruby/proto/gitaly/server_services_pb.rb +++ b/ruby/proto/gitaly/server_services_pb.rb @@ -15,6 +15,7 @@ module Gitaly self.service_name = 'gitaly.ServerService' rpc :ServerInfo, ServerInfoRequest, ServerInfoResponse + rpc :DiskStatistics, DiskStatisticsRequest, DiskStatisticsResponse end Stub = Service.rpc_stub_class |