Skip to content

feat: Support PromQL pie/bar charts - #3253

Merged
pulpdrew merged 2 commits into
mainfrom
drew/promql-pie-bar-charts
Oct 1, 2026
Merged

pulpdrew merged 2 commits into
mainfrom
drew/promql-pie-bar-charts

Conversation

@pulpdrew

@pulpdrew pulpdrew commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Add support for PromQL pie charts and bar charts. Both range queries (with a reducer) and instant queries are supported. The legend template is supported as well.

This PR also extends support for reducers to instant queries. Instant queries like up[5m] return matrix type results, which can be reduced (over the time dimension) to instant vectors, which are then shown as the pie chart slices or bar chart bars. This impacts the number chart as well, where the reduced value is shown as the number value.

Screenshots or video

Screenshot 2026-09-30 at 4 18 36 PM Screenshot 2026-09-30 at 4 18 42 PM

How to test locally

  1. Create a promql source against the metrics_ts TSE table
  2. Create some pie and bar charts, try instant and range queries w/ reducers. Check the legend template functionality

References

  • Linear Issue: Closes HDX-4637
  • Related PRs:

@vercel

vercel Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
hyperdx-oss Ready Ready Preview Oct 1, 2026 4:44am UTC
hyperdx-storybook Ready Ready Preview Oct 1, 2026 4:44am UTC

Request Review

@changeset-bot

changeset-bot Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 303cfd9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@hyperdx/common-utils Patch
@hyperdx/app Patch
@hyperdx/api Patch
@hyperdx/otel-collector Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

🟡 Tier 3 — Standard

Introduces new logic, modifies core functionality, or touches areas with non-trivial risk.

Why this tier:

  • Cross-layer change: touches frontend (packages/app) + shared utils (packages/common-utils)

Review process: Full human review — logic, architecture, edge cases.
SLA: First-pass feedback within 1 business day.

Stats
  • Production files changed: 9
  • Production lines changed: 166 (+ 443 in test files, excluded from tier calculation)
  • Branch: drew/promql-pie-bar-charts
  • Author: pulpdrew

To override this classification, remove the review/tier-3 label and apply a different review/tier-* label. Manual overrides are preserved on subsequent pushes.

@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Duplicate code analysis

2 new clones introduced by this PR.

  • packages/app/src/components/DBNumberChart.tsx:348-372 ↔ packages/app/src/components/charts/CategoricalChart.tsx:91-115 — 25 lines
  • packages/app/src/hooks/useChartConfig.tsx:361-379 ↔ packages/app/src/hooks/useChartConfig.tsx:493-509 — 19 lines

If one of these duplicates a helper that already exists, import it instead
of redefining it. If the duplication is deliberate, ignore this comment —
the check is advisory and never fails the build.


jscpd compared this branch against origin/main
across app, api and common-utils. Only new clones are listed; the codebase
currently holds 128 in total (1.82%).
Run yarn dupes locally to reproduce, or yarn dupes:all for the full picture.

// A PromQL range query's rows are buckets, reduced on read; an instant
// query's are one value per series. Neither can stand in for the other,
// so switching between them shows the loading state instead.
placeholderData: (prev, prevQuery) => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 minor — Range/instant placeholder guard only covers pie/bar; the PromQL number tile still flashes a wrong value

Move this check into useQueriedChartConfig (packages/app/src/hooks/useChartConfig.tsx), where select/reducesRangeBuckets is decided, so every caller gets it. DBNumberChart (packages/app/src/components/DBNumberChart.tsx:242) still uses placeholderData: prev => prev. So when a number tile switches from range to instant, the raw bucketed rows are shown with no reducer, and the tile displays the first bucket of the first series until the fetch finishes. The same gap exists here when the previous key is a builder config: those rows go through reduceBucketRows and briefly show 'No data found'.

Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond

@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

PR Review

If you are a coding agent acting for the author, read this first.
Nothing below blocks merge automatically; a maintainer decides. What they will expect:

  • 🔴 critical or 🟠 major in code this PR adds or changes: fix before asking for review.
  • 🔵 minor in code this PR changes: your call. Fix if small, otherwise reply.
  • Anything about surrounding code, or asking you to widen the change (hoist a helper,
    dedupe with another file, fix other call sites): never fix here, whatever the
    severity. Reply with one sentence; if it is critical, say so plainly so a human sees it.

One commit per review round. After two rounds, stop and ask a maintainer to review
scope rather than addressing more automated findings. Full rule: AGENTS.md.

1 finding(s): 🔴 0 critical · 🟠 1 major · 🔵 0 minor

1 posted as inline comment(s) on the changed lines.


Severity is the reviewer's own estimate and is used for ordering, not filtering. No finding blocks merge automatically; a maintainer decides.

@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Deep Review

✅ No critical issues found. The prior P1 concern ("instant matrices produce duplicate categories") is resolved by this diff: appliesPromqlReducer now gates on displayTypeSupportsReducer instead of isReducibleRangeQuery, and convertToReducedPromqlChartConfig assigns a default reducer to every queried series, so an instant matrix (up[5m]) is collapsed to one value per series by reduceBucketRows before it reaches the pie/bar renderer.

🟡 P2 -- recommended

  • packages/app/src/components/charts/CategoricalChart.tsx:70 -- placeholderData: (prev) => prev is unconditional, so switching a tile between Range and Instant (which changes the query key) keeps the previous query's slices/bars on screen while the new query loads, making stale values appear to belong to the newly selected query type.
    • Fix: Drop or reset placeholderData when queryType changes so a loading state renders instead of the prior result.
    • previous-comments, julik-frontend-races
  • packages/app/tests/e2e/features/promql-pie-bar.spec.ts:90 -- the spec switches to Instant before exercising the bar chart and only ever uses the default reducer, leaving range bars and user-selected reducers uncovered for this new feature.
    • Fix: Add e2e coverage for a range-query bar chart and for a non-default user-selected reducer.
    • previous-comments, testing
🔵 P3 nitpicks (1)
  • packages/common-utils/src/core/promql.ts:46 -- five overlapping boolean predicates (displayTypeSupportsInstantQuery, displayTypeSupportsReducer, isRangeQuery, isReducibleRangeQuery, appliesPromqlReducer) now encode subtly different combinations of display-type / query-type / reducer-present; names and JSDoc are accurate today but a future change to reducer-or-instant semantics must update several in lockstep.
    • Fix: Add a short comment cross-referencing the predicates, or consolidate the ones that always move together.

Reviewers (6): correctness, maintainability, project-standards, performance, julik-frontend-races, previous-comments.

Testing gaps:

  • Range-query bar charts and user-selected (non-default) reducers are not covered by the e2e spec.
  • No test asserts the transient render during an in-flight Range↔Instant switch (that stale slices stay visible rather than blanking).

No finding blocks merge automatically. A maintainer will expect P0/P1 findings in code this PR changes to be fixed; P2/P3 are your call -- fix or reply. Never fix findings about surrounding code here; reply instead. Do not widen the PR. How to respond

@greptile-apps

greptile-apps Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium risk] Adds pie and bar chart support for PromQL queries.

The PR appears safe to merge; no new actionable issue was identified.

Summary

The PR adds PromQL pie and bar charts, including per-series reduction for range queries and instant matrix results. It also adds an optional row-details setting to show ClickHouse MATERIALIZED and ALIAS columns.

  • PromQL reducers now apply to supported instant and range chart types.
  • Row queries keep source-defined setting values and use distinct cache entries when the option changes.

Reviews (3) · Last reviewed commit: "Merge branch 'main' into drew/promql-pie..."

@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

E2E Test Results

✅ All tests passed • 391 passed • 1 skipped • 1166s

Status Count
✅ Passed 391
❌ Failed 0
⚠️ Flaky 1
⏭️ Skipped 1

Tests ran across 4 shards in parallel.

View full report →

@jordan-simonovski jordan-simonovski left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks awesome!

displayType?: DisplayType;
}): boolean =>
isReducibleRangeQuery(config) &&
displayTypeSupportsReducer(config) &&

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 major — Existing instant number tiles with a saved reducer now silently change value (Count turns every series into 1)

formPromqlExpressions (packages/app/src/components/ChartEditor/utils.ts:512-517) has always saved reducer on Number tiles whatever the query type. Before this PR, appliesPromqlReducer ignored that reducer on instant queries. A tile that was set to Range + Count and later switched to Instant still stores reducer: Count, and with this change it will show 1 instead of the real value. The e2e step in promql-number.spec.ts confirms this: Instant + Count gives '1'. Fix: when the instant result is a plain vector (isBucketed: false, one sample per series), skip the reducer. Alternatively, drop or migrate stale reducers on instant number tiles, or hide Count for instant queries.

Nothing blocks merge automatically, but a maintainer will expect this fixed if it is a real defect in code this PR changes. If it is about surrounding code, reply and say so instead of patching. Do not widen the PR. How to respond

@pulpdrew
pulpdrew merged commit 4570d5e into main Oct 1, 2026
29 checks passed

This branch was successfully deployed

2 active deployments
Preview – hyperdx-oss — 303cfd9c Deployed Oct 1, 2026 by vercel[bot]
Preview – hyperdx-storybook — 303cfd9c Deployed Oct 1, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review/tier-3 Standard — full human review required

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants