Skip to content

Commit

Permalink
updated s3 create bucket with prom observe
Browse files Browse the repository at this point in the history
  • Loading branch information
anurag4DSB committed Dec 24, 2024
1 parent 6baeda0 commit 0af4ba1
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions pkg/clients/s3/s3_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/aws/aws-sdk-go-v2/service/s3"
"github.com/aws/aws-sdk-go-v2/service/s3/types"
"github.com/aws/smithy-go/logging"
"github.com/prometheus/client_golang/prometheus"
"github.com/scality/cosi-driver/pkg/metrics"
"github.com/scality/cosi-driver/pkg/util"
)
Expand Down Expand Up @@ -65,7 +66,13 @@ var InitS3Client = func(ctx context.Context, params util.StorageClientParameters
}

func (client *S3Client) CreateBucket(ctx context.Context, bucketName string, params util.StorageClientParameters) error {
start := time.Now()
metricStatus := "success"

timer := prometheus.NewTimer(prometheus.ObserverFunc(func(duration float64) {
metrics.S3RequestDuration.WithLabelValues("CreateBucket", metricStatus).Observe(duration)
}))
defer timer.ObserveDuration()

input := &s3.CreateBucketInput{Bucket: &bucketName}
if params.Region != util.DefaultRegion {
input.CreateBucketConfiguration = &types.CreateBucketConfiguration{
Expand All @@ -74,15 +81,11 @@ func (client *S3Client) CreateBucket(ctx context.Context, bucketName string, par
}

_, err := client.S3Service.CreateBucket(ctx, input)
duration := time.Since(start).Seconds()

status := "success"
if err != nil {
status = "error"
metricStatus = "error"
}
metrics.S3RequestsTotal.WithLabelValues("CreateBucket", status).Inc()
metrics.S3RequestDuration.WithLabelValues("CreateBucket", status).Observe(duration)

metrics.S3RequestsTotal.WithLabelValues("CreateBucket", metricStatus).Inc()
return err
}

Expand Down

0 comments on commit 0af4ba1

Please sign in to comment.