Skip to content

feat: Support sparkline on promql number charts - #3178

Merged
kodiakhq[bot] merged 4 commits into
mainfrom
drew/promql-number-sparkline
Sep 28, 2026
Merged

kodiakhq[bot] merged 4 commits into
mainfrom
drew/promql-number-sparkline

Conversation

@pulpdrew

@pulpdrew pulpdrew commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Support sparklines for PromQL number charts. Sparklines are supported only for range queries, where the Sparkline can re-use the results range query that was already fetched and reduced for the number.

Further, range number queries are now aligned to the dashboard's time range and granularity, like timeseries charts would be, since a range query is bucketing similar to how a timeseries query would be. This has the added benefit of allowing the sparkline query to re-use the same query results.

Screenshots or video

Screen.Recording.2026-09-22.at.8.56.00.AM.mov

How to testlocally

  1. Setup a timeseries source against the metrics_ts table
  2. Create some number charts
  3. Add a sparkline

References

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

@changeset-bot

changeset-bot Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 7e621ce

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

This PR includes changesets to release 4 packages
Name Type
@hyperdx/app Patch
@hyperdx/common-utils 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

@vercel

vercel Bot commented Sep 22, 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 Sep 28, 2026 2:13pm UTC
hyperdx-storybook Ready Ready Preview Sep 28, 2026 2:13pm UTC

Request Review

@greptile-apps

greptile-apps Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium risk] Adds sparkline support to PromQL number tiles.

This PR appears safe to merge; no outstanding finding or new issue was identified.

Summary

This PR adds background sparklines to PromQL range-query number tiles.

  • The value and sparkline use the same aligned range-query results, with client-side reduction applied only to the value.
  • Display settings, saved chart configuration, and tests are updated for the new option.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  C[PromQL range number tile] --> Q[Aligned range query]
  Q --> B[Shared cached buckets]
  B --> R[Reducer]
  R --> V[Number value]
  B --> S[Background sparkline]
Loading

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

Comment thread packages/app/src/ChartUtils.tsx Resolved
@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Deep Review

✅ No critical issues found.

The core design is sound. The single-request optimization — where a PromQL number tile's value (reducer applied) and its background sparkline (no reducer) reuse one react-query cache entry — was verified directly: stripClientSideConfigFields (packages/app/src/utils/chartConfig.ts:9) removes reducer from each promql series before it becomes the query key, so both observers resolve to an identical key and Prometheus is queried once. Range-only date-range alignment, instant-query disabling, the multiple-series suppression gate, and the error-boundary isolation of sparkline failures all hold up against the code. No data-loss, injection, auth, or guaranteed-crash path was found in this diff.

The prior Greptile "Alignment Changes Number Values" thread was re-examined: alignment is applied only to range queries, where expanding to complete bucket boundaries is intentional and consistent with existing timeseries-chart alignment. The original reporter withdrew the finding, and the current code matches that model — no unaddressed correctness regression remains.

🟡 P2 — recommended

  • packages/app/src/components/NumberTileBackgroundChart.tsx:131 — The one-request cache-sharing optimization relies on an implicit invariant spread across convertToPromqlNumberChartConfig, stripClientSideConfigFields, and the queryKeyPrefix-vs-queryKey branch, with no test asserting the value and sparkline configs differ only by the stripped reducer field, so a later client-influencing promql field added to one path would silently split the shared entry into two Prometheus requests.
    • Fix: Add a test asserting the value and sparkline query keys are identical (or that stripClientSideConfigFields strips exactly the fields convertToPromqlNumberChartConfig varies) so the shared-cache contract fails loudly if it erodes.
    • maintainability, orchestrator-verification
🔵 P3 nitpicks (1)
  • packages/common-utils/src/core/promql.ts:129 — appliesPromqlReducer reads as an action verb but is a boolean predicate, breaking the is/has convention of its siblings (isRangeQuery, isReducibleRangeQuery).
    • Fix: Rename to hasPromqlReducer (or specifiesPromqlReducer) to signal a boolean return.

Pre-existing (not counted toward verdict)

  • packages/app/src/ChartUtils.tsx (~1513 lines), ChartDisplaySettingsDrawer.tsx (480), and DBNumberChart.tsx (421) exceed the repo's "keep files under 300 lines" guideline. Pre-existing; this diff only adds small increments and a split would be out of scope.

Reviewers (3 + orchestrator): maintainability, project-standards, learnings-researcher, plus orchestrator correctness/performance verification of the shared-cache design.

Coverage note: The remaining dispatched reviewers (correctness, adversarial, testing, performance, api-contract, kieran-typescript, julik-frontend-races, previous-comments, agent-native) had not returned results within this run's synthesis window; the correctness, performance, and prior-comment dimensions they target were covered directly by orchestrator verification against the source. No standards violations were introduced (changeset present and correct; cross-package imports and test placement conform).

Testing gaps: No test guards that stripClientSideConfigFields strips exactly the fields convertToPromqlNumberChartConfig varies between the value and sparkline configs — the invariant the single-request optimization depends on.

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

Comment thread packages/app/src/ChartUtils.tsx Resolved
@github-actions

github-actions Bot commented Sep 22, 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.

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

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

Findings outside the changed lines

1 minor
  • 🔵 packages/app/src/components/__tests__/DBNumberChart.test.tsx:678 — toHaveBeenCalledTimes(1) assertion is vacuous because NumberTileBackgroundChart is mocked → With NumberTileBackgroundChart mocked, its useQueriedChartConfig call never runs, so the count is 1 whether or not the sparkline shares the value's query. The test can't catch a regression that splits the two cache entries. Fix: render the real NumberTileBackgroundChart and assert that both configs passed to useQueriedChartConfig have the same stripClientSideConfigFields(...) and the same queryKeyPrefix, or drop the assertion.

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

Comment thread packages/app/src/ChartUtils.tsx Resolved
@pulpdrew
pulpdrew added this pull request to stack #3189 September 22, 2026 19:05
@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

E2E Test Results

✅ All tests passed • 287 passed • 1 skipped • 953s

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

Tests ran across 4 shards in parallel.

View full report →

@pulpdrew
pulpdrew requested a review from knudtty September 22, 2026 19:13
@pulpdrew
pulpdrew removed this pull request from stack #3189 September 22, 2026 19:31
@pulpdrew
pulpdrew changed the base branch from drew/promql-instant-number-charts to main September 22, 2026 19:45
@pulpdrew
pulpdrew force-pushed the drew/promql-number-sparkline branch from 86ec2d5 to 9fc2ace Compare September 22, 2026 19:46
@github-actions github-actions Bot added the review/tier-3 Standard — full human review required label Sep 22, 2026
@github-actions

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: 218 (+ 525 in test files, excluded from tier calculation)
  • Branch: drew/promql-number-sparkline
  • 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.

knudtty
knudtty previously approved these changes Sep 24, 2026

@knudtty knudtty 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.

Very cool!

Comment thread packages/app/src/ChartUtils.tsx Resolved
@github-actions

Copy link
Copy Markdown
Contributor

Duplicate code analysis

1 new clone introduced by this PR.

  • packages/app/src/hooks/useChartConfig.tsx:333-351 ↔ packages/app/src/hooks/useChartConfig.tsx:456-472 — 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 129 in total (1.84%).
Run yarn dupes locally to reproduce, or yarn dupes:all for the full picture.

@kodiakhq
kodiakhq Bot merged commit 8cfb267 into main Sep 28, 2026
42 of 44 checks passed
@kodiakhq
kodiakhq Bot deleted the drew/promql-number-sparkline branch September 28, 2026 14:26

This branch was successfully deployed

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

Labels

automerge review/tier-3 Standard — full human review required

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants