Skip to content

fix: Respect explicit granularity on heatmaps - #3305

Merged
kodiakhq[bot] merged 6 commits into
mainfrom
drew/heatmap-granularity
Oct 7, 2026
Merged

kodiakhq[bot] merged 6 commits into
mainfrom
drew/heatmap-granularity

Conversation

@pulpdrew

@pulpdrew pulpdrew commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR makes a couple of fixes to heatmaps:

  1. Explicit granularity selections (non-auto) are respected. Previously, auto was always used, and targeted 245 buckets. Auto still targets 245 buckets.
  2. Metric source's minGranularitySeconds is respected, putting a floor on auto granularity

Screenshots or video

Screen.Recording.2026-10-06.at.4.23.08.PM.mov

How to test on Vercel preview

  • Try a heatmap with varying granularities, in distribution and series modes, on chart explorer, dashboards, and search event deltas.

References

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

@vercel

vercel Bot commented Oct 6, 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 7, 2026 4:32pm UTC
hyperdx-storybook Ready Ready Preview Oct 7, 2026 4:32pm UTC

Request Review

@changeset-bot

changeset-bot Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 5ff7ff1

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

This PR includes changesets to release 3 packages
Name Type
@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 added the review/tier-2 Low risk — AI review + quick human skim label Oct 6, 2026
@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

🔵 Tier 2 — Low Risk

Small, isolated change with no API route or data model modifications.

Why this tier:

  • Standard feature/fix — introduces new logic or modifies core functionality

Review process: AI review + quick human skim (target: 5–15 min). Reviewer validates AI assessment and checks for domain-specific concerns.
SLA: Resolve within 4 business hours.

Stats
  • Production files changed: 11
  • Production lines changed: 168 (+ 428 in test files, excluded from tier calculation)
  • Branch: drew/heatmap-granularity
  • Author: pulpdrew

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

@github-actions

github-actions Bot commented Oct 6, 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 127 in total (1.77%).
Run yarn dupes locally to reproduce, or yarn dupes:all for the full picture.

@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

PR Review

✅ No issues found.

@greptile-apps

greptile-apps Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium risk] Heatmap chart granularity and display logic.

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

What we checked:

  • First bucket stays in range: The inner query keeps the selected event range. Only the outer filter on bucket timestamps is widened to bucket boundaries.

Summary

Heatmaps now respect explicit intervals. Series heatmaps also respect metric sources’ minimum auto interval.

  • Live dashboard heatmaps keep their finer auto interval, including fullscreen.
  • Aggregate distribution queries preserve the selected event range while keeping the first bucket.
  • pulpdrew accepted the single-bucket warning as intentional because a one-column heatmap is not useful. Greptile withdrew that finding.
  • pulpdrew disputed the browser-memory finding because the ClickHouse client imposes a row limit. Greptile conceded and withdrew it.
  • The aggregate-query, first-bucket, and outside-event threads were resolved without explanatory replies. The current code addresses their reported causes.

Reviews (9) · Last reviewed commit: "Merge branch 'main' into drew/heatmap-gr..." · Reviewed by Greptile

@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

E2E Test Results

✅ All tests passed • 403 passed • 1 skipped • 1466s

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

Tests ran across 4 shards in parallel.

View full report →

@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Deep Review

✅ No critical issues found. No P0/P1 defects: the alignment math (getAlignedDateRange on outer bucket-label filters, original range preserved on inner CTEs), the live-dashboard granularity → undefined special case, and the highlightDataPlugin box-clamping were all traced and are correct on the happy path. The items below are a recommended guard and a set of nits.

🟡 P2 -- recommended

  • packages/app/src/components/DBHeatmapChart/heatmapQueries.ts:61 -- Honoring an explicit granularity verbatim removes the former 245-bucket ceiling, so a fine granularity over a long range makes the client bucket array, the N×80 grid, and the ClickHouse bounds/bucket queries scale unboundedly with user input (e.g. 30 second over 30 days ≈ 86,400 synchronous Date objects in a render-path useMemo plus a multi-million-cell grid and result set); before this PR heatmaps were pinned to auto and immune, and the granularity picker is now shown on the heatmap tab.
    • Fix: In resolveHeatmapGranularity, when granularity is explicit, coarsen or clamp it so dateRange / granularity cannot exceed a bounded multiple of HEATMAP_AUTO_GRANULARITY_BUCKETS, and/or cap the length of timeBucketByGranularity output.
    • adversarial, performance
🔵 P3 nitpicks (5)
  • packages/app/src/components/DBHeatmapChart/useHeatmapData.ts:40 -- The distribution path forwards only { dateRange, granularity } to useHeatmapTimeBuckets, dropping minGranularitySeconds that callers thread in via getMinGranularitySeconds(source), while the series path passes the whole config; this is inert today since distribution heatmaps are Trace-only and the floor is always undefined for Trace, but it is an undocumented asymmetry and a trap if distribution ever gains metric-source support.
    • Fix: Pass the full config (or minGranularitySeconds: config.minGranularitySeconds) into useHeatmapTimeBuckets for symmetry, or drop the now-dead distribution caller plumbing and add a comment explaining why distribution ignores the floor.
    • correctness, adversarial, kieran-typescript, maintainability, testing
  • packages/app/src/DBDashboardPage.tsx:730 -- A builder heatmap tile's saved explicit granularity is overwritten by the dashboard-level granularity in setQueriedConfig, so on the non-live dashboard surface a heatmap no longer renders at its own saved granularity; this was inert before the PR (heatmaps ignored granularity) and now partially undercuts the PR's explicit-granularity goal.
    • Fix: Confirm whether dashboard granularity should supersede a heatmap tile's saved granularity on non-live dashboards; if not, preserve the tile's own granularity the way the live case already special-cases it.
    • adversarial, correctness
  • packages/app/src/components/DBHeatmapChart/highlightDataPlugin.ts:76 -- The clamp uses u.over.clientWidth/clientHeight as the max bound with no guard, so a setCursor firing with a stale or zero over size mid-resize collapses every cell to a zero-size highlight box for a frame.
    • Fix: When plotWidth/plotHeight is 0/NaN, fall back to the unclamped cell bounds.
    • julik-frontend-races, correctness
  • packages/app/src/components/DBHeatmapChart/__tests__/highlightDataPlugin.test.ts:78 -- The new clip-to-plot test exercises only the right-edge clamp-to-max path; the lower-bound Math.max(v, 0) branch (left/top edge cell at a negative coordinate) and the zero-size-plot case are untested.
    • Fix: Add a left/top edge-cell case that clamps a negative coordinate to 0 and a zero-dimension plot case.
    • testing
  • packages/app/src/ChartUtils.tsx:101 -- The new generic getTimeChartGranularity<T extends string> collapses to string for every caller since SQLInterval is a string alias, so it adds a type parameter without buying safety or literal preservation.
    • Fix: Use a concrete granularity: SQLInterval | 'auto' | undefined signature returning SQLInterval.
    • kieran-typescript, maintainability

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

Testing gaps:

  • No test exercises an explicit fine granularity over a large date range to assert a bounded bucket/column count (the P2 blowup path is uncovered).
  • highlightDataPlugin lower-bound clamp and zero-size-plot branches are untested.
  • No test covers a metric-source distribution heatmap (currently blocked by source-kind gating) — the exact path where the dropped minGranularitySeconds floor would bite if gating changes.
  • No end-to-end test asserts generatedTsBuckets align with the aggregate bucket query's aligned-dateRange __hdx_time_bucket labels; ChartPreviewPanel.test.tsx mocks the build helpers to identity, so granularity resolution in the SQL-preview path is not asserted end-to-end.

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/DBDashboardPage.tsx Resolved
Comment thread packages/app/src/DBDashboardPage.tsx Resolved
@pulpdrew
pulpdrew force-pushed the drew/heatmap-granularity branch from 69c5228 to f18f4f6 Compare October 7, 2026 12:21
@pulpdrew
pulpdrew marked this pull request as ready for review October 7, 2026 12:22

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Changes here ensure the highlight on hover doesn't extend past the left and right bounds of the heatmap, which was obvious at longer granularities.

@pulpdrew
pulpdrew requested a review from karl-power October 7, 2026 13:17
@kodiakhq
kodiakhq Bot merged commit 3e34efa into main Oct 7, 2026
29 checks passed

This branch was successfully deployed

2 active deployments
Preview – hyperdx-oss — 5ff7ff1b Deployed Oct 7, 2026 by vercel[bot]
Preview – hyperdx-storybook — 5ff7ff1b Deployed Oct 7, 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-2 Low risk — AI review + quick human skim

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants