-
Notifications
You must be signed in to change notification settings - Fork 544
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
Extract delta from rate function #10353
Extract delta from rate function #10353
Conversation
Signed-off-by: Jon Kartago Lamida <[email protected]>
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 OK with the extra duplication this introduces - I think this makes the logic of delta
much clearer.
|
||
func floatDelta(fCount int, fHead []promql.FPoint, fTail []promql.FPoint, rangeStart int64, rangeEnd int64, rangeSeconds float64) float64 { | ||
firstPoint := fHead[0] | ||
fHead = 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.
[nit] We don't need to do this for delta
.
|
||
func histogramDelta(hCount int, hHead []promql.HPoint, hTail []promql.HPoint, rangeStart int64, rangeEnd int64, rangeSeconds float64, emitAnnotation types.EmitAnnotationFunc) (*histogram.FloatHistogram, error) { | ||
firstPoint := hHead[0] | ||
hHead = hHead[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.
[nit] We don't need to do this for delta
.
if firstPoint.H.CounterResetHint == histogram.GaugeType || lastPoint.H.CounterResetHint == histogram.GaugeType { | ||
emitAnnotation(annotations.NewNativeHistogramNotCounterWarning) | ||
} |
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.
Is this correct? We emit a "not a gauge" warning further down if either point is not a gauge.
(we might need to add more test cases to TestAnnotations
in engine_test.go
)
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 apply only for rate and increase. Removed in 7ba501f
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 one test case in 56f67de. Still figuring out how to set CounterResetHint
from promql test.
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 delta.Schema != desiredSchema { | ||
delta = delta.CopyToSchema(desiredSchema) | ||
} |
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 don't think this is necessary - the Sub
and CopyToSchema
calls above should cover this.
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 in 175a67f
delta := lastPoint.H.CopyToSchema(desiredSchema) | ||
_, err := delta.Sub(firstPoint.H) |
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.
Couldn't we do this? Sub
will automatically adjust the schema if necessary.
delta := lastPoint.H.CopyToSchema(desiredSchema) | |
_, err := delta.Sub(firstPoint.H) | |
delta, err := lastPoint.H.Copy().Sub(firstPoint.H) |
If so, then we don't need desiredSchema
at all.
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.
Updated in 9c6474a
} | ||
|
||
if fCount >= 2 { | ||
// TODO: just pass step here? (and 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.
Is this TODO still relevant?
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
Co-authored-by: Charles Korn <[email protected]>
Co-authored-by: Charles Korn <[email protected]>
Co-authored-by: Charles Korn <[email protected]>
Co-authored-by: Charles Korn <[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]>
Signed-off-by: Jon Kartago Lamida <[email protected]>
@charleskorn I have addressed almost all of your suggestion. I will merge this to #9795 and we can continue the discussion there. |
* Extract delta from rate function Signed-off-by: Jon Kartago Lamida <[email protected]> * Update pkg/streamingpromql/operators/functions/rate_increase.go Co-authored-by: Charles Korn <[email protected]> * Update pkg/streamingpromql/operators/functions/rate_increase.go Co-authored-by: Charles Korn <[email protected]> * Update pkg/streamingpromql/operators/functions/rate_increase.go Co-authored-by: Charles Korn <[email protected]> * Update pkg/streamingpromql/operators/functions/rate_increase.go Co-authored-by: Charles Korn <[email protected]> * Tidy up after applying PR suggestion Signed-off-by: Jon Kartago Lamida <[email protected]> * Remove unnecessary head subslice Signed-off-by: Jon Kartago Lamida <[email protected]> * Remove wrong placed annotation Signed-off-by: Jon Kartago Lamida <[email protected]> * Remove extra copySchema Signed-off-by: Jon Kartago Lamida <[email protected]> * Simplify native histogram sub schema Signed-off-by: Jon Kartago Lamida <[email protected]> * Remove TODO Signed-off-by: Jon Kartago Lamida <[email protected]> * The lastPoint should be last index of the head Signed-off-by: Jon Kartago Lamida <[email protected]> * Add delta counterResetHint test Signed-off-by: Jon Kartago Lamida <[email protected]> --------- Signed-off-by: Jon Kartago Lamida <[email protected]> Co-authored-by: Charles Korn <[email protected]>
* Extract delta from rate function Signed-off-by: Jon Kartago Lamida <[email protected]> * Update pkg/streamingpromql/operators/functions/rate_increase.go Co-authored-by: Charles Korn <[email protected]> * Update pkg/streamingpromql/operators/functions/rate_increase.go Co-authored-by: Charles Korn <[email protected]> * Update pkg/streamingpromql/operators/functions/rate_increase.go Co-authored-by: Charles Korn <[email protected]> * Update pkg/streamingpromql/operators/functions/rate_increase.go Co-authored-by: Charles Korn <[email protected]> * Tidy up after applying PR suggestion Signed-off-by: Jon Kartago Lamida <[email protected]> * Remove unnecessary head subslice Signed-off-by: Jon Kartago Lamida <[email protected]> * Remove wrong placed annotation Signed-off-by: Jon Kartago Lamida <[email protected]> * Remove extra copySchema Signed-off-by: Jon Kartago Lamida <[email protected]> * Simplify native histogram sub schema Signed-off-by: Jon Kartago Lamida <[email protected]> * Remove TODO Signed-off-by: Jon Kartago Lamida <[email protected]> * The lastPoint should be last index of the head Signed-off-by: Jon Kartago Lamida <[email protected]> * Add delta counterResetHint test Signed-off-by: Jon Kartago Lamida <[email protected]> --------- Signed-off-by: Jon Kartago Lamida <[email protected]> Co-authored-by: Charles Korn <[email protected]>
This PR is trying to address suggestion in #9795 to extract delta function from rate. The diff will show how we have many more line additions if we extract the logic from rate.
How this different with #9795
delta
calculateFloatRate
andcalculateHistogramRate
to do extrapolationMy concern with extracting delta from rate is we create many line duplications, such as most of lines in delta(), floatDelta() and histogramDelta(). This is reflected from 118 line additions and 36 line removal in this PR diffs.
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.