-
Notifications
You must be signed in to change notification settings - Fork 545
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
MQE: Add support for changes function #9724
Conversation
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.
Nice work, thanks for that!
I think it's also worth putting this function through TestCompareVariousMixedMetricsVectorSelectors
to test some edge cases (just add it to line 2310).
haveFloats := len(fHead) > 0 || len(fTail) > 0 | ||
|
||
if !haveFloats { | ||
// PromQL engine doesn't support histogram for `changes` function yet, |
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] We use the term "Prometheus' engine" to refer to it - "PromQL engine" is ambiguous because MQE is a PromQL engine too.
// PromQL engine doesn't support histogram for `changes` function yet, | |
// Prometheus' engine doesn't support histogram for `changes` function yet, |
Might also be good to add a link to the Prometheus' issue tracking adding support for native histograms in changes
, if there is one.
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 tried to find but it seems there are no issue tracking for that.
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.
Charles is likely referring to this one: prometheus/prometheus#13934
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.
That issue didn't mention changes. This is the comment that mentioned the need to add support (code link).
@jhesketh @charleskorn I have addressed all the comments. These are changes from the previous reviews:
|
@@ -237,6 +239,49 @@ func (b *FPointRingBuffer) AnyAtOrBefore(maxT int64) bool { | |||
return b.points[b.firstIndex].T <= maxT | |||
} | |||
|
|||
// ChangesAtOrBefore returns the number of changes between subsequent points in this ring buffer from the first | |||
// point to the point with timestamp less than or equal to maxT. | |||
func (b *FPointRingBuffer) ChangesAtOrBefore(maxT int64) (float64, 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.
I think this is better fit into functions/range_vectors in terms of consistency. Can we not create a test in the functions package and pass it a constructed types.RangeVectorStepData
?
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 this is better fit into functions/range_vectors in terms of consistency
Actually some functions are implemented in fpoint_ring_buffer.go
too like CountAtOrBefore
, LastAtOrBefore
and AnyAtOrBefore
.
Can we not create a test in the functions package and pass it a constructed types.RangeVectorStepData?
It is not possible to create the buffer to simulate wrap around becausepoints
and other fields are private. I prefer not to make them public just for testing.
Other than that, if we put the logic in range_vectors.go
we are exposing the internal representation of the ring buffer in range_vector.go
. Like on how iterating head and tail which I believe should be internal fpoint_ring_buffer.go
.
At the end I don't have any strong opinion and I am fine if there is a better argument.
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.
Can we not create a test in the functions package and pass it a constructed types.RangeVectorStepData?
It is not possible to create the buffer to simulate wrap around because the fields are private.
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 would favour this not being on the ring buffer type - ChangesAtOrBefore
can efficiently be implemented by using UnsafePoints
, whereas CountAtOrBefore
, LastAtOrBefore
and AnyAtOrBefore
don't need the slices produced by UnsafePoints
and so benefit from being implemented directly on the ring buffer type.
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 will moved back to range_vectors.go
then. I will figure out how the best to test that.
// The points buffer is wrapped around, therefore we need to check changes starting from the buffer's head | ||
// and then continue to the tail. | ||
if len(fHead) > 0 && len(fTail) > 0 { | ||
// We don't need to compare the first point with itself, hence start from fHead[1:] | ||
accumulate(fHead[1:]) | ||
accumulate(fTail) | ||
} | ||
|
||
if len(fHead) > 0 && len(fTail) == 0 { | ||
// We don't need to compare the first point with itself, hence start from fHead[1:] | ||
accumulate(fHead[1:]) | ||
} |
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 is consistent with how we use accumulate elsewhere. I don't think there is much overhead in range when the len is 0 vs using an if.
// The points buffer is wrapped around, therefore we need to check changes starting from the buffer's head | |
// and then continue to the tail. | |
if len(fHead) > 0 && len(fTail) > 0 { | |
// We don't need to compare the first point with itself, hence start from fHead[1:] | |
accumulate(fHead[1:]) | |
accumulate(fTail) | |
} | |
if len(fHead) > 0 && len(fTail) == 0 { | |
// We don't need to compare the first point with itself, hence start from fHead[1:] | |
accumulate(fHead[1:]) | |
} | |
// The points buffer is wrapped around, therefore we need to check changes starting from the buffer's head | |
// and then continue to the tail. | |
// We don't need to compare the first point with itself, hence start from fHead[1:] | |
accumulate(fHead[1:]) | |
accumulate(fTail) |
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.
You are right. We can simplify that. Updated in a7d0474
{T: 9, F: 99}, | ||
{T: 1, F: 1}, | ||
{T: 3, F: 2}, | ||
{T: 5, F: 3}, |
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.
Would be good to have a test where the value doesn't change at the wrap around
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.
Added in af5c867
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
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 too, but agree with Charles. Thanks Jon!
Signed-off-by: Jon Kartago Lamida <[email protected]>
Signed-off-by: Jon Kartago Lamida <[email protected]>
Signed-off-by: Jon Kartago Lamida <[email protected]>
Signed-off-by: Jon Kartago Lamida <[email protected]>
Signed-off-by: Jon Kartago Lamida <[email protected]>
Signed-off-by: Jon Kartago Lamida <[email protected]>
Signed-off-by: Jon Kartago Lamida <[email protected]>
Co-authored-by: Joshua Hesketh <[email protected]>
Signed-off-by: Jon Kartago Lamida <[email protected]>
Signed-off-by: Jon Kartago Lamida <[email protected]>
Signed-off-by: Jon Kartago Lamida <[email protected]>
Signed-off-by: Jon Kartago Lamida <[email protected]>
Signed-off-by: Jon Kartago Lamida <[email protected]>
Signed-off-by: Jon Kartago Lamida <[email protected]>
Signed-off-by: Jon Kartago Lamida <[email protected]>
This was missed from previous commits. Signed-off-by: Jon Kartago Lamida <[email protected]>
Signed-off-by: Jon Kartago Lamida <[email protected]>
Signed-off-by: Jon Kartago Lamida <[email protected]>
Signed-off-by: Jon Kartago Lamida <[email protected]>
Signed-off-by: Jon Kartago Lamida <[email protected]>
Signed-off-by: Jon Kartago Lamida <[email protected]>
Signed-off-by: Jon Kartago Lamida <[email protected]>
Signed-off-by: Jon Kartago Lamida <[email protected]>
Co-authored-by: Charles Korn <[email protected]>
7f5623d
to
fa584f5
Compare
Signed-off-by: Jon Kartago Lamida <[email protected]>
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.