Adding step invariant metrics and fast path for instant queries. #13911
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.
What this PR does
This PR introduces metrics for tracking the effectiveness of the step invariant operator.
When an expression is marked as a step invariant, the float or histogram points are assumed to be the same at each step. As such, the inner data only needs to be queried once and the value re-used in each subsequent step.
This PR provides a metric to track the number of points saved / re-used.
This PR also adds a metric for tracking the total number of step invariant nodes which have been observed. Note that not ever step invariant node will result in savings. This can occur if the inner operator returns no data.
An enhancement has also been made to remove the step invariant operator if the query is an instant query - as this operator does not provide any useful value when there is only a single step of data.
The new metrics are;
cortex_mimir_query_engine_step_invariant_nodes_totalcortex_mimir_query_engine_step_invariant_points_saved_total- and this will have a type label of fpoint or hpointTo assist in supporting a metric tracker being passed into the operator, a new
MetricsTrackerhas been added to the query planner which is passed down to operators within theOperatorParameters. This could be re-used to allow other metric trackers to be passed into operators.Which issue(s) this PR fixes or relates to
Fixes #
Checklist
CHANGELOG.mdupdated - the order of entries should be[CHANGE],[FEATURE],[ENHANCEMENT],[BUGFIX]. If changelog entry is not needed, please add thechangelog-not-neededlabel to the PR.about-versioning.mdupdated with experimental features.Note
Introduces metrics to observe step-invariant expression usage and savings, and avoids unnecessary wrapping for instant queries.
operators/metricstracker with counters:cortex_mimir_query_engine_step_invariant_nodes_totalandcortex_mimir_query_engine_step_invariant_points_saved_total(labeled bytype:fpoint/hpoint)OperatorMetricsTrackerand passes it viaplanning.OperatorParameters; engine wires it into operator paramsStepInvariantInstantVectorOperatorandStepInvariantScalarOperatorupdated to record node observations and saved points; constructors accept trackerStepCount <= 1(instant queries)Written by Cursor Bugbot for commit 91ae18a. This will update automatically on new commits. Configure here.