Skip to content

Commit

Permalink
resmon: ann: make sure to report meaningful times
Browse files Browse the repository at this point in the history
Make sure we always report meaningful data.
Most notable, 1 second granularity is sufficient for all
the expected use cases (e2e tests)

In general, if the update period is less than 1 second, the
configuration is very suspicious anyway.

Signed-off-by: Francesco Romani <[email protected]>
  • Loading branch information
ffromani committed Jun 14, 2022
1 parent 94dd528 commit 7e38bdb
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions pkg/resourcetopologyexporter/resourceobserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ func (rm *ResourceObserver) Run(eventsChan <-chan notification.Event, condChan c
tsEnd := time.Now()

if rm.exposeTiming {
monInfo.Annotations[k8sannotations.SleepDuration] = tsWakeupDiff.String()
monInfo.Annotations[k8sannotations.UpdateInterval] = ev.TimerInterval.String()
monInfo.Annotations[k8sannotations.SleepDuration] = clampTime(tsWakeupDiff.Round(time.Second)).String()
monInfo.Annotations[k8sannotations.UpdateInterval] = clampTime(ev.TimerInterval).String()
}

condStatus := v1.ConditionTrue
Expand All @@ -85,3 +85,10 @@ func (rm *ResourceObserver) Run(eventsChan <-chan notification.Event, condChan c
}
}
}

func clampTime(t time.Duration) time.Duration {
if t < 0 {
return 0
}
return t
}

0 comments on commit 7e38bdb

Please sign in to comment.