Fix incorrect metric values for scheduler_behind_seconds (#45830)

This commit is contained in:
George Robinson
2022-02-25 11:40:30 +00:00
committed by GitHub
parent 304185f682
commit 6cccbb5a09

View File

@@ -368,7 +368,11 @@ func (sch *schedule) schedulePeriodic(ctx context.Context) error {
for { for {
select { select {
case tick := <-sch.ticker.C: 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()) sch.metrics.BehindSeconds.Set(start.Sub(tick).Seconds())
tickNum := tick.Unix() / int64(sch.baseInterval.Seconds()) tickNum := tick.Unix() / int64(sch.baseInterval.Seconds())