Skip to content

feat: Filter time chart series into adhoc dashboard filters - #3405

Merged
pulpdrew merged 1 commit into
mainfrom
drew/adhoc-filters-click-timechart
Oct 20, 2026
Merged

pulpdrew merged 1 commit into
mainfrom
drew/adhoc-filters-click-timechart

Conversation

@pulpdrew

@pulpdrew pulpdrew commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR adds click-to-adhoc-filter functionality to timecharts (line, stacked bar, stacked line) via the series tooltip. The tooltip gains a new action button that adds all of a series' labels to the relevant adhoc filter.

Like #3389, the "filter keys" (expressions being filtered) are intended to be any group-by keys.

This determination is made as follows:

  • Builder charts: The group-by columns are matched to expressions in the GROUP BY by position in the result meta
  • Raw SQL line charts: The query is rendered (macros and variables replaced) and parsed with node-sql-parser (chSqlToSelectColumns in common-utils). Each outer SELECT item lines up with a result column by position. An item is filterable if the GROUP BY lists it by alias, by name, by normalized expression, or by position (GROUP BY 2). If the query can't be read that way (no GROUP BY, GROUP BY ALL, SELECT *, a parse failure, or a column count that doesn't match the result), we fall back to type-based determination. Any String, Map or Array column is filterable, keyed by the expression behind its alias, or by its quoted column name.
  • PromQL line charts: Each series' labels are kept from the Prometheus response, keyed by series name, and the series filters on all of them except name.

Exclude is offered only for series with a single key, because ANDed != conditions can't exclude one combination of values.

Screenshots or video

Screen.Recording.2026-10-20.at.9.38.35.AM.mov

How to test on Vercel preview

Create a dashboard, add some line charts and an adhoc filter on the same source, click some series tooltips to update the filter.

References

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

@pulpdrew
pulpdrew added this pull request to stack #3342 October 19, 2026 16:53
@vercel

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

Request Review

@changeset-bot

changeset-bot Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 13cab8d

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 commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

E2E Test Results

✅ All tests passed • 446 passed • 1 skipped • 1341s

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

Tests ran across 4 shards in parallel.

View full report →

@github-actions github-actions Bot added the review/tier-2 Low risk — AI review + quick human skim label Oct 19, 2026
@github-actions

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: 6
  • Production lines changed: 226 (+ 471 in test files, excluded from tier calculation)
  • Branch: drew/adhoc-filters-click-timechart
  • 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 19, 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 123 in total (1.62%).
Run yarn dupes locally to reproduce, or yarn dupes:all for the full picture.

@github-actions

github-actions Bot commented Oct 19, 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 · 🟠 0 major · 🔵 1 minor

None could be anchored to changed lines; they are listed below.

Findings outside the changed lines

1 minor
  • 🔵 packages/app/src/components/charts/ChartSeriesTooltip.tsx:433 — onFocus is always set, so the new actions.onFocus != null guard is dead code and the doc comment that Focus hides without a handler is wrong → Only set onFocus when onFocusSeries is provided: onFocus: onFocusSeries ? () => { onFocusSeries({ dataKey: payload.dataKey, name }); onDismiss?.(); } : undefined. That makes the guard and the comment at line ~80 true. Otherwise, drop the guard and fix the comment. Today a caller that omits onFocusSeries still gets a Focus button that only closes the tooltip. Every current caller passes onFocusSeries (DBTimeChart.tsx:340/1113, DBSearchPage.tsx:2620/2720), so the false branch can't happen.

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

@greptile-apps

greptile-apps Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with no new actionable findings.

Summary

Adds Filter and Exclude actions to pinned time-chart tooltips.

  • Time-chart tooltips can add a series to a dashboard filter.

pulpdrew accepted the risk that labels created by PromQL expressions may not match the input metrics, citing Grafana-compatible behavior and easy filter removal. The earlier file-size thread was manually resolved without explanation. Both previous threads were unnumbered, so neither has a numbered previous-finding entry.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Click a chart series] --> B[Pinned tooltip]
  B --> C[SQL group values or PromQL labels]
  C --> D[Filter]
  C --> E{One key?}
  E -->|Yes| F[Exclude]
  D --> G[Matching dashboard filters]
  F --> G
  G --> H[Charts reload]
Loading

Reviews (4) · Last reviewed commit: "feat: Filter time chart series into adho..." · Reviewed by Greptile

@github-actions

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Deep Review

✅ No critical issues found. No P0/P1 defects: the filter-value path is injection-safe (values are escaped via escapeSqlString / escapePromqlStringValue, and PromQL tiles restrict clicks to promql-sourceType targets), types are sound, hook dependency arrays are complete, and no click/stream race was reproducible. The items below are recommendations and nits.

🟡 P2 — recommended

  • packages/app/src/utils/promqlChartQuery.ts:164 — When two PromQL series render to the same display name, promqlSeriesLabels[seriesName] = metric keeps only the last write, so "Filter for this series" can apply a different series' labels to the broadcast adhoc filter.
    • Fix: Detect colliding rendered series names and either disambiguate the key or suppress the filter offer for collided series, and add a test locking the behavior.
    • correctness, adversarial, kieran-typescript, testing
🔵 P3 nitpicks (4)
  • packages/app/src/components/charts/ChartSeriesTooltip.tsx:410 — The file is 465 lines (over the repo's 300-line component-size standard) and this diff grows it further with the filter wiring; DBTimeChart.tsx (1164 lines) is similarly worsened. Both were already over the limit, and this was raised in prior review feedback that remains unaddressed.
    • Fix: Extract the series-filter helpers and SeriesRow/SeriesAction into a sibling module to stop growing the files.
    • previous-comments, project-standards
  • packages/app/src/components/charts/ChartSeriesTooltip.tsx:324 — showPerSeriesActions now only gates the multi-series cluster (Search/Focus); Filter/Exclude render for a lone series too, so the name misleads readers of the showPerSeriesActions ? {...} : filterActions ternary.
    • Fix: Rename to something like showMultiSeriesActions.
  • packages/app/src/components/DBTimeChart.tsx:175 — The PromQL branch returns [] (not undefined) for a series whose only label is __name__, contradicting the function's documented "returns undefined when it can't be filtered on" contract; it is handled downstream by the seriesFilters?.length guard so there is no bug.
    • Fix: Return undefined when the filtered label list is empty for a uniform contract.
  • packages/app/src/components/DBTimeChart.tsx:175 — String(value) on a non-string group-by value (notably Float64, which isAdhocComparableDataType still allows) can diverge from ClickHouse's toString(col) formatting, producing an equality that matches nothing.
    • Fix: Confirm numeric/float group-by values round-trip into a matching adhoc equality, and add an end-to-end test for a numeric group-by column.
    • correctness, adversarial

Reviewers (8): correctness, adversarial, kieran-typescript, julik-frontend-races, testing, maintainability, project-standards, previous-comments.

Testing gaps:

  • No test for two PromQL expressions producing a colliding rendered series name (last-write-wins on promqlSeriesLabels).
  • No test for numeric/float/bool group-by values flowing through String(value) into the adhoc equality.
  • No test for a dataKey present in the pinned activePayload but absent from lineDataByKey (stale tooltip) confirming the filter buttons are suppressed.
  • No builder test with multiple value columns and multiple group-by columns to lock positional alignment.

Note: The label_replace-style PromQL case (filtering can empty a chart when output labels aren't on the input selector) was explicitly accepted by the author as a Grafana-compatible trade-off and withdrawn by the prior reviewer; no action expected.

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

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

Image

LGTM - one small UX thing - its weird that "Filter for this series" will toggle/unselect it when there is an exclude button right beside it. Though, not sure if thats easy to fix

@pulpdrew
pulpdrew force-pushed the drew/adhoc-filters-click-timechart branch from 54c9abf to 13cab8d Compare October 20, 2026 17:34
@pulpdrew
pulpdrew merged commit 7db73cf into main Oct 20, 2026
41 of 44 checks passed

This branch was successfully deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants