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

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

@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 Nov 25, 2026 12:12pm UTC
hyperdx-storybook Ready Ready Preview Nov 25, 2026 12:12pm 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.

- 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 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: 21db794

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 • 476 passed • 1 skipped • 1083s

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

Tests ran across 4 shards in parallel.

View full report →

@github-actions

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 107 in total (1.12%).
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

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.

3 finding(s): 🔴 0 P0/P1 · 🟡 2 P2 · 🔵 1 P3

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

Findings outside the changed lines

  • 🟡 P2 packages/api/src/routers/api/dashboards.ts:66 — The new allowAll and all checks only run on the external API, which already strips both fields; the internal API accepts and stores invalid combinations → DashboardFilterSchema and DashboardFilterValueSchema now accept allowAll and all: true. The internal router's addFilterIssues does not call validateDashboardFilterFieldGating, and nothing calls validateDashboardSavedFilterValues. The same is true of provisioning in packages/api/src/tasks/provisionDashboards/index.ts. So the internal API stores {allowAll: true, maxSelections: 1}, or all: true on a filter without allowAll. On the external API (packages/api/src/routers/external-api/v2/utils/dashboards.ts:2016) allowAll is omitted from the shape, so the new branch can never fire there. Fix: call both validators from the internal router and provisioning now. Otherwise these invalid combinations get saved and stay valid stored data when the UI ships.
🔵 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 way to represent "All" → Grep finds no uses outside the new test. "All" is already modelled as VariableFilterValue.all and ChartVariable.all, and this adds a third, unused string[] | {all: true} shape that would have to be kept in sync by hand. Fix: drop these exports until a caller needs them, or build them on the existing all flag instead of a separate marker type.

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

Copy link
Copy Markdown
Contributor

Deep Review

✅ No critical issues found. This is carefully-scoped groundwork behind an off-switch: the new allowAll/all fields have no production writer or reader yet, so nothing below is a current production break. The findings cluster around one theme worth fixing before this lands — the external hold-back is asymmetric (ingress rejects the new fields, egress does not strip them) — plus latent traps the follow-up wiring will hit.

🟡 P2 — recommended

  • packages/api/src/utils/externalApi.ts:252 — translateFilterToExternalFilter strips minSelections/isGlobalRequirement (and connection/source for SQL_QUERY at line 266) but not allowAll, so a stored allowAll leaks on external GET and MCP get_dashboard while ingress .strict() rejects it, breaking the "GET response can be PUT back verbatim" contract noted at line 244.
    • Fix: Add allowAll to the omit lists for the STATIC_LIST and SQL_QUERY branches so egress matches the ingress omit.
    • api-contract, kieran-typescript
  • packages/api/src/routers/external-api/v2/utils/dashboards.ts:825 — savedFilterValues is assigned straight from the stored document with no translation, so a stored variable value carrying all: true leaks on external GET/MCP read even though externalVariableSavedFilterValueSchema.strict() rejects it on write.
    • Fix: Map savedFilterValues through a translator that drops all from variable entries, symmetric with the ingress .omit({ all: true }).
    • api-contract
  • packages/common-utils/src/variables.ts:97 — formatVariableValues never consults all, so an { all: true, values: [] } variable (the state expandAllSelections leaves when options are not yet known) renders IN (NULL) (matches nothing) through a bare $var but 1=1 (matches everything) through $__filter/$__conditionalAll, and nothing enforces that expansion runs before substitution.
    • Fix: Make the bare-reference render path all-aware (emit the all-no-op or refuse to render until expanded), or assert that an all: true variable never reaches substituteVariables with empty values.
    • adversarial, correctness, testing
  • packages/common-utils/src/dashboardFilterValues.ts:198 — filterSupportsAllValue does not exclude required filters and resolveUncappedFilterSelection maps all: true to an empty included set (no all marker on FilterSelection), so getUnsatisfiedRequiredFilters reads "All" as "nothing selected" and blocks the filter's tiles, while serialize/broadcast treat the same state as "match all".
    • Fix: Carry an explicit "all" marker on FilterSelection, or treat all: true as satisfying the required-filter check, before the UI can set it.
    • adversarial
  • .changeset/ — No changeset accompanies behavior-affecting additions to the published @hyperdx/common-utils package (new accepted schema fields and new substituteVariables handling of all), per the repo's documented rule; this is a judgment call since the fields are held back from the external API.
    • Fix: Add a patch changeset via yarn changeset if the internal behavior change is release-worthy, or confirm it is inert groundwork that needs none.
    • project-standards
🔵 P3 nitpicks (5)
  • packages/common-utils/src/dashboardValidation.ts:348 — validateDashboardSavedFilterValues is defined and unit-tested but wired into no production path, so a stored all: true on a non-all-capable filter is unvalidated on the internal save path today.
    • Fix: Confirm the follow-up wires it into the internal dashboard refinement, or track it so the rule is not silently unenforced.
    • correctness, maintainability, api-contract, security, agent-native
  • packages/common-utils/src/dashboardValidation.ts:306 — The new single-select allowAll gating branch cannot fire in production (external ingress strips allowAll before the refinement runs; the internal router never calls this validator), so the types.ts:2428 comment "Multi-select filters only" overstates enforcement.
    • Fix: Note that the gating activates only once the internal path accepts allowAll, or soften the schema comment.
    • correctness
  • packages/common-utils/src/variableSelection.ts:7 — The entire new module (VariableSelection, ALL_SELECTION, isAllSelection, selectionHasValue, expandAllSelections) has no production consumer; only its own tests import it.
    • Fix: Acceptable as stated EE groundwork, but track the follow-up that wires it in so it does not become orphaned.
    • maintainability, testing, kieran-typescript
  • packages/common-utils/src/variableSelection.ts:28 — selectionHasValue returns the type predicate selection is VariableSelection, which is unsound on the false branch because an empty array is still a VariableSelection yet returns false, so a future caller relying on the narrowing would treat a real [] selection as absent.
    • Fix: Return plain boolean, since "has a value" does not cleanly partition the type.
    • kieran-typescript
  • packages/common-utils/src/variableSelection.ts:10 — ALL_SELECTION is an exported, non-frozen shared mutable object ({ all: true }), risking accidental mutation across future call sites.
    • Fix: Object.freeze it, or drop the constant in favor of the isAllSelection guard once a consumer exists.
    • maintainability

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

Testing gaps:

  • No test exercises a bare $var / $__filter against an unexpanded all variable (all: true with empty values); the ALL_SERVICE fixture always pre-fills values, so the match-nothing-vs-match-all divergence is unexercised.
  • No external-API test asserts that a stored allowAll/all is stripped from a GET response or that such a GET round-trips cleanly back through PUT; the integration test covers only ingress rejection (400 on POST/PUT).
  • No test covers the validateDashboardSavedFilterValues interaction where a filter's allowAll was gated out (single-select) while a saved value sets all: true.

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

This branch was successfully deployed

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