Repository navigation
fix(common-utils): query every expression of a PromQL table tile - #3886
Tyagiquamar wants to merge 1 commit into
Conversation
Table tiles kept only the first PromQL expression and silently dropped the rest. They now query every expression and join the results into one value column per expression (named after the expression's alias), the way a builder table gives one column per select item. Instant queries join on the label set, range queries on the label set and timestamp. The chart editor also offers multi-expression editing for table tiles, matching what the query path already supports for time series charts.
|
@Tyagiquamar is attempting to deploy a commit to the HyperDX Team on Vercel. A member of the Team first needs to authorize it. |
🦋 Changeset detectedLatest commit: 8341f09 The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 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 |
| const key = isBucketed ? `${ts} ${labelKey}` : labelKey; | ||
| let row = rowsByKey.get(key); | ||
| if (row == null) { | ||
| if (rowsByKey.size >= maxRows) { |
There was a problem hiding this comment.
🟡 P2 — Row cap stops the whole join, so later expressions lose values on rows already shown
Once rowsByKey.size >= maxRows, the first new key from expression 2 or later sets capped and breaks out of every loop. All of that expression's remaining samples, and every later expression's samples, are then skipped, even ones whose key already has a row. Example: expression 1 fills 10,000 rows and expression 2's first series is one expression 1 lacked. Every value expression 2 has for the existing rows then shows as null, which looks like missing data. Fix: when the cap is hit, skip only the new key (continue) and keep filling cells on rows that already exist. Report truncation separately if needed.
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
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
🔵 1 P3 — no action needed before merge
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. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
Reviewed by Cursor Bugbot for commit 8341f09. Configure here.
| } | ||
| row.push([valueColumn, value]); | ||
| data.push(Object.fromEntries(row)); | ||
| if (capped) break; |
There was a problem hiding this comment.
Row cap drops later expression values
High Severity
Once rowsByKey hits maxRows, capped breaks out of every loop, so later expressions never write into already-created rows. Shared series then keep null in subsequent value columns even though those samples were already fetched. Range table tiles hit this easily: default range evaluation with a modest series count fills the 10,000-row cap from the first expression alone, leaving every other value column empty.
Reviewed by Cursor Bugbot for commit 8341f09. Configure here.
Deep ReviewPromQL table tiles now query every expression and join results into one value column per expression (aliased, falling back to 🔴 P0/P1 — must fix✅ No critical issues found. 🟡 P2 — recommended
🔵 P3 nitpicks (10)
Reviewers (9): correctness, adversarial, testing, maintainability, project-standards, agent-native, kieran-typescript, api-contract, performance. 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 |


Summary
Closes #3835 (table case).
A PromQL tile can hold several expressions, but
getQueriedPromqlSerieskept only the first one for every display type except line and stacked charts. On a table tile the rest stayed saved and never ran, with no error or warning, so a reader saw oneValuecolumn and could not tell data was missing.Table tiles now query every expression and return one value column per expression, joined on the label set (and on the timestamp for range queries), the way a builder table gives one column per select item. Value columns are named after the expression's
alias, falling back toValue_1,Value_2, and so on. Series that share a join key get one row; the expressions they miss staynull. The chart editor now offers multi-expression editing for table tiles too, matching what the query path already did for time series charts.Number, pie and bar tiles are unchanged: they still query only the first expression, as before.
Screenshots or video
I could not capture before/after screenshots myself (no browser tool in this environment). The visible change is small: the PromQL expression editor on a table tile now shows the "add expression" affordance and no longer marks extra expressions as ignored. Happy to add captures if useful.
How to reproduce
Starting point: a PromQL source (Prometheus endpoint or ClickHouse TimeSeries table), e.g. from
yarn devwith a seeded PromQL connection, or the Vercel preview's local mode if a PromQL source is available.On
main:clickstack_save_dashboardor the external API) withconfigType: "promql",displayType: "table", and two expressions such asmax by (k8s_hpa_name) (k8s_hpa_desired_replicas)andmax by (k8s_hpa_name) (k8s_hpa_current_replicas).Valuecolumn. The second expression never runs.On this branch:
clickstack_query_tilereturns the same joined rows.How to test on Vercel preview
Preview routes: /dashboards
Steps:
clickstack_save_dashboardif needed).Valuecolumn.References
Test plan
packages/common-utils:yarn jest --ci src/core/__tests__/promqlChart.test.ts src/core/__tests__/promql.test.ts— 99 tests pass, including new cases for the joined table layout (instant and range queries, alias column naming, label union,__proto__-safe cells, row cap).packages/api:yarn jest --ci src/mcp/tools/query/__tests__/promqlTile.test.ts— 16 tests pass, including new cases asserting a table tile queries every expression and joins them into one value column each.yarn tsc --noEmitinpackages/common-utilsandpackages/api— clean.oxfmt --checkon all touched files — clean;oxlinton touched files — 0 warnings.make dev-int), and E2E. The change is covered by the unit tests above; CI should run the rest.Note
Medium Risk
Changes PromQL table query and result-shaping logic used by the app and MCP; behavior change for existing multi-expression table tiles, but covered by new unit tests and scoped to table display type.
Overview
PromQL table tiles previously behaved like number/pie/bar charts: only the first expression was sent to Prometheus, while extra expressions stayed in config with no warning and a single
Valuecolumn.This PR treats table like line/stacked charts for querying:
getQueriedPromqlSeriesreturns all non-blank expressions forDisplayType.Table, andtoPromqlTableRowsbuilds one value column per expression, joined on the label set (and timestamp for range queries). Columns use expression aliases orValue_1,Value_2, …; missing join keys arenull. The chart editor (PromqlChartEditor) now allows add expression for table tiles. MCP prompts and dashboard schemas document that table tiles plot every expression.Number, pie, and bar tiles are unchanged (first expression only).
Reviewed by Cursor Bugbot for commit 8341f09. Bugbot is set up for automated code reviews on this repo. Configure here.