Repository navigation
fix: Validate PromQL tile sources and keep PromQL tiles on MCP saves - #3414
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
[Medium impact] The PR appears safe to merge with no new blocking findings. SummaryAdds PromQL source checks to dashboard writes and keeps hidden PromQL tiles during MCP saves.
Reviews (8) · Last reviewed commit: "fix: Only check PromQL tile sources that..." · Reviewed by Greptile |
Duplicate code analysisNo new duplicate code introduced by this PR. jscpd compared this branch against |
E2E Test Results✅ All tests passed • 458 passed • 1 skipped • 1262s
Tests ran across 4 shards in parallel. |
e533c4c to
e34c81e
Compare
🦋 Changeset detectedLatest commit: 3e9d310 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 |
e34c81e to
0f1a196
Compare
0f1a196 to
6205edf
Compare
🔴 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
|
| // Validate that PROMETHEUS_LABEL filters reference PromQL sources | ||
| // PromQL tiles and PROMETHEUS_LABEL filters query through their source's | ||
| // connection and TimeSeries table, which only a PromQL source carries. | ||
| const promqlTileError = getNonPromqlSourceError( |
There was a problem hiding this comment.
🔵 minor — PromQL source check re-validates every PromQL tile on update, so one tile with a stale source blocks unrelated PUTs
Unlike the heatmap and formula checks just above, which only re-check new or changed tiles on update (filterChangedHeatmapTiles / filterChangedFormulaTiles), this check runs on every PromQL tile in the request. Suppose a PromQL tile's source later changes kind. A GET→PUT round trip that only renames the dashboard then returns 400, which is the case the heatmap gate's doc comment (around line 1461) was written to avoid. When existingTiles is set, limit the check to PromQL tiles that are new, were just switched to PromQL, or changed sourceId.
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
| const stored = await Dashboard.findById(dashboard._id).lean(); | ||
| expect(stored?.tiles.map(t => t.id)).toEqual([ | ||
| 'markdown-tile', | ||
| 'promql-tile', |
There was a problem hiding this comment.
🔵 minor — No test for a request tile that reuses a hidden PromQL tile's id
The new merge in saveDashboard.ts:329-336 has a second branch: a request tile whose id matches a hidden PromQL tile replaces it instead of being added next to it. The PR description promises this, but no test sends a tile with id promql-tile. If the !requestTileIds.has(tile.id) filter breaks, the stored dashboard ends up with two tiles sharing one id. Add a case that saves { id: 'promql-tile', ... } and asserts exactly one promql-tile with the new config.
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
PR Review
2 finding(s): 🔴 0 critical · 🟠 0 major · 🔵 2 minor 2 posted as inline comment(s) on the changed lines. Severity is the reviewer's own estimate and is used for ordering, not filtering. No finding blocks merge automatically; a maintainer decides. |
Deep ReviewScope: PromQL tile source validation in the external API ( The prior P1 ("unrelated dashboard edits fail after a source-kind change") is addressed by ✅ No critical issues found. 🟡 P2 -- recommended
🔵 P3 nitpicks (4)
Reviewers (7): correctness, testing, maintainability, api-contract, kieran-typescript, previous-comments, adversarial. Testing gaps: MCP cap-bypass path (request at 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 |
| // connection and TimeSeries table, which only a PromQL source carries. | ||
| const promqlTileError = getNonPromqlSourceError( | ||
| sources, | ||
| tiles.flatMap(tile => |
There was a problem hiding this comment.
should this only check PromQL tiles that are new or have a new source?
A source's kind can be changed after the dashboard is saved. If that happens, every PUT to the dashboard fails, even one that only renames it.
Would something like this work?
const existingPromqlSources = new Map(
(existingTiles ?? []).flatMap(t =>
isPromqlSavedChartConfig(t.config) ? [[t.id, t.config.source]] : [],
),
);
// then in the filter:
existingPromqlSources.get(tile.id) !== tile.config.sourceIdThere was a problem hiding this comment.
Yes, good idea. I've updated it now
6205edf to
aa74b01
Compare
53ee77e to
0070b61
Compare
Reject external API PromQL tiles whose sourceId is not a PromQL source, sharing the check with PROMETHEUS_LABEL filters. MCP save_dashboard updates now keep the PromQL tiles MCP hides from agents instead of deleting them, until HDX-5302. Add integration tests for PromQL tile create, read and save back, source validation, PromQL heatmaps, and MCP hide and keep.
A source whose kind changes after a PromQL tile is saved no longer blocks unrelated dashboard edits, matching the heatmap and formula checks.
0070b61 to
3e9d310
Compare
Summary
Validate PromQL tile sources in the external API and stop MCP dashboard saves from deleting PromQL tiles. Stacked on #3379.
/api/v2/dashboardsreturns a 400 when a PromQL tile'ssourceIdis not a PromQL source. The check shares a helper with the existingPROMETHEUS_LABELfilter check, whose error message is unchanged.clickstack_save_dashboardupdates replace the whole tile list, and MCP hides PromQL tiles from agents, so an update deleted them. Existing PromQL tiles not in the request are now kept. A request tile that reuses a hidden tile's id replaces it. This goes away when MCP supports PromQL tiles (HDX-5302).How to test
POST /api/v2/dashboardswith a PromQL tile whosesourceIdis a trace source:{ "name": "PromQL API test", "tiles": [ { "name": "Up", "x": 0, "y": 0, "w": 12, "h": 4, "config": { "configType": "promql", "displayType": "line", "sourceId": "<trace source id>", "expressions": [{ "expression": "up" }] } } ] }PromQL tiles require a PromQL source.References