diff --git a/discovery/refresh/refresh.go b/discovery/refresh/refresh.go index 043b2f7ba..919567a53 100644 --- a/discovery/refresh/refresh.go +++ b/discovery/refresh/refresh.go @@ -114,7 +114,10 @@ func (d *Discovery) Run(ctx context.Context, ch chan<- []*targetgroup.Group) { func (d *Discovery) refresh(ctx context.Context) ([]*targetgroup.Group, error) { now := time.Now() - defer d.duration.Observe(time.Since(now).Seconds()) + defer func() { + d.duration.Observe(time.Since(now).Seconds()) + }() + tgs, err := d.refreshf(ctx) if err != nil { d.failures.Inc() diff --git a/tsdb/db.go b/tsdb/db.go index 9adff0b9d..dbf8e5034 100644 --- a/tsdb/db.go +++ b/tsdb/db.go @@ -1939,7 +1939,9 @@ func (db *DB) CleanTombstones() (err error) { defer db.cmtx.Unlock() start := time.Now() - defer db.metrics.tombCleanTimer.Observe(time.Since(start).Seconds()) + defer func() { + db.metrics.tombCleanTimer.Observe(time.Since(start).Seconds()) + }() cleanUpCompleted := false // Repeat cleanup until there is no tombstones left.