Skip to content

fix: pass return_columns to timeSeriesSelector on ClickHouse 26.11 - #3824

Open
bcanvural wants to merge 2 commits into
ClickHouse:mainfrom
bcanvural:fix/timeseries-selector-26-11
Open

bcanvural wants to merge 2 commits into
ClickHouse:mainfrom
bcanvural:fix/timeseries-selector-26-11

Conversation

@bcanvural

@bcanvural bcanvural commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

ClickHouse 26.11 added a required return_columns argument to timeSeriesSelector(). Our 5-argument call ('db', 'table', selector, min, max) is now read as (table, selector, min, max, return_columns): 'db' is taken as the table, and every PromQL label lookup with match[] fails with Table default.<db> does not exist. On a PromQL source with the table-function backend, that breaks every dashboard variable dropdown. 26.10 and earlier reject a sixth argument, so the call form is now picked by server version.

Call 26.10.3.7 26.11.1.2942
('db', 'table', q, min, max) works UNKNOWN_TABLE
('db', 'table', q, min, max, 'samples') requires 4..5 arguments works

'samples' is passed because only id is read. It matches the bucketed layout of version 11 tables, where 'timestamp_and_value' would add an arrayJoin over every bucket. On older layouts the unused samples column is pruned (checked with EXPLAIN header = 1 on 26.11).

Until this ships, a PromQL source can use the clickhouse-http backend if the server has the prometheus_api_v1 handler.

Testing

timeseriesEngine.int.test.ts (47 tests) passes on 26.10.3.7 (the CI version) and on 26.11.1.2942. On 26.11 without this change, 19 of the match[] tests fail.

Closes #3825

ClickHouse 26.11 added a required return_columns argument to
timeSeriesSelector(). The 5-argument ('db', 'table', selector, min, max)
call is now read as (table, selector, min, max, return_columns), so 'db'
is taken as the table and every PromQL label lookup with match[] fails
with UNKNOWN_TABLE. 26.10 and earlier reject a sixth argument, so the call
form is picked by server version.

'samples' is passed because only `id` is read: it matches the bucketed
layout of version 11 tables, while 'timestamp_and_value' would unfold
every bucket with arrayJoin. On older layouts the unused column is pruned.
@bcanvural
bcanvural requested a review from a team as a code owner November 25, 2026 09:59
@vercel

vercel Bot commented Nov 25, 2026

Copy link
Copy Markdown

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

A member of the Team first needs to authorize it.

@github-actions

github-actions Bot commented Nov 25, 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.

1 finding(s): 🔴 0 P0/P1 · 🟡 1 P2 · 🔵 0 P3

1 posted as inline comment(s) on the changed lines.


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.

@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Deep Review

✅ No critical issues found. This is a small, well-scoped version-gate fix; the query-construction change keeps user-controlled selectors as bound parameters and appends only a static literal, so no injection or correctness regression is introduced. The one substantive gap is test coverage of the new version→gate wiring.

🟡 P2 — recommended

  • packages/api/src/controllers/timeseriesEngine.ts:195 — the new wiring that fetches the server version and threads timeSeriesSelectorTakesReturnColumns(version) into getSeriesSelectorCondition is untested; both seams are tested in isolation but a regression that fetches the wrong version, drops the await, or mis-passes the flag would pass every existing test.
    • Fix: add a getSeriesFilterConditions test that stubs metadata.getServerVersion to return a ≥26.11 version, a ≤26.10 version, and undefined, asserting the emitted selector SQL includes or omits the return_columns argument accordingly.
    • testing, correctness, kieran-typescript
🔵 P3 nitpicks (1)
  • packages/api/src/controllers/__tests__/timeseriesEngine.test.ts:22 — expect(selectorSql(true)).toContain("), 'samples'\n") couples the assertion to the SQL template's exact indentation and trailing newline, so a behavior-preserving reformat of the query block would break the test.
    • Fix: assert against whitespace-normalized SQL that the rendered call ends with the , 'samples' argument rather than matching the literal layout.

Reviewers (9): correctness, testing, maintainability, project-standards, kieran-typescript, performance, security, agent-native, learnings-researcher.

Testing gaps:

  • No integration test confirms a real 26.11 server accepts the generated 6-argument timeSeriesSelector(..., 'samples') call (and a ≤26.10 server the 5-argument form); unit tests only assert the SQL string contains/omits 'samples'.
  • The undefined-version path at the call site is untested end-to-end: if getServerVersion fails on a genuine 26.11+ server it returns undefined (cached per request), falling back to the 5-argument call and reintroducing the UNKNOWN_TABLE failure — a degraded path the diff improves but does not cover.

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

@changeset-bot

changeset-bot Bot commented Nov 25, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: af1831e

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

This PR includes changesets to release 4 packages
Name Type
@hyperdx/api Patch
@hyperdx/common-utils Patch
@hyperdx/app 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

@bcanvural

Copy link
Copy Markdown
Contributor Author

Added both tests in af1831e: the version check gets a boundary block like its neighbours, and the call form is checked on the generated SQL for both branches, so CI covers the 26.11 path without a 26.11 server. I left the P3 log out: an unknown version falls back the same way in every other version check.

'match[] requires a TimeSeries table that stores time ranges (store_time_ranges = 1, or store_min_time_and_max_time = 1 before version 8), or the prometheus_api_v1 HTTP handler on ClickHouse 26.9+',
);
}
const version = await metadata.getServerVersion({ connectionId });

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 — SELECT version() now runs on every match[] label lookup, after the time-bounds probes have finished

metadata is built on a throwaway new MetadataCache() (line 176), so getServerVersion sends a fresh SELECT version() on every call. It waits until timeSeriesTimeBounds has finished its one or two probe queries, which adds a third sequential round trip to every dashboard-variable lookup that uses match[]. When selectors != null, start metadata.getServerVersion({ connectionId }) alongside timeSeriesTimeBounds with Promise.all (it does not depend on the bounds), or pass in a version the caller already holds.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Leaving this as is: it only runs when match[] is given, and SELECT version() is a sub-millisecond query next to the tags scan that follows. Running it in parallel is a fine follow-up if lookups ever show it.

@bcanvural

Copy link
Copy Markdown
Contributor Author

Deep review P2 on the wiring: both halves are tested, and the one line joining them is type-checked (a missing await would pass a Promise where a version is expected). The 26.11 path also passes the full timeseriesEngine.int.test.ts suite against a 26.11.1.2942 server locally.

Two review rounds are done with no P0/P1 left, so I'll stop on the automated findings here. @karl-power, could you take a look when you have time? This fixes the match[] label lookups from #3603 on ClickHouse 26.11.

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 label lookups with match[] fail on ClickHouse 26.11 (timeSeriesSelector needs return_columns)

1 participant