fix(aggregators): Handle time drift when calculating aggregation windows (#16375)

Co-authored-by: Joachim DB Systel <joachim.schachermayer@deutschebahn.com>
This commit is contained in:
Joachim 2025-03-26 16:07:17 +01:00 committed by GitHub
parent e5a9309451
commit 52244af2b6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 11 additions and 0 deletions

View File

@ -177,6 +177,17 @@ func (r *RunningAggregator) Push(acc telegraf.Accumulator) {
since := r.periodEnd since := r.periodEnd
until := r.periodEnd.Add(r.Config.Period) until := r.periodEnd.Add(r.Config.Period)
// Check if the next aggregation window will contain "now". This might
// not be the case if the machine's clock was adjusted or the machine
// hibernated as in those cases the clock might be advanced before or
// after the initial aggregation window.
nowWall := time.Now().Truncate(-1)
if nowWall.Before(since.Truncate(-1)) || nowWall.After(until.Truncate(-1)) {
since = nowWall.Truncate(r.Config.Period)
until = since.Add(r.Config.Period)
}
r.UpdateWindow(since, until) r.UpdateWindow(since, until)
start := time.Now() start := time.Now()