diff options
Diffstat (limited to 'lib/model/util.go')
-rw-r--r-- | lib/model/util.go | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/model/util.go b/lib/model/util.go index 2364c5e80c..54d33c5808 100644 --- a/lib/model/util.go +++ b/lib/model/util.go @@ -158,7 +158,9 @@ func inWritableDir(fn func(string) error, targetFs fs.Filesystem, path string, i func addTimeUntilCancelled(ctx context.Context, counter prometheus.Counter) { t0 := time.Now() defer func() { - counter.Add(time.Since(t0).Seconds()) + if dur := time.Since(t0).Seconds(); dur > 0 { + counter.Add(dur) + } }() ticker := time.NewTicker(time.Second) @@ -167,7 +169,9 @@ func addTimeUntilCancelled(ctx context.Context, counter prometheus.Counter) { for { select { case t := <-ticker.C: - counter.Add(t.Sub(t0).Seconds()) + if dur := t.Sub(t0).Seconds(); dur > 0 { + counter.Add(dur) + } t0 = t case <-ctx.Done(): return |