← Back to Pull requests

feat: expand SQL query filter "All" in dependent filters, disable loops #3896

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Dec 03, 2026 12:03 UTC
Author

Summary

"All" on a SQL query filter now gives other filters' options queries every option, the same as tiles get, matching Grafana.

  • Dropdowns whose query references a filter set to "All" (SQL query, SQL expression, PromQL label and ad hoc filters) get its full option list. Before, they treated it as no constraint (1=1), so a dependent dropdown listed options for values outside that list.

  • Those dropdowns wait for the options to load, and show the error instead of querying when the options fail to load or exceed 1,000. References through $__conditionalAll don't wait, since it is 1=1 on "All".

  • An "All" filter whose options query references another "All" filter runs after it, and runs again when that filter's options change.

  • Filters whose options queries reference each other in a loop that includes a filter offering "All" are disabled, as Grafana does: the filters and tiles that use them show "Cloud and Tier reference each other in their options queries…" instead of running. Filters whose queries depend on the loop are disabled too. Loops between filters without "All" keep working as before.

  • Every filter editor checks for these loops before saving, including SQL expression and PromQL label filters. The SQL query filter preview waits for the "All" options its query uses, and its help text describes the new behaviour.

  • MCP clickstack_save_dashboard warns about such loops, and query_tile / query_tiles fail when one of the looping filters is passed "All". They load "All" options in dependency order, running independent queries at the same time instead of one after another.

  • common-utils gains getAllOptionsLoopErrors, getAllSelectionDependencies and getFilterValuesTemplate, shared by the app and MCP.
  • Behaviour notes

  • Tiles that use a variable only through $__conditionalAll still wait for its options, as in #3861.

  • The 30 s cut-off warning shows on the filter whose query was cut off and on tiles that use it, not on filters that depend on it.
  • Screenshots or video

    <img width="711" height="301" alt="Screenshot 2026-12-03 at 12 35 43" src="https://github.com/user-attachments/assets/0b9df3d6-d80d-4f4f-8645-25fc378dbf39" />
    <img width="775" height="626" alt="Screenshot 2026-12-03 at 12 06 00" src="https://github.com/user-attachments/assets/01330ce4-a741-49a6-bd0c-d43c56bf9b38" />

    How to reproduce

    Import the dashboard below. Pick "All" in Region, Zone and Cloud, and select gold in Tier. Tier uses "SQL expression values" on the Logs source and does not offer "All". Zone's query keeps the zones whose region is in $region; Region returns eu and us, but there is also an ap-1 zone.

    <details>
    <summary>Test dashboard</summary>

    {"version":"0.1.0","name":"TEST: \"All\" in dependent SQL query filters","tags":[],"tiles":[{"id":"nuagx63lpdej0vz58gr5fn","x":0,"y":0,"w":5,"h":10,"config":{"name":"Zones","source":"","displayType":"markdown","markdown":"Zones: $zone","select":[],"where":""}},{"id":"o4h3o1rqqs9vy9qlhx7sl","x":5,"y":0,"w":5,"h":10,"config":{"name":"Cloud & Tier","source":"","displayType":"markdown","markdown":"Cloud: $cloud, Tier: $tier","select":[],"where":""}}],"filters":[{"id":"4f1ebe7d-31d5-4ebc-a66f-5b3dfb802040","name":"Region","variableName":"region","type":"SQL_QUERY","sqlTemplate":"SELECT arrayJoin(['eu', 'us']) AS region","allowAll":true,"isBroadcastEnabled":false,"isVariableEnabled":true,"connection":"Local ClickHouse"},{"id":"e5c097d3-1a6b-4e18-8399-9fd509772a0f","name":"Zone","variableName":"zone","type":"SQL_QUERY","sqlTemplate":"SELECT zone\n   FROM (SELECT arrayJoin(['eu-1', 'eu-2', 'us-1', 'ap-1']) AS zone, left(zone, 2) AS region)\n   WHERE $__filter(region, $region)","allowAll":true,"isBroadcastEnabled":false,"isVariableEnabled":true,"connection":"Local ClickHouse"},{"id":"a0781518-a08b-481d-87e0-86cc9e3a6dfc","name":"Cloud","variableName":"cloud","type":"SQL_QUERY","sqlTemplate":"SELECT cloud\n   FROM (SELECT arrayJoin([('aws', 'gold'), ('gcp', 'silver')]) AS pair, pair.1 AS cloud, pair.2 AS tier)\n   WHERE $__filter(tier, $tier)","allowAll":true,"isBroadcastEnabled":false,"isVariableEnabled":true,"connection":"Local ClickHouse"},{"id":"0046e15d-d20c-41eb-afc6-e6e00acd4b0c","name":"Tier","variableName":"tier","type":"QUERY_EXPRESSION","expression":"arrayJoin(['gold', 'silver'])","whereLanguage":"sql","isBroadcastEnabled":false,"isVariableEnabled":true,"source":"Logs"}],"containers":[],"savedFilterValues":[]}
    

    </details>

    On #3862 (base):

    1. Open the Zone dropdown. It lists eu-1, eu-2, us-1, ap-1, and the Zones tile shows all four.

    On this branch:

    1. Open the Zone dropdown. It lists only eu-1, eu-2, us-1, and the Zones tile shows Zones: eu-1, eu-2, us-1.
    2. Set Region to just us. Zone lists only us-1. Set Region back to "All".
    3. Click the filter icon next to Refresh ("Edit filters and variables"), edit Region's query to SELECT arrayJoin(['eu', 'us']) AS region WHERE sleep(3) = 0 AND $__fromTime_ms > 0 and save. Close the modal and click Refresh: for about 3 s the Zones tile shows "Loading the options for Zone…" and the Zone dropdown loads, then both fill in. ap-1 never appears.
    4. Edit Region's query to SELECT throwIf(1, 'Region query failed') AS region. The Zone label and the Zones tile show "Couldn't load the options for Region: Region query failed…". Edit Zone and click "Preview values": it shows the same error instead of running. Restore Region's query.
    5. Edit Tier ("SQL expression values"). Set "Dropdown values filter" to SQL and enter $__filter(ServiceName, $cloud), then click "Save filter". The editor refuses: "Cloud and Tier reference each other in their options queries, which "All" doesn't support. Remove one of the references." Clear the dropdown-values condition and save again; the save succeeds.

    References

  • Linear Issue: Closes HDX-6191

  • Related PRs: #3830, #3847, #3861, #3862
  • <!-- CURSOR_SUMMARY -->
    ---

    [!NOTE]

    Medium Risk

    Touches dashboard variable expansion, filter query orchestration, and MCP tile runs; incorrect dependency or loop handling could block filters or run queries with stale options, but behaviour is heavily tested.

    > Overview

    SQL query filters set to "All" now expand to every loaded option in other filters' dropdown queries (not only in tiles), and those queries wait until upstream "All" options finish loading—or surface the same error state instead of running. $__conditionalAll still skips that wait by treating "All" as 1=1.

    > Dependency-aware loading runs options queries in order (parallel when independent), refreshes dependents when a parent's options change, and exposes unavailableByFilterId / unavailableVariables across the filter bar, ad hoc filters, tile editor, and SQL filter preview.

    > Circular "All" loops (options queries that reference each other across SQL query, query expression, and PromQL label filters) are detected via new getAllOptionsLoopErrors, getAllSelectionDependencies, and getFilterValuesTemplate in common-utils. Looped filters are disabled with a clear message; the filter editor blocks save; MCP warns on save and fails tile runs that pass "All" on a loop member. Loops without "All" are unchanged.

    > Docs/changesets and broad unit/e2e coverage accompany the behaviour shift.

    > <sup>Reviewed by Cursor Bugbot for commit 98f12fc21926dc07c8e1b5037cecb8f347985bf8. Bugbot is set up for automated code reviews on this repo. Configure here.</sup>

    <!-- /CURSOR_SUMMARY -->

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: pulpdrew Review duration: 816m
    All Vouch review confidence checks passed
    Residual risk 0.28 = Change Risk (0.52) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #3896"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 27.7% · Safe to merge
    27.7%