Repository navigation
feat: accept SQL_QUERY dashboard filters in the API, external API, and MCP - #3674
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: 7288dda The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
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 |
Duplicate code analysis1 new clone introduced by this PR.
If one of these duplicates a helper that already exists, import it instead jscpd compared this branch against |
PR Review
2 finding(s): 🔴 0 critical · 🟠 0 major · 🔵 2 minor 1 posted as inline comment(s) on the changed lines. 1 listed below. Findings outside the changed lines1 minor
Severity is the reviewer's own estimate and is used for ordering, not filtering. No finding blocks merge automatically; a maintainer decides. |
Deep ReviewScope: PR #3674 — accept The change is small, well-contained, and backed by new integration tests on all three surfaces (internal route, external API, MCP validation). Connection↔connectionId translation round-trips cleanly, the discriminated-union exhaustiveness check ( ✅ No critical issues found. 🟡 P2 — recommended
🔵 P3 nitpicks (2)
Reviewers (11): correctness, security, adversarial, api-contract, kieran-typescript, testing, maintainability, project-standards, previous-comments, agent-native, learnings-researcher. Testing gaps:
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 |
E2E Test Results✅ All tests passed • 467 passed • 1 skipped • 1156s
Tests ran across 4 shards in parallel. |
|
Review follow-up:
|
🔴 Tier 4 — CriticalTouches authentication, tenancy data models, the public API or shipped database config — or substantially changes the query rendering engine, background tasks, the OTel pipeline, image build, or release CI. Why this tier:
Review process: Deep review from a domain expert. Synchronous walkthrough may be required. Stats
|
e5c0930 to
f049f92
Compare
| * `validateFilterSources`, a connection the stored filter with the same ID | ||
| * already used is skipped. Returns an error message, or null. | ||
| */ | ||
| async function validateFilterConnections( |
There was a problem hiding this comment.
🔵 minor — validateFilterConnections reimplements the team-connection lookup in getMissingConnections
Both functions collect connection IDs, call getConnectionsByTeam, build a set of _id.toString() and return the IDs missing from it. The existing one is getMissingConnections in packages/api/src/routers/external-api/v2/utils/dashboards.ts:1589. Move one helper (for example getMissingTeamConnectionIds(teamId, ids)) into controllers/connection.ts and call it from both places, so the ownership rule has a single source of truth.
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
| sqlTemplate: SqlQueryDashboardFilterSchema.shape.sqlTemplate.describe( | ||
| 'ClickHouse SELECT whose FIRST column becomes the dropdown values (cast to ' + | ||
| 'string; nulls and duplicates dropped; row order kept, so add ORDER BY). ' + | ||
| 'May use the time macros ($__timeFilter(<column>), $__fromTime, $__toTime) ' + | ||
| "and other filters' variables, ideally as $__filter(<expression>, $<variableName>). " + | ||
| 'Cannot use $__sourceTable or $__filters: the filter has no source, so name ' + | ||
| 'tables explicitly. Example: "SELECT DISTINCT env FROM default.envs ORDER BY env".', | ||
| ), |
There was a problem hiding this comment.
Is there a reason not to support an optional sourceId that allows for using $__sourceTable or $__filters? This could also help shortly when we have source-type variables, the source could be dynamic based on the selected source variable value. It would also make it seem more consistent with raw SQL tiles.
There was a problem hiding this comment.
Is there a reason not to support an optional sourceId that allows for using $__sourceTable or $__filters?
No, there's no strong reason except that I thought it would keep it a little simpler for the first iteration. I'd be happy to add that in a PR at the end of the stack.
…d MCP Validate a SQL query filter's connection on save, and let the external API and MCP read and write the filter. - Reject dashboard saves whose SQL_QUERY filter names a connection outside the team, skipping a connection the stored filter already used - Map the filter's connection to connectionId in the external API and MCP, and stop hiding the type there - Check filter connections in the external API's connection validation - Warn in MCP about source-only macros, unclosed macros, and unknown variables in the filter's SQL - Document the filter in the MCP tool descriptions, prompts, and OpenAPI spec Refs HDX-5524
f049f92 to
7288dda
Compare
Summary
Lets the API, external API v2, and MCP save and return
SQL_QUERYdashboard filters, and checks their connection on save. This is the second of four PRs; the dropdown still has no values and the UI can't create the filter yet.SQL_QUERYfilter whose connection doesn't belong to the team. A connection the stored filter with the same ID already used is skipped, matching how filter sources are checked.connectionIdfield, translated to and from the internalconnection. The PR 1 stopgap that hid the type is removed;ADHOCstays hidden.sourceId.$__sourceTableor$__filters(the filter has no source), leaves a macro unclosed, or references an unknown variable.$__filter(<column>, $<variable>)for reading another filter's selection.openapi.jsonis regenerated.How to reproduce
Starting point:
yarn dev, with the MCP server connected.On the base branch (#3672):
clickstack_save_dashboardwith a filter{ "type": "SQL_QUERY", "name": "Service", "connectionId": "<connection ID>", "sqlTemplate": "SELECT DISTINCT ServiceName FROM default.otel_logs WHERE $__timeFilter(Timestamp) ORDER BY 1", "variableName": "svc" }.On this branch:
connectionId.$__filter(ServiceName, $svc)and runclickstack_query_tilewith and withoutvariableValues: [{ "name": "svc", "values": ["<service>"] }]. The tile narrows to that service only when a value is selected.connectionId: "000000000000000000000000". The call fails with "Could not find the following connection IDs".sqlTemplate: "SELECT 1 FROM $__sourceTable". The dashboard saves and returns a warning that the filter has no source.How to test on Vercel preview
N/A — non-UI change
References