Skip to content

refactor: Split up DBHeatmap into smaller, focused files; Add tests - #3256

Merged
kodiakhq[bot] merged 3 commits into
mainfrom
drew/heatmap-generalization-0
Oct 1, 2026
Merged

kodiakhq[bot] merged 3 commits into
mainfrom
drew/heatmap-generalization-0

Conversation

@pulpdrew

@pulpdrew pulpdrew commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR splits the monolithic Heatmap component into several composable files, and improves test coverage (including with new E2E tests).

No behavior changes are expected, this is a pure refactor.

Motivation: subsequent PRs are going to extend Heatmap support to new use-cases (non-trace sources, raw SQL and PromQL).

Screenshots or video

Screenshot 2026-10-01 at 11 25 43 AM Screenshot 2026-10-01 at 11 25 56 AM

How to test on Vercel preview

References

  • Linear Issue: Related to HDX-5527
  • Related PRs:

@vercel

vercel Bot commented Oct 1, 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 5:04pm UTC
hyperdx-storybook Ready Ready Preview Oct 1, 2026 5:04pm UTC

Request Review

@changeset-bot

changeset-bot Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 35b95dc

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@github-actions github-actions Bot added the review/tier-4 Critical — deep review + domain expert sign-off label Oct 1, 2026
@github-actions

github-actions Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

🔴 Tier 4 — Critical

Touches authentication, tenancy data models, the public API or shipped database config — or substantially changes the query rendering engine, background tasks, the OTel pipeline, image build, or release CI.

Why this tier:

  • Large diff: 3111 production lines changed (threshold: 1000)

Review process: Deep review from a domain expert. Synchronous walkthrough may be required.
SLA: Schedule synchronous review within 2 business days.

Stats
  • Production files changed: 16
  • Production lines changed: 3111 (+ 1143 in test files, excluded from tier calculation)
  • Branch: drew/heatmap-generalization-0
  • Author: pulpdrew

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

@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Duplicate code analysis

No new duplicate code introduced by this PR.


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.81%).
Run yarn dupes locally to reproduce, or yarn dupes:all for the full picture.

@github-actions

github-actions Bot commented Oct 1, 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.

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

3 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 Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Deep Review

Pure refactor splitting the 1446-line DBHeatmapChart.tsx monolith into focused modules under packages/app/src/components/DBHeatmapChart/ plus unit and E2E tests. The split is faithful: the correctness reviewer verified query builders are byte-equivalent, the painter is pixel-equivalent (analytically), the computeBucketPercentiles y-value→row-index rekeying is value-equivalent, and all consumer-facing exports are preserved via index.ts. No behavior-changing bugs or security/data-integrity issues were found.

✅ No critical issues found.

🟡 P2 — recommended

  • packages/app/src/components/DBHeatmapChart/HeatmapPlot.tsx:304 — the one newly-created file that still exceeds the repo's documented 300-line limit, in a PR whose stated purpose is breaking down a large component.
    • Fix: Extract a cohesive block such as the uPlot options useMemo builder into a sibling module to bring the file under 300 lines.
    • maintainability, project-standards, previous-comments
  • packages/app/src/components/DBHeatmapChart/heatmapPaths.ts:54 — the new painter calls valToPosX/valToPosY four times per cell inside the per-draw loop (O(cells), up to ~80k conversions on a dense grid), whereas the monolith precomputed positions once per row and column (O(rows+cols)); impact is modest since conversions are cheap and draws fire only on create/resize/scale-change.
    • Fix: Precompute per-column x and per-row y pixel positions before the loop and index those arrays inside it, restoring the original amortized approach.
    • performance, previous-comments
  • packages/app/src/components/DBHeatmapChart/heatmapQueries.ts:134 — the module generating the ClickHouse widthBucket SQL (log-vs-linear, aggregate-vs-direct, countExpression default) has no direct unit tests and is mocked out by every consumer test, leaving the riskiest part of the planned multi-source extension unverified.
    • Fix: Add heatmapQueries.test.ts asserting the generated config for each branch (log vs linear expression, aggregate CTE vs direct path, countExpression defaulting to count()).
    • testing, maintainability
🔵 P3 nitpicks (9)
  • agent_docs/data_viz_colors.md:16 — doc references the heatmap palette as "imported directly from DBHeatmapChart.tsx" (also lines 225, 236, 499), but that file is now a directory and the arrays moved to palette.ts.
    • Fix: Update the palette references to point at DBHeatmapChart/palette.ts or the package index.
  • packages/app/src/components/DBHeatmapChart/heatmapGrid.ts:17 — the HeatmapYAxis 'series' variant and openTop flag have no producer; both grid builders emit {type:'numeric'} without openTop, so these are untested-in-prod extension branches.
    • Fix: Defer the 'series' variant and openTop until a consumer lands, or mark them explicitly as intentional placeholders.
  • packages/app/src/components/DBHeatmapChart/heatmapPaths.ts:103 — the module named for path rendering also owns the full base uPlot Options object (scales, axes, padding) and the shared axis const, so base chart config is hard to locate.
    • Fix: Move baseHeatmapOptions/axis into a heatmapOptions.ts module whose name matches its contents.
  • packages/app/src/components/DBHeatmapChart/heatmapPaths.ts:130 — the base options hardcode a trace-specific 'Latency' series label in a module being generalized for non-trace sources (pre-existing; legend is hidden so currently invisible).
    • Fix: Derive the label from config or drop it.
  • packages/app/src/components/DBHeatmapChart/HeatmapPlot.tsx:171 — non-null assertions u.scales.y!.min/u.scales.y!.max! in the log-splits function drop the y-scale-exists guard used elsewhere (pre-existing).
    • Fix: Use optional chaining with a fallback, mirroring the u.scales.y?.min pattern in selection.ts.
  • packages/app/src/components/DBHeatmapChart/heatmapPaths.ts:11 — the newly-exported heatmapPaths keeps disp.fill.values typed any, defeating type checking on the fill-index path now that makeCountsToFills has a concrete signature (pre-existing).
    • Fix: Type disp.fill.values as (u: uPlot, seriesIdx: number) => number[].
  • packages/app/src/components/DBHeatmapChart/highlightDataPlugin.ts:28 — if a background refresh settles while the tooltip is open and the cursor is stationary, setCursor never re-fires, so the tooltip and highlight box keep rendering the old cell's values over the new data (pre-existing).
    • Fix: Clear highlightedPoint and reset lastDataPointIndex when grid identity changes, e.g. a useEffect on [grid].
  • packages/app/src/components/DBHeatmapChart/heatmapGrid.ts:124 — exported gridFromBucketRows takes data: Record<string, any>[] and reads count/x_bucket/timestamp fields untyped on a newly-public surface (pre-existing).
    • Fix: Narrow to a documented row shape such as Record<string, string | number>.
  • packages/app/src/components/DBHeatmapChart/palette.ts:71 — several newly-exported helpers (makeCountsToFills, heatmapLowQuantile, computeEffectiveMin, formatHeatmapTick, heatmapRowCount, heatmapPaths) lack explicit return types on the public API (pre-existing).
    • Fix: Add explicit return types to the exported helpers for API stability.

Reviewers (10): correctness, testing, maintainability, project-standards, agent-native, learnings-researcher, performance, kieran-typescript, julik-frontend-races, previous-comments.

Testing gaps:

  • heatmapQueries.ts and useHeatmapData.ts have no direct unit tests; both are only exercised through mocked consumers and full-stack E2E.
  • No test asserts pixel/geometry equivalence between the old uniform-bin painter and the new per-extent painter (equivalence verified analytically only), nor covers the overflow/underflow rows (j=0, j=nBuckets+1) end-to-end.
  • No test exercises a data refresh while the tooltip is open (stationary cursor) to catch the stale-tooltip behavior above.
  • The prior-review concern that E2E tests passed on an empty canvas is resolved: both the search and dashboard specs now call hoverPopulatedCell(), which requires a "Count Value:" tooltip that only renders for non-zero cells.
  • The adversarial reviewer did not return before synthesis; its coverage was substituted by the orchestrator's own edge-case probing (empty data, degenerate extents, selection/lifecycle, value-equivalence) and the correctness reviewer's exhaustive monolith comparison, which found no behavior regressions.

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

@github-actions

github-actions Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

E2E Test Results

✅ All tests passed • 393 passed • 1 skipped • 1347s

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

Tests ran across 4 shards in parallel.

View full report →

@greptile-apps

greptile-apps Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium risk] Refactors heatmap chart into smaller modules with new tests.

The PR appears safe to merge; no new actionable failure was established.

Summary

The PR separates the heatmap’s query, grid, plotting, and tooltip logic into focused files and adds unit and end-to-end coverage.

  • The change since the previous review updates the API’s ip-address dependency and matching lockfile entry.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  Q[Heatmap queries] --> D[useHeatmapData]
  D --> G[Heatmap grid]
  G --> P[HeatmapPlot]
  P --> C[Canvas and tooltip]
Loading

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

@brandon-pereira brandon-pereira left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM - Thanks!

@kodiakhq
kodiakhq Bot merged commit 51d35da into main Oct 1, 2026
29 checks passed
@kodiakhq
kodiakhq Bot deleted the drew/heatmap-generalization-0 branch October 1, 2026 17:10

This branch was successfully deployed

2 active deployments
Preview – hyperdx-oss — 35b95dcc Deployed Oct 1, 2026 by vercel[bot]
Preview – hyperdx-storybook — 35b95dcc 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

automerge review/tier-4 Critical — deep review + domain expert sign-off

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants