-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Add sum stat to basicstats aggregator #3797
Conversation
Is not included by default to maintain backwards compatibility.
@@ -146,6 +147,9 @@ func (m *BasicStats) Push(acc telegraf.Accumulator) { | |||
if config.mean { | |||
fields[k+"_mean"] = v.mean | |||
} | |||
if config.sum { | |||
fields[k+"_sum"] = (v.mean * v.count) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seemed the simplest way to implement it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And cheapest for backwards compatibility case
// stdev, and s2. We purposely exclude sum for backwards compatability, | ||
// otherwise user's working systems will suddenly (and surprisingly) start | ||
// capturing sum without their input. | ||
func TestBasicStatsWithDefaultStats(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be overkill, but I like the idea of verifying "default configuration" separately from verifying "aggregations are working".
Hey @danielnelson , I would love to use this feature to help simplify my continuous queries. Do you have time to take a look? |
One thing I'm worried about is that we might see some weird floating point artifacts that wouldn't appear if we kept a running sum:
|
@danielnelson I'll switch to tracking |
Let's switch to calculating the mean based on sum and count. |
bbc2930
to
ae83e44
Compare
@danielnelson I've switched to keeping a running sum (and added a test for the floating-point problem you were concerned about). However, when I tried to remove tracking the mean, the naive approach added another floating-point divide when calculating variance (example here). Do we care about a potential performance impact of this? I haven't measured anything yet - I wanted to get a sense of whether you'd be concerned before investing time. If you are concerned, options I see are: continue tracking the mean; or rearranging the variance equations to avoid the extra floating-point divide, but at the cost of an extra floating-point multiplication (example here). |
In the first example, doesn't it equal out since we can remove this divide?
|
Not without changing the The online variance algorithm produces its estimate by using both the current mean and the previous mean. In the current code, the previous mean is tracked, and the new mean is calculated with a single divide ( (Note that I'd be very happy to be wrong about this.) |
@danielnelson, could we keep tracking |
Implements #3467.
sum
is not included by default to maintain backwards compatibility.Required for all PRs: