Skip to content

PromQL instant aggregates lose their evaluation horizon and lower directly over Scan #408

Description

@milindsrivastava1997

Problem

ASAPPlanner lowers PromQL instant aggregates over a bare Scan, with no TimeRange that represents the instant-query horizon. This makes the semantic time scope unavailable to summary planning and downstream materialization.

In ASAPQuery, the workload declares a 1 s instant lookback (also its scrape interval). The backend can select an exact Sum summary for sum(data), but the physical materializer rejects the resulting raw Scan input because it requires a temporal accumulator readout:

instantaneous sample selection is not a temporal accumulator readout

Reproduction

Pinned ASAPPlanner revision: ca7546de792d74aee8231e9a1100ca893d9e86d3.

printf '%s\n' \
  'promql> sum(data)' \
  'promql> sum by (job) (data)' \
  'promql> count(data)' \
  'promql> count by (job) (data)' \
  'promql> avg(data)' \
  'promql> avg by (job) (data)' \
  'promql> quantile(0.9, data)' \
  'promql> quantile by (job) (0.9, data)' \
| cargo run --locked -p asap-devtools --bin show_pre_asap_ir

Every query lowers as Aggregate { …, child: Scan { … } }:

Query family Lowered intent Child
sum, sum by (job) Sum Scan(data)
count, count by (job) Cardinality { accuracy: Exact } Scan(data)
avg, avg by (job) Avg Scan(data)
quantile, quantile by (job) Quantile { q: 0.9, accuracy: Exact } Scan(data)

Expected direction

For an instant query evaluated with a caller-supplied horizon, lower the selector side to:

Aggregate { … }
└── TimeRange { range: instant_horizon }
    └── Scan(data)

For the ASAPQuery workload above, instant_horizon = scrape interval = 1 s. More generally, this must be supplied by the caller’s instant-query context (lookback/scrape policy); the current lower_promql(query, accuracy) API has no such parameter and therefore cannot derive it safely from query text. This should not silently change the semantics of the AST-only API by inventing a global default.

Acceptance criteria

  • A lowering/workload API can receive the explicit instant-query horizon.
  • The eight instant aggregate variants above lower their input selector through TimeRange(horizon) → Scan.
  • Explicit range selectors/functions (for example sum_over_time(data[5m])) preserve their explicit 5 m range rather than receiving an additional inferred range.
  • Coverage pins both ungrouped and by (...) forms.

Related downstream symptom: ProjectASAP/ASAPQuery-backend#702.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions