fix(promql): lower workloads with ingestion intervals - #417
Open
milindsrivastava1997 wants to merge 8 commits into
Open
milindsrivastava1997 wants to merge 8 commits into
milindsrivastava1997 wants to merge 8 commits into
Conversation
milindsrivastava1997
force-pushed
the
408-promql-instant-aggregates-lose-their-evaluation-horizon-and-lower-directly-over-scan
branch
from
September 14, 2026 14:22
c431b36 to
751a16d
Compare
Collaborator
Author
|
@zzylol Pls check the entire PR description. Code is in progress. |
milindsrivastava1997
marked this pull request as ready for review
September 14, 2026 23:05
…gregates-lose-their-evaluation-horizon-and-lower-directly-over-scan
…gregates-lose-their-evaluation-horizon-and-lower-directly-over-scan
Collaborator
Author
|
@zzylol code is done |
zzylol
previously approved these changes
Sep 18, 2026
zzylol
requested changes
Sep 18, 2026
zzylol
left a comment
Contributor
There was a problem hiding this comment.
I'm not sure why data ingestion interval is a requirement to lower for PromQL, it may be useful for dataworkload as input to planner in general.
Also, the data ingestion interval (sample scraping interval in prometheus), and the query window range are two concepts, not sure how they are related in this PR.
Collaborator
Author
|
@zzylol See issue 408. To convert PromQL instant selector queries to pre ASAP IR, we need a scrape interval. For range selector queries too, the scrape interval helps guide the possible sliding window choices we can use for precomputation. |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Why
Issue #408 showed that context-free PromQL lowering loses the source cadence needed to plan instant selectors and materialize summaries.
What
DataWorkload.data_ingestion_interval: Evidence<DurationMs>.lower_promql_workloadandlower_promql_workload_with_histograms.TimeRange(data_ingestion_interval)for every bare instant selector.How
lower_promql_workloadvalidates the workload, lowers normalizedworkload.entries()for batch and repeating queries, and passes the declared interval to the PromQL lowerer. Validation failures remainPromqlErrors throughPromqlError::InvalidWorkload.The histogram-aware API keeps one supplied catalog scoped to the whole workload. The raw
PromqlLowererand old standalone helpers are no longer public escape hatches.Before this PR
sum(data)lowered as:The materializer had no selection horizon and rejected the raw scan input.
After this PR
With
data_ingestion_interval = 1s,sum(data)lowers as:sum_over_time(data[5m])retains only its explicit five-minute range. A bare selector withoffset 5mis bounded around the shifted evaluation instant.Devtools that lower PromQL now require
--data-ingestion-interval-ms; examples and tests pass an explicit 1-second value.Compatibility with maintained populations
The current-series maintained-population replacement recognizes simple instant inputs such as
sum(a)andtopk(5, a). It previously recognized a directScan(a). After this PR, the same input isTimeRange(interval) → Scan(a).The strategy and its execution-data-state validation now look through this selector-horizon wrapper when identifying the current-series population, but retain it in the actual maintained input. A shifted selector remains distinct:
TimeRange(interval) → TimeShift → Scan(a)is still rejected.The test-only workload fixture used by the affected planner modules is centralized in one
#[cfg(test)]helper.Bug fixed during implementation
The frontend previously treated a direct
TimeRangechild as a signal to chooseAggregate.reduction = PerEntity. #408 injectsTimeRange(data_ingestion_interval)for ordinary instant selectors, so that shortcut incorrectly changedsum(data)from a cross-seriesReduce([])into a per-series aggregate.The fix chooses the existing aggregate reduction from PromQL operation semantics before attaching the injected selector horizon:
TimeRangenow represents temporal input scope only. In particular, range functions over subqueries explicitly select per-series reduction because an intent such asmaxis cross-series inmax(v)but per-series inmax_over_time(v[...]).Grilling Q&A
Question: Should lowering add
LastOverTimebefore the cross-series aggregate?Answer: No. "we can assume that promql series are getting a sample every scrape interval".
Question: Should every plan-ready PromQL workload require
data_ingestion_interval, including queries with explicit ranges such asrate(data[5m])?Answer: Yes.
Question: Should the interval retain provenance/freshness metadata like other data facts, as
DataWorkload.data_ingestion_interval: Evidence<DurationMs>with a required nonzero value?Answer: Yes.
Question: Should we replace both existing public helpers with one authoritative
lower_promql_workload(&QueryWorkload)that covers normalized batch and repeating entries?Answer: Yes.
Question: Is a nested
Resulttoo complex? There is alreadyQueryWorkload::validate(), so should it own the required-interval validation and should workload lowering be all-or-nothing?Answer: "yes, this makes sense."
Question: What happens to the existing
PromqlError?Answer: Keep it as the sole error type and add an invalid-workload wrapper.
Question: Should interval injection apply to every bare instant selector, rather than only aggregate inputs?
Answer: "injection -- yeah cool every bare instant selector"
Question: Does this mean that, irrespective of offset, an instant selector gets
data_ingestion_intervaland a range selector does not? Does offset change whether the time range is atnow()ornow() - offset?Answer: "sorry, yes range selectors. So irrespective of whether offset of not, instant selector gets the data_ingestion_interval and range selector does not. the offset changes where the time range starts -- where at now() or now() - offset"
Question: Should the old public raw lowering helpers be removed immediately, with callers migrated to workload lowering?
Answer: Yes.
Verification
cargo test --workspace --lockedcargo clippy --workspace --all-targets --all-features --locked -- -D warningsFollow-up
ASAPQuery-backend must migrate its callers to the workload API and provide the source cadence. That coordinated work is tracked in ASAPQuery-backend#729.