Skip to content

Commit

Permalink
add prom timer to delete bucket
Browse files Browse the repository at this point in the history
  • Loading branch information
anurag4DSB committed Dec 24, 2024
1 parent 0af4ba1 commit cf1d211
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions pkg/clients/s3/s3_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"net/http"
"os"
"strings"
"time"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
Expand Down Expand Up @@ -90,16 +89,16 @@ func (client *S3Client) CreateBucket(ctx context.Context, bucketName string, par
}

func (client *S3Client) DeleteBucket(ctx context.Context, bucketName string) error {
start := time.Now()
_, err := client.S3Service.DeleteBucket(ctx, &s3.DeleteBucketInput{Bucket: &bucketName})
duration := time.Since(start).Seconds()
metricStatus := "success"
timer := prometheus.NewTimer(prometheus.ObserverFunc(func(duration float64) {
metrics.S3RequestDuration.WithLabelValues("DeleteBucket", metricStatus).Observe(duration)
}))
defer timer.ObserveDuration()

status := "success"
_, err := client.S3Service.DeleteBucket(ctx, &s3.DeleteBucketInput{Bucket: &bucketName})
if err != nil {
status = "error"
metricStatus = "error"
}
metrics.S3RequestsTotal.WithLabelValues("DeleteBucket", status).Inc()
metrics.S3RequestDuration.WithLabelValues("DeleteBucket", status).Observe(duration)

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

0 comments on commit cf1d211

Please sign in to comment.