From f6695f3b4c04b32c23bdf6b756379c39d1659058 Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Tue, 29 Nov 2022 16:08:58 +0300 Subject: [PATCH] [#29] Add delete metrics Signed-off-by: Denis Kirillov --- internal/native/client.go | 5 +++++ internal/native/native.go | 11 ++++++++--- internal/s3/client.go | 5 +++++ internal/s3/s3.go | 5 +++++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/internal/native/client.go b/internal/native/client.go index 798df13..8359d69 100644 --- a/internal/native/client.go +++ b/internal/native/client.go @@ -137,6 +137,9 @@ func (c *Client) Delete(containerID string, objectID string) DeleteResponse { panic(err) } + stats.Report(c.vu, objDeleteTotal, 1) + start := time.Now() + var prm client.PrmObjectDelete prm.ByID(cliObjectID) prm.FromContainer(cliContainerID) @@ -144,9 +147,11 @@ func (c *Client) Delete(containerID string, objectID string) DeleteResponse { _, err = c.cli.ObjectDelete(c.vu.Context(), prm) if err != nil { + stats.Report(c.vu, objDeleteFails, 1) return DeleteResponse{Success: false, Error: err.Error()} } + stats.Report(c.vu, objDeleteDuration, metrics.D(time.Since(start))) return DeleteResponse{Success: true} } diff --git a/internal/native/native.go b/internal/native/native.go index 51c6659..d0f70bc 100644 --- a/internal/native/native.go +++ b/internal/native/native.go @@ -28,9 +28,10 @@ var ( _ modules.Instance = &Native{} _ modules.Module = &RootModule{} - objPutTotal, objPutFails, objPutDuration *metrics.Metric - objGetTotal, objGetFails, objGetDuration *metrics.Metric - cnrPutTotal, cnrPutFails, cnrPutDuration *metrics.Metric + objPutTotal, objPutFails, objPutDuration *metrics.Metric + objGetTotal, objGetFails, objGetDuration *metrics.Metric + objDeleteTotal, objDeleteFails, objDeleteDuration *metrics.Metric + cnrPutTotal, cnrPutFails, cnrPutDuration *metrics.Metric ) func init() { @@ -116,6 +117,10 @@ func (n *Native) Connect(endpoint, hexPrivateKey string) (*Client, error) { objGetFails, _ = registry.NewMetric("neofs_obj_get_fails", metrics.Counter) objGetDuration, _ = registry.NewMetric("neofs_obj_get_duration", metrics.Trend, metrics.Time) + objDeleteTotal, _ = registry.NewMetric("neofs_obj_delete_total", metrics.Counter) + objDeleteFails, _ = registry.NewMetric("neofs_obj_delete_fails", metrics.Counter) + objDeleteDuration, _ = registry.NewMetric("neofs_obj_delete_duration", metrics.Trend, metrics.Time) + cnrPutTotal, _ = registry.NewMetric("neofs_cnr_put_total", metrics.Counter) cnrPutFails, _ = registry.NewMetric("neofs_cnr_put_fails", metrics.Counter) cnrPutDuration, _ = registry.NewMetric("neofs_cnr_put_duration", metrics.Trend, metrics.Time) diff --git a/internal/s3/client.go b/internal/s3/client.go index b82cc35..686467f 100644 --- a/internal/s3/client.go +++ b/internal/s3/client.go @@ -72,14 +72,19 @@ func (c *Client) Put(bucket, key string, payload goja.ArrayBuffer) PutResponse { } func (c *Client) Delete(bucket, key string) DeleteResponse { + stats.Report(c.vu, objDeleteTotal, 1) + start := time.Now() + _, err := c.cli.DeleteObject(c.vu.Context(), &s3.DeleteObjectInput{ Bucket: aws.String(bucket), Key: aws.String(key), }) if err != nil { + stats.Report(c.vu, objDeleteFails, 1) return DeleteResponse{Success: false, Error: err.Error()} } + stats.Report(c.vu, objDeleteDuration, metrics.D(time.Since(start))) return DeleteResponse{Success: true} } diff --git a/internal/s3/s3.go b/internal/s3/s3.go index fc4fefd..242f3b4 100644 --- a/internal/s3/s3.go +++ b/internal/s3/s3.go @@ -26,6 +26,7 @@ var ( objPutTotal, objPutFails, objPutDuration *metrics.Metric objGetTotal, objGetFails, objGetDuration *metrics.Metric + objDeleteTotal, objDeleteFails, objDeleteDuration *metrics.Metric createBucketTotal, createBucketFails, createBucketDuration *metrics.Metric ) @@ -75,6 +76,10 @@ func (s *S3) Connect(endpoint string) (*Client, error) { objGetFails, _ = registry.NewMetric("aws_obj_get_fails", metrics.Counter) objGetDuration, _ = registry.NewMetric("aws_obj_get_duration", metrics.Trend, metrics.Time) + objDeleteTotal, _ = registry.NewMetric("aws_obj_delete_total", metrics.Counter) + objDeleteFails, _ = registry.NewMetric("aws_obj_delete_fails", metrics.Counter) + objDeleteDuration, _ = registry.NewMetric("aws_obj_delete_duration", metrics.Trend, metrics.Time) + createBucketTotal, _ = registry.NewMetric("aws_create_bucket_total", metrics.Counter) createBucketFails, _ = registry.NewMetric("aws_create_bucket_fails", metrics.Counter) createBucketDuration, _ = registry.NewMetric("aws_create_bucket_duration", metrics.Trend, metrics.Time)