Skip to content

feat: add an "All" option to SQL query dashboard filters - #3861

Open
karl-power wants to merge 1 commit into
claude/sql-filter-all-static-listfrom
claude/sql-filter-all-sql-query
Open

karl-power wants to merge 1 commit into
claude/sql-filter-all-static-listfrom
claude/sql-filter-all-sql-query

Conversation

@karl-power

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

Copy link
Copy Markdown
Contributor

Summary

SQL query dashboard filters can now offer "All", which selects every option the filter's query returns. Stacked on #3847, which added "All" for static list filters.

  • The SQL query filter settings get the Include "All" option checkbox, hidden for single-select filters.
  • The dashboard page loads the options of SQL query filters with "All" selected and fills them in for tiles. It runs the same query as the filter's dropdown, so the result is shared, not fetched twice.
  • Tiles that reference the variable wait for the options, and show an error when they can't be loaded or there are more than 1,000. The tile editor's preview does the same.
  • The SQL query filter form explains, under its SQL editor, how "All" on other filters behaves in its options query.
  • The external API and MCP accept allowAll on SQL query filters. MCP query_tile and query_tiles with all: true run the filter's query to fill in its options.
  • The 1,000-option cap is documented in the checkbox, OpenAPI and MCP descriptions.
  • toSqlQueryFilterValues and the values query settings moved to common-utils so the app and MCP run the query the same way.

Behaviour notes

  • In tiles, "All" makes $variable and $__filter use every returned option; $__conditionalAll becomes 1=1.
  • In dependent filter queries, including filter-editor previews, a SQL query filter's "All" means no constraint: both macros become 1=1, while bare $variable becomes NULL. Use macros for these dependencies to avoid filtering out every option. Static-list "All" still supplies its full option list; $__conditionalAll remains unconstrained.
  • Tiles and tile-editor previews that reference the variable wait for its options. Failed queries or more than 1,000 options show an error instead of running; unrelated tiles remain usable.
  • Empty results behave like nothing selected: bare $variable becomes NULL, and both macros become 1=1.
  • The options query stops after 30 seconds and returns partial results, so "All" can silently select an incomplete list.
  • MCP expands every SQL query filter passed all: true; one failed or over-cap filter fails the whole call, even for unrelated tiles.

How to test

On this branch, import this dashboard to ClickStack and follow the instructions:
{"version":"0.1.0","name":"TEST: SQL query All — tiles and editor","tags":["testing","sql-filters","all-option"],"tiles":[{"id":"6b0d3d27e6df08cb05ff4ef4","x":0,"y":0,"w":24,"h":7,"config":{"name":"Start here","source":"","displayType":"markdown","markdown":"**Keep Region set to All; change Scenario to test.** This demo uses 1,002 synthetic rows (region IDs 0–1001), so no telemetry data is needed.\n\n- **Ready:** 3 options → bare / filter / conditionalAll = **3 / 3 / 1,002**.\n- **At limit:** 1,000 options → **1,000 / 1,000 / 1,002**.\n- **Over limit:** 1,001 options → dependent tiles and editor previews show the cap error.\n- **Query error:** deliberate options-query failure → dependent tiles and editor previews show the error.\n- **Loading:** about 10 seconds of loading, then **5 / 5 / 1,002**. Change **Run** to repeat with an uncached query.\n- **Empty:** zero options → **0 / 1,002 / 1,002**, the documented empty-selection behavior.\n\nThe **Unrelated control** must stay at **1,002**, even while other tiles are blocked.","select":[],"where":""}},{"id":"6b0d3d27e6df08cb05ff4ef5","x":0,"y":7,"w":6,"h":4,"config":{"displayType":"number","numberFormat":{"output":"number","mantissa":0,"thousandSeparated":true},"configType":"sql","sqlTemplate":"SELECT count() AS \"Matching rows\"\nFROM (SELECT number AS region_id, toString(number) AS region, $__fromTime_ms AS ts FROM numbers(1002))\nWHERE $__timeFilter_ms(ts)\n  AND region IN ($region)\nLIMIT 1","connection":"Local ClickHouse","name":"Bare variable — selected IDs"}},{"id":"6b0d3d27e6df08cb05ff4ef6","x":6,"y":7,"w":6,"h":4,"config":{"displayType":"number","numberFormat":{"output":"number","mantissa":0,"thousandSeparated":true},"configType":"sql","sqlTemplate":"SELECT count() AS \"Matching rows\"\nFROM (SELECT number AS region_id, toString(number) AS region, $__fromTime_ms AS ts FROM numbers(1002))\nWHERE $__timeFilter_ms(ts)\n  AND $__filter(region, $region)\nLIMIT 1","connection":"Local ClickHouse","name":"Filter macro — selected IDs"}},{"id":"6b0d3d27e6df08cb05ff4ef7","x":12,"y":7,"w":6,"h":4,"config":{"displayType":"number","numberFormat":{"output":"number","mantissa":0,"thousandSeparated":true},"configType":"sql","sqlTemplate":"SELECT count() AS \"Matching rows\"\nFROM (SELECT number AS region_id, toString(number) AS region, $__fromTime_ms AS ts FROM numbers(1002))\nWHERE $__timeFilter_ms(ts)\n  AND $__conditionalAll(region IN ($region), $region)\nLIMIT 1","connection":"Local ClickHouse","name":"conditionalAll — unconstrained on All"}},{"id":"6b0d3d27e6df08cb05ff4ef8","x":18,"y":7,"w":6,"h":4,"config":{"displayType":"number","numberFormat":{"output":"number","mantissa":0,"thousandSeparated":true},"configType":"sql","sqlTemplate":"SELECT count() AS \"Matching rows\"\nFROM (SELECT number AS region_id, toString(number) AS region, $__fromTime_ms AS ts FROM numbers(1002))\nWHERE $__timeFilter_ms(ts)\nLIMIT 1","connection":"Local ClickHouse","name":"Unrelated control — always 1,002"}},{"id":"6b0d3d27e6df08cb05ff4ef9","x":0,"y":11,"w":12,"h":7,"config":{"displayType":"table","configType":"sql","sqlTemplate":"SELECT\n  region_id AS \"Region ID\",\n  if(region IN ($region), 'kept', 'dropped') AS \"Bare variable\",\n  if($__filter(region, $region), 'kept', 'dropped') AS \"Filter macro\",\n  if($__conditionalAll(region IN ($region), $region), 'kept', 'dropped') AS \"conditionalAll\"\nFROM (SELECT number AS region_id, toString(number) AS region, $__fromTime_ms AS ts FROM numbers(1002))\nWHERE $__timeFilter_ms(ts)\nORDER BY region_id\nLIMIT 12","connection":"Local ClickHouse","name":"Which sample rows each expression keeps"}},{"id":"6b0d3d27e6df08cb05ff4efa","x":12,"y":11,"w":12,"h":7,"config":{"name":"Markdown expansion — also guarded in the editor","source":"","displayType":"markdown","markdown":"**Selected region values:** [$region]\n\nThis tile should show the same loading or error message as the query tiles when its options are unavailable. Its editor preview should do the same.\n\nAt the 1,000-option boundary this list is long; use the number tiles to check the count.","select":[],"where":""}},{"id":"6b0d3d27e6df08cb05ff4efb","x":0,"y":18,"w":24,"h":7,"config":{"name":"Editor checks and recovery","source":"","displayType":"markdown","markdown":"**Editor check**\n1. Choose **Over limit** or **Query error**, leaving **Region = All**.\n2. Open **Edit** on **Filter macro — selected IDs**. With **Apply filters** on, the preview must show the same unavailable message as the tile.\n3. Turn **Apply filters** off → **1,002**. Turn it back on → blocked again.\n4. Close the editor and switch **Scenario** back to **Ready** → **3**.\n\n**Loading:** select **Loading**, then immediately open the editor. If cached, change **Run** first or while Loading is selected. There should be no temporary unfiltered number.\n\n**Selection semantics:** with Ready selected, clear Region → **0 / 1,002 / 1,002**; pick one ID → **1 / 1 / 1**; restore All → **3 / 3 / 1,002**.\n\nAll queries are synthetic and read-only. The time picker does not change the sample IDs. For MCP validation, pass Scenario and Region explicitly; MCP ignores these saved defaults and intentionally fails the whole call for an unavailable All filter.","select":[],"where":""}}],"filters":[{"id":"6b0d3d27e6df08cb05ff4efc","name":"Scenario","variableName":"scenario","maxSelections":1,"type":"STATIC_LIST","options":["Ready","At limit","Over limit","Query error","Loading","Empty"],"isBroadcastEnabled":false,"isVariableEnabled":true},{"id":"6b0d3d27e6df08cb05ff4efd","name":"Region","variableName":"region","type":"SQL_QUERY","connection":"Local ClickHouse","sqlTemplate":"WITH ifNull(arrayElement([$scenario], 1), 'Ready') AS scenario\nSELECT toString(number) AS region\nFROM numbers(multiIf(scenario = 'At limit', 1000, scenario = 'Over limit', 1001, scenario = 'Empty', 0, scenario = 'Loading', 5, 3))\nWHERE throwIf(scenario = 'Query error', 'Intentional SQL All options failure') = 0\n  AND sleepEachRow(if(scenario = 'Loading', 2., 0.)) = 0\n  AND ifNull(arrayElement([$run], 1), '1') != ''\nLIMIT 1001\nSETTINGS max_block_size = 1, max_threads = 1","allowAll":true,"isBroadcastEnabled":false,"isVariableEnabled":true},{"id":"6b0d3d27e6df08cb05ff4efe","name":"Run","variableName":"run","maxSelections":1,"type":"STATIC_LIST","options":["1","2","3"],"isBroadcastEnabled":false,"isVariableEnabled":true}],"containers":[],"savedFilterValues":[{"type":"variable","name":"scenario","values":["Ready"]},{"type":"variable","name":"region","values":[],"all":true},{"type":"variable","name":"run","values":["1"]}]}

References


Note

Medium Risk
Expands filter variables via extra ClickHouse queries on tile load and MCP runs; high-cardinality or slow options queries can block tiles or fail whole MCP batch calls, though behavior is bounded by the 1,000-option cap.

Overview
SQL query dashboard filters can now expose Include "All" option" (allowAll), matching static-list filters. Choosing All means every value the filter’s options query returns, capped at 1,000 (tiles and editor previews error above that or when the options query fails).

The dashboard and tile editor expand SQL All by running the same options query as the filter bar (useExpandedSqlQueryVariables), block dependent tiles/previews until options resolve, and pass expanded variables into queries. The SQL filter form documents how All on sibling SQL filters behaves in dependent queries ($__filter / $__conditionalAll → 1=1, bare $variable → NULL).

API/MCP: allowAll is no longer stripped from SQL query filters on the external API; OpenAPI/MCP schemas and prompts document it. clickstack_query_tile / query_tiles call expandSqlQueryAllVariables to run each filter’s values query when { all: true } is passed.

common-utils centralizes values-query settings and toSqlQueryFilterValues, plus shared 1,000-option limits/messages used by app and MCP.

Reviewed by Cursor Bugbot for commit 2c209d8. 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 30, 2026 10:25
@vercel

vercel Bot commented Nov 30, 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 30, 2026 10:29am UTC
hyperdx-storybook Ready Ready Preview Nov 30, 2026 10:29am UTC

Request Review

@changeset-bot

changeset-bot Bot commented Nov 30, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 2c209d8

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

This PR includes changesets to release 4 packages
Name Type
@hyperdx/api Minor
@hyperdx/app Minor
@hyperdx/common-utils Minor
@hyperdx/otel-collector Minor

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

@karl-power
karl-power added this pull request to stack #3848 November 30, 2026 10:26
@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 108 in total (1.10%).
Run yarn dupes locally to reproduce, or yarn dupes:all for the full picture.

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

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

None could be anchored to changed lines; they are listed below. 1 P3 folded at the bottom.

Findings outside the changed lines

  • 🟡 P2 packages/app/src/hooks/useExpandedSqlQueryVariables.ts:1571 — Tiles expand "All" with the previous query's options while the new options load, because the values query keeps its old data → useSqlQueryFilterValues queries with placeholderData: keepPreviousData (useSqlQueryFilterValues.tsx:202). In react-query v5, isLoading stays false while placeholder data is shown, so this hook takes the old result.values as ready. Example: Region ("All") depends on $country. When the user changes Country from US to EU, the query key changes, tiles run straight away with the US regions and show wrong or empty data, then run again once the EU options arrive. The PR's goal is that tiles wait instead. Fix: also return isPlaceholderData from useSqlQueryFilterValues and treat it as loading here, at least when the rendered SQL changed rather than only the time params. Add a test that doesn't mock useSqlQueryFilterValues; the current hook test mocks it, so it can't catch this.
🔵 1 P3 — no action needed before merge
  • 🔵 P3 packages/api/src/mcp/tools/dashboards/sqlQueryAllValues.ts:352 — MCP options loader rebuilds the source checks and $__sourceTable setup that the app already has → loadOptions repeats the app's resolveValuesCall logic (packages/app/src/hooks/useSqlQueryFilterValues.tsx:64): the "source not found" and "source is not on the filter's connection" checks, plus the source-tables object that getSqlQueryFilterSourceTables (packages/common-utils/src/filters.ts:874) already builds. The PR says these pieces moved to common-utils so the app and MCP run the query the same way, but this part still has two copies. Fix: move the source and connection checks plus the sourceTables derivation into a common-utils helper, and use getSqlQueryFilterSourceTables here. The tables only go into a SQL string, so toPlainMetricTables isn't needed and doesn't have to be exported from query/helpers.ts.

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.

@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 2c209d8. Configure here.

message: tooManyOptionsForAllMessage(filter.name),
});
} else {
optionsByVariableName.set(name, result.values);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Tiles run with stale All options

Medium Severity

Tiles can keep running against a previous options list after the values query key changes. useExpandedSqlQueryVariables only waits while isLoading is true, but useSqlQueryFilterValues sets placeholderData: keepPreviousData, so a refetch reports isLoading false and still returns the old values. Those stale options are expanded as All and tiles query immediately instead of showing the loading placeholder.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 2c209d8. Configure here.

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.

On TanStack Query 5.90, useQueries creates a new observer when a query's key changes, so keepPreviousData never supplies placeholder data here: isLoading is true and tiles wait for the new options. Pinned by a test in #3862 (b3b2426).

@github-actions

Copy link
Copy Markdown
Contributor

Deep Review

✅ No critical issues found. This is a carefully-built, well-tested change. The allowAll + single-select rule is enforced server-side (packages/common-utils/src/dashboardValidation.ts:315, invoked from the external-API refine at packages/api/src/routers/external-api/v2/dashboards.ts:2128), expanded option values flow through the existing escaped substitution machinery rather than raw string concatenation, the 1,000-option cap is checked against the materialized result set, and openapi.json matches the Swagger JSDoc. No P0/P1 ship-blockers surfaced.

The items below are recommendations, not merge blockers — several are explicitly intended trade-offs that are worth a second look.

🟡 P2 -- recommended

  • packages/common-utils/src/filters.ts:1021 -- SQL_QUERY_FILTER_VALUES_SETTINGS uses timeout_overflow_mode: 'break', so a values query exceeding 30s returns partial rows; those partial rows become the expanded IN (...) list for every tile referencing the variable, which then silently renders an incomplete result with no indication that "All" was truncated.
    • Fix: Distinguish a timed-out/partial values response from a complete one and surface a non-blocking "showing partial options" warning on tiles that expanded such a variable.
  • packages/api/src/mcp/tools/dashboards/queryTiles.ts:226 -- expandSqlQueryAllVariables runs for every allowAll filter on the dashboard and returns { error } on the first failed or over-cap filter, so one broken "All" filter fails the entire query_tiles/query_tile call even when none of the requested tiles reference that variable.
    • Fix: Expand only the variables the requested tiles actually reference, or degrade per-variable so an unrelated filter's failure does not block unrelated tiles.
🔵 P3 nitpicks (2)
  • packages/common-utils/src/filters.ts:1032 -- toSqlQueryFilterValues filters with !!value, which drops legitimate empty-string option values in addition to null, so a column that returns '' loses that option from both the dropdown and the "All" expansion.
    • Fix: Filter only on value != null (keeping '') unless dropping empty strings is intended, in which case document it.
  • packages/app/src/hooks/useExpandedSqlQueryVariables.ts:39 -- getUnavailableVariablesMessage joins multiple messages with a single space, so when a tile references two unavailable variables the placeholder reads as two sentences run together.
    • Fix: Join with a newline or render each message as its own line.

Reviewers (11): correctness, testing, maintainability, project-standards, kieran-typescript, performance, reliability, api-contract, adversarial, frontend-races, security.

Testing gaps: No test asserts the partial-results-on-timeout behavior of "All" expansion, nor the query_tiles whole-call failure when an unrelated allowAll filter is over-cap; consider covering both so the documented trade-offs are pinned.

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

Copy link
Copy Markdown
Contributor

E2E Test Results

✅ All tests passed • 481 passed • 1 skipped • 1112s

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

Tests ran across 4 shards in parallel.

View full report →

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

Implementation LGTM, but I am wondering about the rationale behind the dependent filters behavior, asked below.

Also, re The options query stops after 30 seconds and returns partial results, so "All" can silently select an incomplete list. - could we show a warning in this case so it isn't silent?

connectionId ClickHouse connection the query runs on (from clickstack_list_sources), or a CONNECTION filter's "$variableName".
sourceId Optional log, trace, session, or metric source on that connection, or a DATA_SOURCE filter's "$variableName". Needed for $__sourceTable and $__filters; $__filters expands to the dashboard's broadcast filter selections for that source.
sqlTemplate SELECT whose FIRST column becomes the dropdown values, cast to string with nulls and duplicates dropped, in row order (add ORDER BY). May use the time macros and other filters' variables, plus $__sourceTable and $__filters when sourceId is set.
allowAll Set true to add an "All" choice that selects every option the query returns, up to 1,000; tiles show an error above that, so add a LIMIT if the query can return more. Multi-select filters only. Other filters' sqlTemplates see this filter's "All" as no constraint: $__filter and $__conditionalAll expand to 1=1 there and a bare $variableName to NULL, so reference it through the macros.

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.

Why is it that other filters don't see the all option like tiles do?

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.

This also leads to this misleading error message

Screenshot 2026-11-30 at 1 49 38 PM

This branch was successfully deployed

2 active deployments
Preview – hyperdx-oss — 2c209d8f Deployed Nov 30, 2026 by vercel[bot]
Preview – hyperdx-storybook — 2c209d8f Deployed Nov 30, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants