From ac8779f7cb498c73a650360499e8d304b076b5f7 Mon Sep 17 00:00:00 2001 From: Filip Petkovski Date: Wed, 30 Oct 2024 07:39:40 +0100 Subject: [PATCH] Add duration metric Signed-off-by: Filip Petkovski --- objstore.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/objstore.go b/objstore.go index 359107d..d05bc01 100644 --- a/objstore.go +++ b/objstore.go @@ -604,14 +604,15 @@ func (b *metricBucket) Iter(ctx context.Context, dir string, f func(string) erro const op = OpIter b.metrics.ops.WithLabelValues(op).Inc() - start := time.Now() + timer := prometheus.NewTimer(b.metrics.opsDuration.WithLabelValues(op)) + defer timer.ObserveDuration() + err := b.bkt.Iter(ctx, dir, f, options...) if err != nil { if !b.metrics.isOpFailureExpected(err) && ctx.Err() != context.Canceled { b.metrics.opsFailures.WithLabelValues(op).Inc() } } - b.metrics.opsDuration.WithLabelValues(op).Observe(time.Since(start).Seconds()) return err } @@ -619,12 +620,16 @@ func (b *metricBucket) IterWithAttributes(ctx context.Context, dir string, f fun const op = OpIter b.metrics.ops.WithLabelValues(op).Inc() + timer := prometheus.NewTimer(b.metrics.opsDuration.WithLabelValues(op)) + defer timer.ObserveDuration() + err := b.bkt.IterWithAttributes(ctx, dir, f, options...) if err != nil { if !b.metrics.isOpFailureExpected(err) && ctx.Err() != context.Canceled { b.metrics.opsFailures.WithLabelValues(op).Inc() } } + return err }