Skip to content

feat: add groundwork for an "All" option on dashboard filters - #3830

Open
karl-power wants to merge 1 commit into
mainfrom
claude/sql-filter-all-foundation
Open

karl-power wants to merge 1 commit into
mainfrom
claude/sql-filter-all-foundation

Conversation

@karl-power

@karl-power karl-power commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds the data model, macro behaviour, helpers and validation for an "All" option on static list and SQL query dashboard filters. Nothing can turn it on yet: there's no UI, and the external API and MCP reject the new fields. Follow-ups add the dropdown option, then enable it for each filter type.

  • allowAll on static list and SQL query filters opts a filter into offering "All". Multi-select filters only.
  • all: true on a saved variable selection (savedFilterValues and the filters= URL state) records that "All" is selected. Serialization keeps the entry even though it has no values.
  • all: true on ChartVariable marks "All" for template expansion. expandAllSelections fills such a variable's values with its filter's options.
  • $__conditionalAll(cond, $var) expands to 1=1 when "All" is selected, matching Grafana's ClickHouse plugin. $__filter and bare $var use the expanded options, as col IN ($var) does in Grafana.
  • filterSupportsAllValue limits "All" to filters whose option list the author controls. Query expression and Prometheus label options are capped and scoped to the time range, so "All" could miss values there.
  • validateDashboardFilterFieldGating rejects allowAll on a single-select filter. validateDashboardSavedFilterValues rejects all: true on a filter that doesn't offer "All"; it gets wired into the APIs with the UI.
  • The external API, and MCP through it, omits allowAll and all from its schemas until the dashboard UI offers "All".
  • The selection shape, helper names and filterSupportsAllValue mirror the existing source-filter "All" support in EE, so EE can switch to these after the next upstream merge.

How to test

  1. cd packages/common-utils && yarn ci:unit
  2. make dev-int FILE='src/routers/external-api/__tests__/dashboards.int.test.ts --testNamePattern=filter.validation'

How to test on Vercel preview

N/A — non-UI change

References

  • Linear Issue: HDX-6191

Note

Medium Risk
Touches dashboard filter validation, saved state serialization, and SQL variable macro expansion, but external API rejects new fields until the UI ships.

Overview
Adds backend support for an "All" dashboard filter selection on multi-select static list and SQL query filters, without exposing it through the external API or UI yet.

Filters can define allowAll; saved state and ChartVariable can carry all: true, with serialization, parsing, and expandAllSelections to fill options for query templates. SQL macros $__conditionalAll and $__filter treat "All" like Grafana (no-op / full IN list). New filterSupportsAllValue and validateDashboardSavedFilterValues gate where "All" is allowed; validateDashboardFilterFieldGating rejects allowAll on single-select filters.

The external API Zod schemas omit allowAll and saved-value all until the dashboard UI ships, with integration tests asserting 400 on those payloads.

Reviewed by Cursor Bugbot for commit f8f36ed. Bugbot is set up for automated code reviews on this repo. Configure here.

@karl-power
karl-power requested a review from a team as a code owner November 25, 2026 12:07
@vercel

vercel Bot commented Nov 25, 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 Dec 2, 2026 10:31am UTC
hyperdx-storybook Ready Ready Preview Dec 2, 2026 10:31am UTC

Request Review

@github-actions github-actions Bot added the review/tier-3 Standard — full human review required label Nov 25, 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 backend (packages/api) + 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: 7
  • Production lines changed: 178 (+ 280 in test files, excluded from tier calculation)
  • Branch: claude/sql-filter-all-foundation
  • Author: karl-power

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

@karl-power
karl-power force-pushed the claude/sql-filter-all-foundation branch from 0b6cbdd to 21db794 Compare November 25, 2026 12:08
@changeset-bot

changeset-bot Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: f8f36ed

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 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

E2E Test Results

✅ All tests passed • 491 passed • 1 skipped • 1076s

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

Tests ran across 4 shards in parallel.

View full report →

@github-actions

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

if (values?.type === 'variable') {
return {
included: new Set<string | boolean>(values.values),
included: new Set<string | boolean>(values.all ? [] : values.values),

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.

🟡 P2 — resolveFilterSelection turns an all: true entry into an empty selection, so the app drops "All" whenever any filter changes

rebuildEntries in packages/app/src/hooks/useDashboardFilters.tsx:101-110 re-derives every declared variable's entry from resolveFilterSelection and only writes one back when included.size > 0. An all: true entry now resolves to included(), so it gets dropped. Steps: load ?filters=[{"type":"variable","name":"env","values":[],"all":true}] (the URL parser accepts this because DashboardFilterValueSchema now allows all), then change any other filter, and env's "All" disappears. The new serializer test never covers this path. Fix: carry the all flag through resolveFilterSelection or rebuildEntries, for example by copying parsed.byVariable's all entry over as-is, and add a test that setFilterValue on a sibling filter keeps the all entry.

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

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.

Nothing sets all yet, so only a hand-written URL can reach this. The UI follow-up that adds the "All" option has to change useDashboardFilters.tsx anyway. I'll carry all through rebuildEntries there, with a test that changing a sibling filter keeps the entry.

@github-actions

github-actions Bot commented Nov 25, 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:

  • 🔴 P0/P1 in code this PR adds or changes: fix before asking for review.
  • 🟡 P2 in code this PR changes: your call. Fix if small, otherwise reply.
  • 🔵 P3 is collapsed at the bottom: nobody needs to act on it before merge.
  • 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
    priority. Reply with one sentence; if it is P0, 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 P0/P1 · 🟡 3 P2 · 🔵 1 P3

1 posted as inline comment(s) on the changed lines. 2 listed below. 1 P3 folded at the bottom.

Findings outside the changed lines

  • 🟡 P2 packages/api/src/routers/api/dashboards.ts:64 — The internal dashboards API accepts and stores allowAll and all: true with none of the new checks → StaticListDashboardFilterSchema, SqlQueryDashboardFilterSchema and VariableFilterValueSchema now admit allowAll and all. But addFilterIssues here never calls validateDashboardFilterFieldGating, and validateDashboardSavedFilterValues isn't wired anywhere. So POST/PATCH /api/dashboards today persists allowAll on a maxSelections: 1 filter, and all: true on any filter, including query expression filters. That contradicts the PR's "nothing can turn it on yet". Fix: add validateDashboardFilterFieldGating and validateDashboardSavedFilterValues to addFilterIssues, or strip/reject the new fields on the internal route until the UI ships.
  • 🟡 P2 packages/api/src/utils/externalApi.ts:252 — External GET still returns stored allowAll and all, which the external PUT now rejects → translateFilterToExternalFilter returns STATIC_LIST and SQL_QUERY filters with every stored field except the ones it explicitly omits, so allowAll comes back. convertToExternalDashboard (packages/api/src/routers/external-api/v2/utils/dashboards.ts:829) also returns savedFilterValues verbatim, including all: true. The input schemas in packages/api/src/utils/zod.ts strictly reject both, which breaks the documented promise that "a GET response can be PUT back verbatim" for the external API and the MCP patch/save flows. Fix: omit allowAll and the all flag on the output side as well, for as long as the input side holds them back.
🔵 1 P3 — no action needed before merge
  • 🔵 P3 packages/common-utils/src/variableSelection.ts:10 — VariableSelection, ALL_SELECTION, isAllSelection and selectionHasValue have no callers and add a third shape for "all" → Nothing outside the new test imports these. Their string[] | { all: true } shape is a third way to express "all", next to VariableFilterValue.all and ChartVariable.all, which must be kept in sync by hand. Fix: drop them until a caller needs them, or build the selection logic on the existing all flag and keep a single representation.

Priority comes from a separate grading pass over the finished review. P3 is folded here instead of posted inline. No finding blocks merge automatically; a maintainer decides.

@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Deep Review

✅ No critical issues found. This is additive, intentionally-dormant groundwork: no UI or API path can set allowAll/all yet (the external API and MCP strip both fields via .omit(...).strict()), and the macro/serialization changes are inert when all is unset. Reviewers confirmed the "behavior unchanged when all is absent" contract holds on every live path, that the new "All" value flows through the same escapeSqlString sink as any other selection (no injection vector), and that old persisted documents still parse (z.literal(true).optional()). Every risk below becomes live only once the follow-up wires the feature on, so they read as recommendations to settle before that happens rather than merge blockers.

🟡 P2 -- recommended

  • packages/common-utils/src/dashboardValidation.ts:348 -- validateDashboardSavedFilterValues has no production caller, and the internal persistence route (routers/api/dashboards.ts:65) never calls validateDashboardFilterFieldGating, so the internal schema accepts allowAll on a single-select filter and all:true on a filter that doesn't offer "All", while the external API only blocks them incidentally via strict unknown-key rejection.
    • Fix: Wire both validators into the internal addFilterIssues refinement (passing savedFilterValues) so the internal contract matches the external one, or add a tracking reference marking them as deliberately unwired until the UI lands.
    • adversarial, maintainability
  • packages/api/src/utils/externalApi.ts:252 -- the external read path passes allowAll (filters) and raw all:true (saved filter values at routers/external-api/v2/utils/dashboards.ts:829) through to the GET response, but the strict write schema rejects both, breaking the documented "a GET body can be PUT back verbatim" invariant once an internal writer persists either field.
    • Fix: Strip allowAll and all symmetrically on the read path while the feature is held back, so a GET body stays PUT-able.
    • api-contract
  • packages/common-utils/src/dashboardFilterValues.ts:198 -- resolveUncappedFilterSelection collapses an all:true selection to an empty included set, which is indistinguishable from "nothing selected", so a required all-capable filter with "All" chosen is counted unsatisfied by getUnsatisfiedRequiredFilters and blocks the tiles it should unblock.
    • Fix: Represent "All" distinctly in the FilterSelection shape, or special-case all:true in the required-filter check so the maximal selection is never treated as empty.
    • adversarial, correctness
  • packages/common-utils/src/variables.ts:98 -- a bare $var / col IN ($var) reference ignores all:true and renders empty values as IN (NULL) (matches nothing), whereas $__filter and $__conditionalAll both render 1=1 (matches everything) for the same unexpanded state, and no test pins this divergence.
    • Fix: Honor all:true in the bare-reference path (or guarantee expandAllSelections runs before substitution) and add a test asserting the SQL produced for an all:true variable with empty values.
    • adversarial, correctness, testing
  • .changeset/ -- no changeset accompanies a feat that adds runtime schema fields and query-rendering behavior to the published @hyperdx/common-utils and @hyperdx/api packages.
    • Fix: Add a changeset (likely a patch for both packages), or confirm with a maintainer that held-back groundwork intentionally ships without a release entry.
    • project-standards
🔵 P3 nitpicks (3)
  • packages/common-utils/src/variableSelection.ts:26 -- selectionHasValue declares a selection is VariableSelection predicate but returns false for a valid empty string[], so its negative branch unsoundly narrows a real empty-array selection to undefined.
    • Fix: Return a plain boolean and drop the type predicate, which narrows to the whole union and provides no useful guard.
  • packages/common-utils/src/variableSelection.ts:1 -- the entire new module (VariableSelection, ALL_SELECTION, isAllSelection, selectionHasValue, expandAllSelections) has zero production consumers and introduces a second "all" representation that competes with the all?: true flag the rest of the diff actually uses.
    • Fix: Pick one representation before the consumer lands and drop the unused union, or defer the module to the PR that wires it up.
  • packages/common-utils/src/__tests__/filters.test.ts:2081 -- the filterSupportsAllValue "other filter types" case only asserts QUERY_EXPRESSION, leaving PROMETHEUS_LABEL and ADHOC uncovered despite the doc comment calling out Prometheus labels.
    • Fix: Add PROMETHEUS_LABEL and ADHOC with allowAll:true to the case so a future widening of the type check is caught.

Reviewers (11): correctness, adversarial, security, testing, maintainability, api-contract, project-standards, agent-native, previous-comments, kieran-typescript, learnings-researcher.

Testing gaps:

  • No test exercises an all:true variable with un-expanded (empty) values through $__filter / bare $var — the realistic state the feature ships in until expansion is wired.
  • No GET→PUT round-trip test with an internally-persisted allowAll:true filter or all:true saved value (would currently 400, surfacing the read/write asymmetry).
  • No test asserts an "All"-expanded option value containing SQL metacharacters is escaped identically to an ordinary selection, nor that the internal persistence route rejects invalid allowAll/all.

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

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

LGTM, but one question about the intent / approach

Comment on lines +516 to +517
const sqlAllNoOp = (name: string) =>
`(1=1 /** all values selected for variable '${name}' */)`;

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.

OOC will this be configurable? Because for a filter that is dependent on another, "all values shown in the drop down" may not match "all values in the table" (1=1). Grafana compatibility makes sense though.

I am also wondering - what's the difference here between "No selection" and an "All selection" in this case? Both would get 1=1, right? I might not see the utility of a 1=1 all selection when we're not broadcasting an actual list of values.

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.

will this be configurable?

Depending on what you choose in the query, you can get the desired result: $__filter(whatever, $var) and $var use the narrowed dropdown's options, and $__conditionalAll gives 1=1 (so the whole set, not narrowed)

what's the difference here between "No selection" and an "All selection" in this case

For $__conditionalAll they're both 1=1. For $__filter, no selection is 1=1 and All is IN every option

if (values?.type === 'variable') {
return {
included: new Set<string | boolean>(values.values),
included: new Set<string | boolean>(values.all ? [] : values.values),

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.

🟡 P2 — resolveFilterSelection turns an "all" entry into an empty selection, so callers can't tell "All" from "nothing selected"

FilterSelection has no way to carry "all", and the callers in packages/app/src/hooks/useDashboardFilters.tsx treat an empty included set as no selection. Two things break. First, rebuildEntries (line 105) only writes a variable back when selection.included.size > 0, so changing any sibling filter quietly removes another filter's {all: true} entry from the URL. Second, getUnsatisfiedRequiredFilters (line 400) counts a required filter with "All" selected as unsatisfied and blocks its tiles. parseDashboardFilterValues already accepts all: true from the filters= URL param today, so both paths can be hit now. Fix: carry an all flag through FilterSelection, or have resolveFilterSelection return the selection in a form that keeps it. Then update rebuildEntries and getUnsatisfiedRequiredFilters to keep "all" and count it as satisfying the filter. The new test at dashboardFilterValues.test.ts:458 locks in the current flattening, so it needs to change with the fix.

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

name: z.string().min(1).max(1024),
values: z.array(z.string().max(10000)).max(1000),
/** When true, represents a selection of "all available values", and `values` is ignored. */
all: z.literal(true).optional(),

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.

🟡 P2 — Persisted variable entry accepts all: true together with non-empty values, which are then silently dropped

VariableFilterValueSchema lets {all: true, values: ['prod']} pass validation, and both serializeDashboardFilterValues and resolveFilterSelection throw values away. Because this format is stored in savedFilterValues and in filters= URLs, any shape accepted now has to stay valid forever. Make the invalid state unrepresentable before it ships: either a discriminated variant {type:'variable', name, all: true} with no values, or a refinement that requires values to be empty when all is set.

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

- Add `allowAll` to static list and SQL query filters, and `all: true` to saved
  variable selections and chart variables
- `$__conditionalAll` expands to `1=1` when "All" is selected, matching Grafana;
  `$__filter` and bare references keep the expanded options
- Add `filterSupportsAllValue`, "all" selection helpers,
  `expandAllSelections` and validation for `allowAll` and saved "all" values
- The external API and MCP reject `allowAll` and `all` until the dashboard UI
  offers "All"
@karl-power
karl-power force-pushed the claude/sql-filter-all-foundation branch from 24e89e5 to f8f36ed Compare December 2, 2026 10:28
if (values?.type === 'variable') {
return {
included: new Set<string | boolean>(values.values),
included: new Set<string | boolean>(values.all ? [] : values.values),

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.

🟡 P2 — An "all" selection resolves to an empty selection, so the app's rebuild drops it and required filters count it as unselected

FilterSelection has no way to say "all", so an "all" entry becomes included: new Set(). Three things follow. (1) rebuildEntries in packages/app/src/hooks/useDashboardFilters.tsx:101-110 writes nothing for an empty included set. The name is declared, so the pass-through loop doesn't keep the entry either. Changing any sibling filter therefore deletes {all: true} from the filters= URL, and the schema already accepts that entry today. (2) getUnsatisfiedRequiredFilters sees size 0 and treats a required filter set to "All" as unsatisfied, which blocks its tiles. (3) The ChartVariables built at useDashboardFilters.tsx:336-350 never carry all, so $__conditionalAll gets no "all" signal. Fix: return an "all" marker from resolveFilterSelection (or a separate lookup), and have rebuildEntries, the required-filter check and ChartVariable construction keep it. The new test that pins the empty-set result locks in the lossy behaviour.

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

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit f8f36ed. Configure here.

// offers "All".
const externalStaticListFilterShape = StaticListDashboardFilterSchema.omit({
allowAll: true,
}).extend({

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

GET responses leak held-back All fields

Low Severity

Omitting allowAll and all from the external request schemas does not strip them from GET responses. translateFilterToExternalFilter forwards the stored filter, and convertToExternalDashboard copies savedFilterValues as-is. The internal schema already persists these fields, so a GET body PUT back fails .strict() validation.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit f8f36ed. Configure here.

This branch was successfully deployed

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