Skip to content

fix(common-utils): query every expression of a PromQL table tile - #3886

Open
Tyagiquamar wants to merge 1 commit into
ClickHouse:mainfrom
Tyagiquamar:agent/promql-table-multi-expression
Open

Tyagiquamar wants to merge 1 commit into
ClickHouse:mainfrom
Tyagiquamar:agent/promql-table-multi-expression

Conversation

@Tyagiquamar

@Tyagiquamar Tyagiquamar commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Closes #3835 (table case).

A PromQL tile can hold several expressions, but getQueriedPromqlSeries kept 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 one Value column 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 to Value_1, Value_2, and so on. Series that share a join key get one row; the expressions they miss stay null. 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.

Before After

How to reproduce

Starting point: a PromQL source (Prometheus endpoint or ClickHouse TimeSeries table), e.g. from yarn dev with a seeded PromQL connection, or the Vercel preview's local mode if a PromQL source is available.

On main:

  1. Save a dashboard tile (via MCP clickstack_save_dashboard or the external API) with configType: "promql", displayType: "table", and two expressions such as max by (k8s_hpa_name) (k8s_hpa_desired_replicas) and max by (k8s_hpa_name) (k8s_hpa_current_replicas).
  2. Open the tile. Only the first expression's values appear, under a single Value column. The second expression never runs.

On this branch:

  1. Same tile. The table now shows the label columns plus one value column per expression (named after each expression's alias), joined on the label set, and clickstack_query_tile returns the same joined rows.

How to test on Vercel preview

Preview routes: /dashboards

Steps:

  1. Open a dashboard with a PromQL table tile that has two expressions (create one via MCP clickstack_save_dashboard if needed).
  2. Verify the tile renders one value column per expression instead of a single Value column.

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 --noEmit in packages/common-utils and packages/api — clean.
  • oxfmt --check on all touched files — clean; oxlint on touched files — 0 warnings.
  • Not run locally: full unit suites, integration tests (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 Value column.

This PR treats table like line/stacked charts for querying: getQueriedPromqlSeries returns all non-blank expressions for DisplayType.Table, and toPromqlTableRows builds one value column per expression, joined on the label set (and timestamp for range queries). Columns use expression aliases or Value_1, Value_2, …; missing join keys are null. 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.

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
Tyagiquamar requested a review from a team as a code owner December 2, 2026 06:52
@vercel

vercel Bot commented Dec 2, 2026

Copy link
Copy Markdown

@Tyagiquamar is attempting to deploy a commit to the HyperDX Team on Vercel.

A member of the Team first needs to authorize it.

@changeset-bot

changeset-bot Bot commented Dec 2, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8341f09

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

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

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) {

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.

🟡 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

@github-actions

github-actions Bot commented Dec 2, 2026

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.

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

  • 🟡 P2 packages/common-utils/src/core/__tests__/promqlChart.test.ts:366 — Row cap is only tested with one expression → The 'caps the rows it returns' test passes one expression, so it cannot catch the multi-expression cap bug above. The PR description says the row cap is covered, but no test reaches it with joined rows. Add a case with maxRows set low and two expressions: the second should include a key the first lacks, followed by keys that are already in the table. Assert that the shared rows keep the second expression's values.
🔵 1 P3 — no action needed before merge
  • 🔵 P3 packages/app/src/components/ChartEditor/PromqlChartEditor.tsx:94 — Rule for which display types query several expressions is now written in two places → isTimeSeriesDisplayType(displayType) || displayType === DisplayType.Table here repeats the condition in getQueriedPromqlSeries (packages/common-utils/src/core/promql.ts:54-56). If the two drift, the editor and the query path will disagree about which expressions are ignored, the same silent-drop bug this PR fixes. Export a displayTypeSupportsMultiExpression(config) helper from core/promql.ts, alongside displayTypeSupportsInstantQuery and displayTypeSupportsReducer, and use it in both places.

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

Reviewed by Cursor Bugbot for commit 8341f09. Configure here.

}
row.push([valueColumn, value]);
data.push(Object.fromEntries(row));
if (capped) break;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 8341f09. Configure here.

@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Deep Review

PromQL table tiles now query every expression and join results into one value column per expression (aliased, falling back to Value_N), joined on the label set plus timestamp for range queries. The core join in toPromqlTableRows is sound: label keys are unambiguous JSON arrays, value-column names are deduped via uniqueColumnName, every row carries the same key set in the same order, and setCell/Object.defineProperty plus Map(Object.entries()) correctly defuse the __proto__ hazard. Single-expression tables keep the legacy Value column, so that path stays backward compatible. The remaining concerns are a user-facing display wart, a silent truncation trap at the row cap, and discoverability/doc gaps on the new agent path.

🔴 P0/P1 — must fix

✅ No critical issues found.

🟡 P2 — recommended

  • packages/app/src/HDXMultiSeriesTableChart.tsx:196 — A joined null value cell fails the typeof === 'string' | 'number' check and is rendered as the literal string "null" via JSON.stringify, never reaching the numberFormat/formatNumber branch, so most multi-expression tables (any label mismatch between expressions produces nulls) display "null" text instead of a blank cell.
    • Fix: Render null/undefined cells as an empty string or em dash before the JSON.stringify fallback.
    • correctness, adversarial
  • packages/common-utils/src/core/promqlChart.ts:351 — When the joined-row cap (MAX_TABLE_ROWS) is reached, the loop breaks out of all remaining expressions, so a later expression's value column stays null even for rows whose join key already exists and had a value; the truncated result is still returned as complete with no truncation signal.
    • Fix: On reaching the cap, keep filling cells of already-admitted rows (only skip new keys) and surface a truncation flag through PromqlChartRows so callers can signal incompleteness.
    • adversarial, testing, correctness, maintainability, kieran-typescript, performance
  • packages/api/src/mcp/tools/dashboards/schemas.ts:1419 — The alias field is described only as a Legend label for this series, but it now also names each table value column; a table has no legend, so an agent has no cue to set alias and gets Value_1/Value_2 headers for multi-expression tables.
    • Fix: Extend the alias description (and the "one value column per expression" schema note) to state that on a table tile the alias becomes the value-column header, defaulting to Value_1, Value_2.
    • agent-native
🔵 P3 nitpicks (10)
  • packages/common-utils/src/core/promqlChart.ts:344 — Expressions with different by groupings join on the union of all labels (missing labels coerced to ''), so series at different label granularity never line up and produce disjoint, mostly-null rows rather than a combined row.
    • Fix: Document the full-label-union join semantics, or join on the shared label intersection when groupings differ.
    • adversarial
  • packages/common-utils/src/core/promqlChart.ts:348 — A table tile mixing an instant and a range expression makes the whole table bucketed, so the instant sample joins at most one timestamped row and otherwise lands on its own row with the other columns null.
    • Fix: Coerce all table expressions to one query mode, or document the mixed-mode join behavior.
    • adversarial, correctness, kieran-typescript
  • packages/common-utils/src/core/promqlChart.ts:379 — Value columns are declared type: 'Float64' in meta while their cells can now be null; for a ClickHouse-shaped response a nullable column would be Nullable(Float64), so any consumer deriving nullability from meta.type gets an inaccurate contract.
    • Fix: Signal nullability in meta (e.g. Nullable(Float64)) for joined value columns.
    • api-contract, kieran-typescript
  • packages/common-utils/src/core/promqlChart.ts:305 — Two expressions with the same alias are silently deduped to alias and alias_1 with no editor or schema warning.
    • Fix: Warn when two expressions resolve to the same column name.
    • adversarial, testing
  • packages/common-utils/src/core/promqlChart.ts:306 — A single-expression table always labels its column Value, ignoring a user-set alias, which may surprise a user who aliased the expression.
    • Fix: Use the alias for the lone column when one is set, or document that single-expression tables keep Value.
    • adversarial
  • packages/api/src/mcp/prompts/dashboards/promqlContent.ts:49 — The create_dashboard PromQL section has no multi-expression table example showing alias-as-column behavior.
    • Fix: Add a short two-expression table example with aliases.
    • agent-native
  • packages/api/src/mcp/prompts/dashboards/promqlContent.ts:49 — The prompt moved the queryType "instant" note to number, pie and bar only, so it no longer tells an agent that table tiles can also run instant queries (the schema and displayTypeSupportsInstantQuery still permit it).
    • Fix: Restore a note that table tiles can set queryType "instant".
    • project-standards
  • .changeset/promql-table-multi-expression.md:2 — The change adds user-facing capability (multi-expression table editing, new output columns) and widens the exported PromqlChartRows.data type to include null, yet ships as a patch; repo precedent bumps comparable additive changes as minor.
    • Fix: Reconsider a minor bump for @hyperdx/app and @hyperdx/common-utils, or note the type widening in the changeset.
    • project-standards, api-contract
  • packages/common-utils/src/core/promqlChart.ts:339 — The join/cap uses a triple-nested loop with a capped flag propagated through three separate if (capped) break; statements, concentrating the hardest-to-follow control flow in one function.
    • Fix: Use a labeled outer loop or extract the per-sample fill into a helper that returns whether the cap was hit.
    • maintainability
  • packages/common-utils/src/core/promqlChart.ts:122 — The comment "A vector is one sample per series, so capping series caps a table's rows exactly" no longer holds for multi-expression tables, where each expression is capped independently and the join is re-capped in toPromqlTableRows.
    • Fix: Update the comment to reflect per-expression limiting plus the join-level re-cap.
    • maintainability

Reviewers (9): correctness, adversarial, testing, maintainability, project-standards, agent-native, kieran-typescript, api-contract, performance.

Testing gaps:

  • No test exercises the row cap under a multi-expression join (which rows/columns survive, null backfill, joined-row counting).
  • No test drives a null join cell through the MCP toPromqlTileResult consumer or the app table renderer (the "null"-string render path).
  • No test for two expressions sharing an alias, or an alias colliding with a label-column name.
  • No test for a table tile mixing instant and range expressions.

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

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PromQL table, number, pie and bar tiles silently ignore every expression after the first

1 participant