mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-09 23:24: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) {
|
func (d *Discovery) refresh(ctx context.Context) ([]*targetgroup.Group, error) {
|
||||||
now := time.Now()
|
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)
|
tgs, err := d.refreshf(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
d.failures.Inc()
|
d.failures.Inc()
|
||||||
|
|
|
@ -1939,7 +1939,9 @@ func (db *DB) CleanTombstones() (err error) {
|
||||||
defer db.cmtx.Unlock()
|
defer db.cmtx.Unlock()
|
||||||
|
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
defer db.metrics.tombCleanTimer.Observe(time.Since(start).Seconds())
|
defer func() {
|
||||||
|
db.metrics.tombCleanTimer.Observe(time.Since(start).Seconds())
|
||||||
|
}()
|
||||||
|
|
||||||
cleanUpCompleted := false
|
cleanUpCompleted := false
|
||||||
// Repeat cleanup until there is no tombstones left.
|
// Repeat cleanup until there is no tombstones left.
|
||||||
|
|
Loading…
Reference in a new issue