Skip to content

feat(promql): support topk over sum_over_time/count_over_time (ASAPQuery #706 parity) #502

Description

@zzylol

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_time and count weighting for count_over_time.
  • Process E2E sends both query shapes through /api/v1/query and /api/v1/query_range, compares against Prometheus, and asserts data_source: warm.
  • Negative tests keep topk(rate(...)) and topk(avg_over_time(...)) on exact fallback.
  • No regression to existing raw-vector Top-K behavior.

Parent: #501

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: control planePlanning, configuration, routing, and control-plane orchestrationarea: data planeRuntime ingestion, storage, and query-serving data pathsarea: physical compilerCompilation from selected logical plans to executable backend and Collector plansarea: query enginePromQL lowering, execution, result shaping, and fallback behaviorarea: summary executionWarm-summary binding, readout, composition, and result decodingenhancementNew feature or requestfeature: PromQLPromQL compatibility and execution semanticsfeature: Top-KTop-K planning, heap materialization, ranking, and labelsfeature: range evaluationRange-query steps, windows, timestamps, and temporal evaluationfeature: sketch algorithmsSketch-family configuration, lifecycle, merge, and readout behaviorfeature: warm summariesASAP warm-tier materialization, readiness, and servingintegration: ASAPPlannerASAPPlanner API, IR, candidate, and selected-plan integrationtest: end-to-endProcess-boundary, differential, conformance, and full-stack tests

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions