From d53b491273746e7e29c0b7f4a47aa4b7d2f36fa3 Mon Sep 17 00:00:00 2001 From: Congqi Xia Date: Wed, 6 Nov 2024 11:57:25 +0800 Subject: [PATCH] enhance: Use cancel label for ctx canceled storage op Previously failed label is used for canceled storage op, which may cause wrong alarm when user cancel load operation or etc. This PR utilizes cancel label when such case happens. Signed-off-by: Congqi Xia --- internal/storage/remote_chunk_manager.go | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/internal/storage/remote_chunk_manager.go b/internal/storage/remote_chunk_manager.go index f510fe2e5008b..451b043f892e3 100644 --- a/internal/storage/remote_chunk_manager.go +++ b/internal/storage/remote_chunk_manager.go @@ -338,7 +338,11 @@ func (mcm *RemoteChunkManager) getObject(ctx context.Context, bucketName, object if err == nil && reader != nil { metrics.PersistentDataOpCounter.WithLabelValues(metrics.DataGetLabel, metrics.SuccessLabel).Inc() } else { - metrics.PersistentDataOpCounter.WithLabelValues(metrics.DataGetLabel, metrics.FailLabel).Inc() + if errors.Is(err, context.Canceled) { + metrics.PersistentDataOpCounter.WithLabelValues(metrics.DataGetLabel, metrics.CancelLabel).Inc() + } else { + metrics.PersistentDataOpCounter.WithLabelValues(metrics.DataGetLabel, metrics.FailLabel).Inc() + } } return reader, err @@ -354,7 +358,11 @@ func (mcm *RemoteChunkManager) putObject(ctx context.Context, bucketName, object Observe(float64(start.ElapseSpan().Milliseconds())) metrics.PersistentDataOpCounter.WithLabelValues(metrics.MetaPutLabel, metrics.SuccessLabel).Inc() } else { - metrics.PersistentDataOpCounter.WithLabelValues(metrics.MetaPutLabel, metrics.FailLabel).Inc() + if errors.Is(err, context.Canceled) { + metrics.PersistentDataOpCounter.WithLabelValues(metrics.MetaPutLabel, metrics.CancelLabel).Inc() + } else { + metrics.PersistentDataOpCounter.WithLabelValues(metrics.MetaPutLabel, metrics.FailLabel).Inc() + } } return err @@ -370,7 +378,11 @@ func (mcm *RemoteChunkManager) getObjectSize(ctx context.Context, bucketName, ob Observe(float64(start.ElapseSpan().Milliseconds())) metrics.PersistentDataOpCounter.WithLabelValues(metrics.DataStatLabel, metrics.SuccessLabel).Inc() } else { - metrics.PersistentDataOpCounter.WithLabelValues(metrics.DataStatLabel, metrics.FailLabel).Inc() + if errors.Is(err, context.Canceled) { + metrics.PersistentDataOpCounter.WithLabelValues(metrics.DataStatLabel, metrics.CancelLabel).Inc() + } else { + metrics.PersistentDataOpCounter.WithLabelValues(metrics.DataStatLabel, metrics.FailLabel).Inc() + } } return info, err @@ -386,7 +398,11 @@ func (mcm *RemoteChunkManager) removeObject(ctx context.Context, bucketName, obj Observe(float64(start.ElapseSpan().Milliseconds())) metrics.PersistentDataOpCounter.WithLabelValues(metrics.DataRemoveLabel, metrics.SuccessLabel).Inc() } else { - metrics.PersistentDataOpCounter.WithLabelValues(metrics.DataRemoveLabel, metrics.FailLabel).Inc() + if errors.Is(err, context.Canceled) { + metrics.PersistentDataOpCounter.WithLabelValues(metrics.DataRemoveLabel, metrics.CancelLabel).Inc() + } else { + metrics.PersistentDataOpCounter.WithLabelValues(metrics.DataRemoveLabel, metrics.FailLabel).Inc() + } } return err