mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-25 05:34:05 -08:00
Fix time.Since() in defer. Wrap in anonymous function (#11489)
Function arguments in defer evaluated during definition of defer, not during execution Signed-off-by: Slavik Panasovets <slavik@google.com> Signed-off-by: Slavik Panasovets <slavik@google.com>
This commit is contained in:
parent
51a44e6657
commit
3d2e18bad5
|
@ -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()
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue