Skip to content

Commit

Permalink
Add duration metric
Browse files Browse the repository at this point in the history
Signed-off-by: Filip Petkovski <[email protected]>
  • Loading branch information
fpetkovski committed Oct 30, 2024
1 parent 2d25e83 commit ac8779f
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions objstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -604,27 +604,32 @@ 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
}

func (b *metricBucket) IterWithAttributes(ctx context.Context, dir string, f func(IterObjectAttributes) error, options ...IterOption) error {
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
}

Expand Down

0 comments on commit ac8779f

Please sign in to comment.