Repository navigation
feat(promql): support topk over sum_over_time/count_over_time (ASAPQuery #706 parity) #502
Description
Summary
Match ASAPQuery PR #706 by accelerating topk over sum_over_time and count_over_time in the backend-local PromQL profile, with the correct heap weighting and labels.
Compatibility target
ProjectASAP/ASAPQuery#706 added these supported shapes:
topk(1, sum_over_time(metric[5m]))
topk by (job) (3, count_over_time(metric[5m]))
The first must rank each series by its summed sample values (count_events = false / value weighting). The second must rank by the number of observations (count_events = true / count weighting). Both grouped and ungrouped forms are included. topk over rate, avg_over_time, and other temporal functions remains unsupported, matching ASAPQuery #706.
ASAPQuery-backend has generic heap-bearing sketch machinery and can compile an evidenced Top-K query, but its checked-in backend-local compatibility workload and process conformance test do not cover either #706 shape. That leaves the weighting and in-sketch key/label contract unverified at the actual profile boundary.
Scope
- Plan both shapes through canonical ASAPPlanner and backend-local physical compilation.
- Emit an explicit heap weight mode derived from the wrapped function; never default or guess.
- Preserve the heap item key labels, including
by(...)partition labels. - Execute instant and range queries from ready warm summaries.
- Fail closed when Top-K membership evidence is missing/stale or the heap's weighting is incompatible.
Acceptance criteria
- Compiler/config tests assert value weighting for
sum_over_timeand count weighting forcount_over_time. - Process E2E sends both query shapes through
/api/v1/queryand/api/v1/query_range, compares against Prometheus, and assertsdata_source: warm. - Negative tests keep
topk(rate(...))andtopk(avg_over_time(...))on exact fallback. - No regression to existing raw-vector Top-K behavior.
Parent: #501
Activity
zzylol commentedon Sep 4, 2026
Implementation is open in #505, with the required ASAPPlanner temporal-TopK dependency in ProjectASAP/ASAPPlanner#344. The branch passes the production collector-free instant/range matrix with explicit value/count heap modes. Keeping this issue open until those PRs are merged.