-
Notifications
You must be signed in to change notification settings - Fork 548
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
Mimir query engine: add support for min_over_time
, max_over_time
, sum_over_time
and avg_over_time
#8934
Merged
Merged
Mimir query engine: add support for min_over_time
, max_over_time
, sum_over_time
and avg_over_time
#8934
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
2ce5275
Ensure non-name labels are retained in `count_over_time`, `last_over_…
charleskorn 294c807
Enable test cases for `min_over_time` and `max_over_time`
charleskorn 68408e7
Add `min_over_time` and `max_over_time`
charleskorn 07777fc
Add support for `sum_over_time`
charleskorn 28ff94c
Add support for `avg_over_time`
charleskorn 5bf52b4
Expand concurrent queries test to include new functions that support …
charleskorn dc3b6a9
Add changelog entry
charleskorn 20cc9cf
Fix typo in test
charleskorn a8e8b0e
Don't create unnecessary `FloatHistogram` instances in `avg_over_time`
charleskorn 82fe467
Add benchmarks
charleskorn 4de9410
Add test cases for combinations of infinity and NaN
charleskorn ae939cb
Explain why we need to copy histograms in `avg_over_time`
charleskorn b921558
Merge branch 'main' into charleskorn/more-over-time-functions
charleskorn 5702f1a
Use simpler and more accurate average calculation in `avg_over_time` …
charleskorn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
// Provenance-includes-location: https://github.com/prometheus/prometheus/blob/main/promql/engine.go | ||
// Provenance-includes-license: Apache-2.0 | ||
// Provenance-includes-copyright: The Prometheus Authors | ||
|
||
package floats | ||
|
||
import "math" | ||
|
||
func KahanSumInc(inc, sum, c float64) (newSum, newC float64) { | ||
t := sum + inc | ||
switch { | ||
case math.IsInf(t, 0): | ||
c = 0 | ||
|
||
// Using Neumaier improvement, swap if next term larger than sum. | ||
case math.Abs(sum) >= math.Abs(inc): | ||
c += (sum - t) + inc | ||
default: | ||
c += (inc - t) + sum | ||
} | ||
return t, c | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
// Provenance-includes-location: https://github.com/prometheus/prometheus/blob/main/promql/functions_internal_test.go | ||
// Provenance-includes-license: Apache-2.0 | ||
// Provenance-includes-copyright: The Prometheus Authors | ||
|
||
package floats | ||
|
||
import ( | ||
"fmt" | ||
"math" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestKahanSumInc(t *testing.T) { | ||
testCases := map[string]struct { | ||
first float64 | ||
second float64 | ||
expected float64 | ||
}{ | ||
"+Inf + anything = +Inf": { | ||
first: math.Inf(1), | ||
second: 2.0, | ||
expected: math.Inf(1), | ||
}, | ||
"-Inf + anything = -Inf": { | ||
first: math.Inf(-1), | ||
second: 2.0, | ||
expected: math.Inf(-1), | ||
}, | ||
"+Inf + -Inf = NaN": { | ||
first: math.Inf(1), | ||
second: math.Inf(-1), | ||
expected: math.NaN(), | ||
}, | ||
"NaN + anything = NaN": { | ||
first: math.NaN(), | ||
second: 2, | ||
expected: math.NaN(), | ||
}, | ||
"NaN + Inf = NaN": { | ||
first: math.NaN(), | ||
second: math.Inf(1), | ||
expected: math.NaN(), | ||
}, | ||
"NaN + -Inf = NaN": { | ||
first: math.NaN(), | ||
second: math.Inf(-1), | ||
expected: math.NaN(), | ||
}, | ||
} | ||
|
||
runTest := func(t *testing.T, a, b, expected float64) { | ||
t.Run(fmt.Sprintf("%v + %v = %v", a, b, expected), func(t *testing.T) { | ||
sum, c := KahanSumInc(b, a, 0) | ||
result := sum + c | ||
|
||
if math.IsNaN(expected) { | ||
require.Truef(t, math.IsNaN(result), "expected result to be NaN, but got %v (from %v + %v)", result, sum, c) | ||
} else { | ||
require.Equalf(t, expected, result, "expected result to be %v, but got %v (from %v + %v)", expected, result, sum, c) | ||
} | ||
}) | ||
} | ||
|
||
for name, testCase := range testCases { | ||
t.Run(name, func(t *testing.T) { | ||
runTest(t, testCase.first, testCase.second, testCase.expected) | ||
runTest(t, testCase.second, testCase.first, testCase.expected) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
(nit)
It might be worth splitting out the
_over_time
functions into their own test so we can check the common case of mixed metrics etc iterating over the function.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.
I'm inclined to leave this as-is for the time being - until prometheus/prometheus#14609 is vendored into Mimir, we need to skip one of the
rate
test cases that would fall into this group of tests, and I don't think it's so bad that the tests are repeated.