Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(MergeAggregator): fixed merge window time drift issue by calculation of aggregation range based on wall clock time, Refs: #13403 #16375

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion models/running_aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,34 @@ func (r *RunningAggregator) Push(acc telegraf.Accumulator) {
r.Lock()
defer r.Unlock()

// In case of time drift forward (e.g. after sleep)
// we will have intentionally a long period, so
// metrics got stuck in meantime will not lost.
since := r.periodEnd
until := r.periodEnd.Add(r.Config.Period)
until := time.Now().Add(r.Config.Period)

// Truncate() eliminates the monotonic clock from the
// time which otherwise may lead to miscalculation of
// the duration. We want to calculate the duration
// based on the wall clock time because the check, if
// a metric is discarded or not, is based on the wall
// clock time (see Add() some lines above).
duration := until.Truncate(-1).Sub(since.Truncate(-1))

if duration < r.Config.Period {
// In case of time drift backwards, a new
// period based on now is constructed.
since = time.Now()
until = since.Add(r.Config.Period)
}

// Note:
// If the time drifted out of the merge window
// and a metric with that new time is pushed and
// the merge window was not yet adjusted, this
// metric will discarded anyway. There is no way
// to prevent this :-(

r.UpdateWindow(since, until)

start := time.Now()
Expand Down
Loading