-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy paths3.go
62 lines (50 loc) · 1.25 KB
/
s3.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package health
import (
"context"
"github.com/ydb-platform/nbs/cloud/tasks/logging"
"github.com/ydb-platform/nbs/cloud/tasks/persistence"
)
////////////////////////////////////////////////////////////////////////////////
type s3Check struct {
s3 *persistence.S3Client
bucket string
}
func (s s3Check) Check(ctx context.Context) bool {
key := "healthCheckKey"
expectedData := byte(0xff)
err := s.s3.PutObject(ctx, s.bucket, key, persistence.S3Object{
Data: []byte{expectedData},
Metadata: map[string]*string{},
})
if err != nil {
logging.Warn(ctx, "S3 health check put failed: %v", err)
return false
}
object, err := s.s3.GetObject(ctx, s.bucket, key)
if err != nil {
logging.Warn(ctx, "S3 health check get failed: %v", err)
return false
}
if len(object.Data) != 1 {
logging.Error(
ctx,
"S3 health check failed, got incorrect data size: %v",
len(object.Data),
)
}
if expectedData != object.Data[0] {
logging.Error(
ctx,
"S3 health check failed, got unexpected data: '%v'",
object.Data,
)
}
return true
}
////////////////////////////////////////////////////////////////////////////////
func newS3Check(s3 *persistence.S3Client, bucket string) *s3Check {
return &s3Check{
s3: s3,
bucket: bucket,
}
}