Fix incorrect metric values for scheduler_behind_seconds (#45830) (#45904)

(cherry picked from commit 6cccbb5a09)

Co-authored-by: George Robinson <george.robinson@grafana.com>
This commit is contained in:
Grot (@grafanabot)
2022-02-25 14:24:44 +00:00
committed by GitHub
co-authored by George Robinson
parent e555fd5455
commit 6ea6c611a9
+5 -1
View File
@@ -368,7 +368,11 @@ func (sch *schedule) schedulePeriodic(ctx context.Context) error {
for {
select {
case tick := <-sch.ticker.C:
start := time.Now()
// We use Round(0) on the start time to remove the monotonic clock.
// This is required as late ticks from the ticker have current monotonic
// timestamps such that start.Sub(tick) does not return the expected
// delta.
start := time.Now().Round(0)
sch.metrics.BehindSeconds.Set(start.Sub(tick).Seconds())
tickNum := tick.Unix() / int64(sch.baseInterval.Seconds())