Skip to content

Conversation

charleskorn
Copy link
Contributor

@charleskorn charleskorn commented Jun 28, 2024

This fixes an issue with kahanSumInc which would result in NaN being used as the final result when +Inf or -Inf was one of the values added.

I've expanded the test coverage of kahanSumInc to cover these cases and others involving NaN.

This does now mean that kahanSumInc does an extra check for Inf at each step. An alternative to this would be to check for +Inf or -Inf when computing the final result (ie. after all the calls to kahanSumInc), but I opted for this as the simplest, least invasive change given how widely kahanSumInc is used.

This also revealed what I believe was an incorrect test case in promql/promqltest/testdata/native_histograms.test, where the stddev and stdvar were incorrectly calculated when a native histogram contained a sample at +Inf.

…nity

Signed-off-by: Charles Korn <charles.korn@grafana.com>
@charleskorn charleskorn force-pushed the charleskorn/sum-infinity branch from 0d48405 to fd6bdf5 Compare June 28, 2024 01:27
Copy link
Member

@codesome codesome left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just 1 nit: Can we put the test inside functions_test.go? It is a small file and we can add a comment to the test saying why we are testing it separately.

@charleskorn
Copy link
Contributor Author

Just 1 nit: Can we put the test inside functions_test.go? It is a small file and we can add a comment to the test saying why we are testing it separately.

That was my original intention, but functions_test.go is in the promql_test package, and so can't access kahanSumInc.

promql_test was introduced in #13999. I can move the test to functions_test.go, but then I'll need to change its package back to promql.

@codesome codesome merged commit 3d54bcc into prometheus:main Jul 3, 2024
@charleskorn charleskorn deleted the charleskorn/sum-infinity branch July 15, 2024 04:04
jhesketh added a commit to jhesketh/mimir that referenced this pull request Aug 7, 2024
jhesketh added a commit to grafana/mimir that referenced this pull request Aug 7, 2024
* MQE: Use kahan in sum aggregation

Implements the improvements from
prometheus/prometheus#14074
prometheus/prometheus#14362

* Update CHANGELOG
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants