diff options
author | Jacob Vosmaer (GitLab) <jacob@gitlab.com> | 2018-06-19 18:23:43 +0300 |
---|---|---|
committer | Jacob Vosmaer (GitLab) <jacob@gitlab.com> | 2018-06-19 18:23:43 +0300 |
commit | 7d627be3016c0d033d945b3274316420369090ae (patch) | |
tree | 82c45d83de676f2a2d60c6f1910628a3b5dfe6d8 | |
parent | 30b217bcf9db3ff277028ec2199bc9fbf6c5f04e (diff) | |
parent | 2556152701caf5acc2ab8afe9ab3d519d879a07f (diff) |
Merge branch 'zj-shard-writeable-readable-check' into 'master'
Server info performs read and write checks
See merge request gitlab-org/gitaly!767
-rw-r--r-- | changelogs/unreleased/zj-shard-writeable-readable-check.yml | 5 | ||||
-rw-r--r-- | internal/service/server/info.go | 38 | ||||
-rw-r--r-- | internal/service/server/info_test.go | 18 | ||||
-rw-r--r-- | vendor/gitlab.com/gitlab-org/gitaly-proto/go/VERSION | 2 | ||||
-rw-r--r-- | vendor/gitlab.com/gitlab-org/gitaly-proto/go/server.pb.go | 76 | ||||
-rw-r--r-- | vendor/vendor.json | 10 |
6 files changed, 128 insertions, 21 deletions
diff --git a/changelogs/unreleased/zj-shard-writeable-readable-check.yml b/changelogs/unreleased/zj-shard-writeable-readable-check.yml new file mode 100644 index 000000000..3f97ec099 --- /dev/null +++ b/changelogs/unreleased/zj-shard-writeable-readable-check.yml @@ -0,0 +1,5 @@ +--- +title: Server info performs read and write checks +merge_request: 767 +author: +type: added diff --git a/internal/service/server/info.go b/internal/service/server/info.go index 3a1d88314..6881a9153 100644 --- a/internal/service/server/info.go +++ b/internal/service/server/info.go @@ -1,7 +1,12 @@ package server import ( + "io/ioutil" + "os" + "path" + pb "gitlab.com/gitlab-org/gitaly-proto/go" + "gitlab.com/gitlab-org/gitaly/internal/config" "gitlab.com/gitlab-org/gitaly/internal/git" "gitlab.com/gitlab-org/gitaly/internal/version" @@ -11,8 +16,37 @@ import ( func (s *server) ServerInfo(ctx context.Context, in *pb.ServerInfoRequest) (*pb.ServerInfoResponse, error) { gitVersion, err := git.Version() + var storageStatuses []*pb.ServerInfoResponse_StorageStatus + for _, shard := range config.Config.Storages { + readable, writeable := shardCheck(shard.Path) + storageStatuses = append(storageStatuses, &pb.ServerInfoResponse_StorageStatus{ + StorageName: shard.Name, + Readable: readable, + Writeable: writeable, + }) + + } + return &pb.ServerInfoResponse{ - ServerVersion: version.GetVersion(), - GitVersion: gitVersion, + ServerVersion: version.GetVersion(), + GitVersion: gitVersion, + StorageStatuses: storageStatuses, }, err } + +func shardCheck(shardPath string) (readable bool, writeable bool) { + if _, err := os.Stat(shardPath); err == nil { + readable = true + } + + // the path uses a `+` to avoid naming collisions + testPath := path.Join(shardPath, "+testWrite") + + content := []byte("testWrite") + if err := ioutil.WriteFile(testPath, content, 0644); err == nil { + writeable = true + } + os.Remove(testPath) + + return +} diff --git a/internal/service/server/info_test.go b/internal/service/server/info_test.go index 1a79fe1b9..1872df6f6 100644 --- a/internal/service/server/info_test.go +++ b/internal/service/server/info_test.go @@ -7,6 +7,7 @@ import ( pb "gitlab.com/gitlab-org/gitaly-proto/go" gitalyauth "gitlab.com/gitlab-org/gitaly/auth" + "gitlab.com/gitlab-org/gitaly/internal/config" "gitlab.com/gitlab-org/gitaly/internal/git" "gitlab.com/gitlab-org/gitaly/internal/server/auth" "gitlab.com/gitlab-org/gitaly/internal/testhelper" @@ -27,6 +28,16 @@ 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) + config.Config.Storages = testStorages + c, err := client.ServerInfo(ctx, &pb.ServerInfoRequest{}) require.NoError(t, err) @@ -35,6 +46,13 @@ func TestGitalyServerInfo(t *testing.T) { gitVersion, err := git.Version() require.NoError(t, err) require.Equal(t, gitVersion, c.GetGitVersion()) + + require.Len(t, c.GetStorageStatuses(), len(testStorages)) + require.True(t, c.GetStorageStatuses()[0].Readable) + require.True(t, c.GetStorageStatuses()[0].Writeable) + + require.False(t, c.GetStorageStatuses()[1].Readable) + require.False(t, c.GetStorageStatuses()[1].Writeable) } func runServer(t *testing.T) (*grpc.Server, string) { diff --git a/vendor/gitlab.com/gitlab-org/gitaly-proto/go/VERSION b/vendor/gitlab.com/gitlab-org/gitaly-proto/go/VERSION index 7bb21aff8..89eba2c5b 100644 --- a/vendor/gitlab.com/gitlab-org/gitaly-proto/go/VERSION +++ b/vendor/gitlab.com/gitlab-org/gitaly-proto/go/VERSION @@ -1 +1 @@ -0.102.0 +0.103.0 diff --git a/vendor/gitlab.com/gitlab-org/gitaly-proto/go/server.pb.go b/vendor/gitlab.com/gitlab-org/gitaly-proto/go/server.pb.go index 819d547fd..cd85fc43e 100644 --- a/vendor/gitlab.com/gitlab-org/gitaly-proto/go/server.pb.go +++ b/vendor/gitlab.com/gitlab-org/gitaly-proto/go/server.pb.go @@ -26,8 +26,9 @@ func (*ServerInfoRequest) ProtoMessage() {} func (*ServerInfoRequest) Descriptor() ([]byte, []int) { return fileDescriptor11, []int{0} } type ServerInfoResponse struct { - ServerVersion string `protobuf:"bytes,1,opt,name=server_version,json=serverVersion" json:"server_version,omitempty"` - GitVersion string `protobuf:"bytes,2,opt,name=git_version,json=gitVersion" json:"git_version,omitempty"` + ServerVersion string `protobuf:"bytes,1,opt,name=server_version,json=serverVersion" json:"server_version,omitempty"` + GitVersion string `protobuf:"bytes,2,opt,name=git_version,json=gitVersion" json:"git_version,omitempty"` + StorageStatuses []*ServerInfoResponse_StorageStatus `protobuf:"bytes,3,rep,name=storage_statuses,json=storageStatuses" json:"storage_statuses,omitempty"` } func (m *ServerInfoResponse) Reset() { *m = ServerInfoResponse{} } @@ -49,9 +50,51 @@ func (m *ServerInfoResponse) GetGitVersion() string { return "" } +func (m *ServerInfoResponse) GetStorageStatuses() []*ServerInfoResponse_StorageStatus { + if m != nil { + return m.StorageStatuses + } + return nil +} + +type ServerInfoResponse_StorageStatus struct { + StorageName string `protobuf:"bytes,1,opt,name=storage_name,json=storageName" json:"storage_name,omitempty"` + Readable bool `protobuf:"varint,2,opt,name=readable" json:"readable,omitempty"` + Writeable bool `protobuf:"varint,3,opt,name=writeable" json:"writeable,omitempty"` +} + +func (m *ServerInfoResponse_StorageStatus) Reset() { *m = ServerInfoResponse_StorageStatus{} } +func (m *ServerInfoResponse_StorageStatus) String() string { return proto.CompactTextString(m) } +func (*ServerInfoResponse_StorageStatus) ProtoMessage() {} +func (*ServerInfoResponse_StorageStatus) Descriptor() ([]byte, []int) { + return fileDescriptor11, []int{1, 0} +} + +func (m *ServerInfoResponse_StorageStatus) GetStorageName() string { + if m != nil { + return m.StorageName + } + return "" +} + +func (m *ServerInfoResponse_StorageStatus) GetReadable() bool { + if m != nil { + return m.Readable + } + return false +} + +func (m *ServerInfoResponse_StorageStatus) GetWriteable() bool { + if m != nil { + return m.Writeable + } + return false +} + func init() { proto.RegisterType((*ServerInfoRequest)(nil), "gitaly.ServerInfoRequest") proto.RegisterType((*ServerInfoResponse)(nil), "gitaly.ServerInfoResponse") + proto.RegisterType((*ServerInfoResponse_StorageStatus)(nil), "gitaly.ServerInfoResponse.StorageStatus") } // Reference imports to suppress errors if they are not otherwise used. @@ -129,15 +172,22 @@ var _ServerService_serviceDesc = grpc.ServiceDesc{ func init() { proto.RegisterFile("server.proto", fileDescriptor11) } var fileDescriptor11 = []byte{ - // 160 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x29, 0x4e, 0x2d, 0x2a, - 0x4b, 0x2d, 0xd2, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x4b, 0xcf, 0x2c, 0x49, 0xcc, 0xa9, - 0x54, 0x12, 0xe6, 0x12, 0x0c, 0x06, 0x8b, 0x7b, 0xe6, 0xa5, 0xe5, 0x07, 0xa5, 0x16, 0x96, 0xa6, - 0x16, 0x97, 0x28, 0xc5, 0x70, 0x09, 0x21, 0x0b, 0x16, 0x17, 0xe4, 0xe7, 0x15, 0xa7, 0x0a, 0xa9, - 0x72, 0xf1, 0x41, 0x8c, 0x88, 0x2f, 0x4b, 0x2d, 0x2a, 0xce, 0xcc, 0xcf, 0x93, 0x60, 0x54, 0x60, - 0xd4, 0xe0, 0x0c, 0xe2, 0x85, 0x88, 0x86, 0x41, 0x04, 0x85, 0xe4, 0xb9, 0xb8, 0xd3, 0x33, 0x4b, - 0xe0, 0x6a, 0x98, 0xc0, 0x6a, 0xb8, 0xd2, 0x33, 0x4b, 0xa0, 0x0a, 0x8c, 0xc2, 0xb8, 0x78, 0x21, - 0xa6, 0x83, 0xc8, 0xcc, 0xe4, 0x54, 0x21, 0x57, 0x2e, 0x2e, 0x84, 0x75, 0x42, 0x92, 0x7a, 0x10, - 0xa7, 0xe9, 0x61, 0xb8, 0x4b, 0x4a, 0x0a, 0x9b, 0x14, 0xc4, 0x75, 0x4a, 0x0c, 0x49, 0x6c, 0x60, - 0x9f, 0x19, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0xa0, 0x30, 0xe2, 0x5e, 0xe9, 0x00, 0x00, 0x00, + // 258 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x91, 0xcf, 0x4a, 0xc3, 0x40, + 0x10, 0xc6, 0x6d, 0x03, 0xa5, 0x9d, 0x34, 0xfe, 0x19, 0x2f, 0x35, 0x08, 0xd6, 0x80, 0x90, 0x53, + 0x0e, 0xf5, 0x19, 0x3c, 0x78, 0xf1, 0x90, 0x40, 0xaf, 0x65, 0xab, 0x63, 0x58, 0x48, 0xb3, 0x75, + 0x67, 0x5a, 0xf1, 0x69, 0x7c, 0x55, 0x71, 0xb6, 0x7f, 0x22, 0xea, 0x65, 0x61, 0x7e, 0xf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 0xaf, 0x00, 0x00, 0x00, 0xff, 0xff, 0xcc, 0xe4, 0x68, 0x27, 0xad, 0x01, + 0x00, 0x00, } diff --git a/vendor/vendor.json b/vendor/vendor.json index 03742ec98..35891afbd 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -201,12 +201,12 @@ "revisionTime": "2017-12-31T12:27:32Z" }, { - "checksumSHA1": "5iPUkFMqYlzAonsIoojzaccg7Hw=", + "checksumSHA1": "vS2mPrHCzTndAzb0yMT9To1i1Ek=", "path": "gitlab.com/gitlab-org/gitaly-proto/go", - "revision": "62f6b32e17393322fd187ce478cd50d3930aeb14", - "revisionTime": "2018-06-11T12:07:10Z", - "version": "v0.102.0", - "versionExact": "v0.102.0" + "revision": "5aeb19f700d2c6d6f1b5e2b2e54c5082fff3007c", + "revisionTime": "2018-06-19T15:00:15Z", + "version": "v0.103.0", + "versionExact": "v0.103.0" }, { "checksumSHA1": "nqWNlnMmVpt628zzvyo6Yv2CX5Q=", |