-
Notifications
You must be signed in to change notification settings - Fork 634
Add double_exponential_smoothing MQE function #10873
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
Conversation
@charleskorn @jhesketh thanks for the review. The implementation is following this wikipedia formula but also I try to follow the Prometheus upstream implementation. Several things to note are the following points:
Seeing the test are passed for both upstream and "ours" test, I am pretty sure the implementation is already correct. Please suggest some test data that can prove this wrong. I also inline the calcTrend call to make it look clearer here: 1a82d9a |
@jhesketh replying #10873 (comment) (not sure why I can't reply inline there.
The operator will just return.
So I don't think there will be any annotation we can test there. We can test for no annotation emitted but I believe it will be pointless. Please let me know if I understand you incorrectly. |
I think it'd be worthwhile adding a test for this: this codifies that we expect that no annotation is returned when only native histograms are selected. |
Yes, that was my intention. That we check we have the same annotations, or lack-thereof, as Prometheus. This can be one as a .test file. |
Signed-off-by: Jon Kartago Lamida <me@lamida.net>
Signed-off-by: Jon Kartago Lamida <me@lamida.net>
Signed-off-by: Jon Kartago Lamida <me@lamida.net>
Signed-off-by: Jon Kartago Lamida <me@lamida.net>
Signed-off-by: Jon Kartago Lamida <me@lamida.net>
…smoothing Signed-off-by: Jon Kartago Lamida <me@lamida.net>
Signed-off-by: Jon Kartago Lamida <me@lamida.net>
Signed-off-by: Jon Kartago Lamida <me@lamida.net>
Signed-off-by: Jon Kartago Lamida <me@lamida.net>
Signed-off-by: Jon Kartago Lamida <me@lamida.net>
Signed-off-by: Jon Kartago Lamida <me@lamida.net>
Signed-off-by: Jon Kartago Lamida <me@lamida.net>
Signed-off-by: Jon Kartago Lamida <me@lamida.net>
Signed-off-by: Jon Kartago Lamida <me@lamida.net>
Signed-off-by: Jon Kartago Lamida <me@lamida.net>
Signed-off-by: Jon Kartago Lamida <me@lamida.net>
// Test each label individually to catch edge cases in with single series | ||
labelCombinations := testutils.Combinations(labelsToUse, 1) | ||
|
||
// We tried to have this test with 2 labels, but it was failing due to the inconsistent ordering of prometheus processing matchers that result in multiples series, e.g series{label=~"(c|e)"}. | ||
// Prometheus might process series c first or e first which will trigger different validation errors for second and third parameter of double_exponential_smoothing. |
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 think it's helpful to explain why it gives a different validation error as you explained to me earlier.
It's not a different argument to the function, it's a different value in the range vector.
That is because the range vector of the series being computed against, values are skipped for the native histograms until it gets to a value where it has a float. That aligns with a different scalar value for the argument and thus gives a different error.
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.
Effectively it is the different argument that is passed. But there is a part of how native histogram being skipped too. I added your point here da3a0a3.
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.
It's not clear to me why, if we might get different errors, we skip comparing the values - shouldn't we skip comparing the errors?
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.
When we get validation error, Value
will be nil and we got panic. We still want to compare the error to ensure the validation is correct. More detail discussion is in this comment: https://github.com/grafana/mimir/pull/10873/files/b1eb614926072c1a01437ddd2e6f53b176459960..aaebaa28df8302ecae7669f0ee65be795718831e#r2015549294
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.
If result.Err
is not nil
, then shouldn't result.Value
always be nil
?
If so, then I think we can drop skipValueComparison
and modify RequireEqualResults
to ensure that both results have the same error (or both don't have an error), and if both have the same error, then both Value
s should be nil
.
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 am still thinking the original check to just return and skip Value comparison if they are nil is the simplest.
But let me attempt to still address this suggestion.
to ensure that both results have the same error (or both don't have an error)
We can achieve just using the existing first check
require.Equal(t, expected.Err, actual.Err)
and if both have the same error, then both Values should be nil.
if expected.Err != nil && actual.Err != nil && expected.Err.Error() == actual.Err.Error() {
require.Nil(t, expected.Value)
require.Nil(t, actual.Value)
return
}
The proposed change is already applied in the last commit.
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.
Note: I can't use errors.Is(expected.Err, actual.Err)
. It won't check the error as the same although the error string is same.
Signed-off-by: Jon Kartago Lamida <me@lamida.net>
Signed-off-by: Jon Kartago Lamida <me@lamida.net>
Signed-off-by: Jon Kartago Lamida <me@lamida.net>
A bit large changes, but this should address your feedback: 611e1b1 |
args args | ||
wantFloat float64 | ||
wantHasFloat bool | ||
wantErr bool |
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.
wantErr
is never used - should we just remove 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.
Removed 18188b0
) | ||
|
||
func Test_runDoubleExponentialSmoothing(t *testing.T) { | ||
type args struct { |
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] Why not just inline these fields into the struct below?
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.
Make it little clearer which one is arguments and which one are want
s. I think I will just keep it this way.
// Test each label individually to catch edge cases in with single series | ||
labelCombinations := testutils.Combinations(labelsToUse, 1) | ||
|
||
// We tried to have this test with 2 labels, but it was failing due to the inconsistent ordering of prometheus processing matchers that result in multiples series, e.g series{label=~"(c|e)"}. | ||
// Prometheus might process series c first or e first which will trigger different validation errors for second and third parameter of double_exponential_smoothing. |
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.
It's not clear to me why, if we might get different errors, we skip comparing the values - shouldn't we skip comparing the errors?
Signed-off-by: Jon Kartago Lamida <me@lamida.net>
Signed-off-by: Jon Kartago Lamida <me@lamida.net>
Signed-off-by: Jon Kartago Lamida <me@lamida.net>
This reverts commit 611e1b1. Signed-off-by: Jon Kartago Lamida <me@lamida.net>
Signed-off-by: Jon Kartago Lamida <me@lamida.net>
Signed-off-by: Jon Kartago Lamida <me@lamida.net>
Signed-off-by: Jon Kartago Lamida <me@lamida.net>
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.
LGTM modulo suggestion below
@@ -20,6 +20,13 @@ import ( | |||
// It's possible that floating point values are slightly different due to imprecision, but require.Equal doesn't allow us to set an allowable difference. | |||
func RequireEqualResults(t testing.TB, expr string, expected, actual *promql.Result, skipAnnotationComparison bool) { | |||
require.Equal(t, expected.Err, actual.Err) | |||
|
|||
if expected.Err != nil && actual.Err != nil && expected.Err.Error() == actual.Err.Error() { |
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 should be sufficient:
if expected.Err != nil && actual.Err != nil && expected.Err.Error() == actual.Err.Error() { | |
if expected.Err != nil { |
We've already checked that expected.Err
and actual.Err
are equal above, so we only need to check if there's an error.
What this PR does
Which issue(s) this PR fixes or relates to
Fixes #
Checklist
CHANGELOG.md
updated - the order of entries should be[CHANGE]
,[FEATURE]
,[ENHANCEMENT]
,[BUGFIX]
.about-versioning.md
updated with experimental features.