Skip to content

Store Prometheus exemplars in TimeSeries tables and serve /api/v1/query_exemplars - #130398

Open
valerypetrov wants to merge 15 commits into
ClickHouse:masterfrom
valerypetrov:promql-exemplars
Open

valerypetrov wants to merge 15 commits into
ClickHouse:masterfrom
valerypetrov:promql-exemplars

Conversation

@valerypetrov

@valerypetrov valerypetrov commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Changelog category (leave one):

  • New Feature

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

TimeSeries tables can store Prometheus exemplars (setting store_exemplars), and the Prometheus HTTP API serves them at /api/v1/query_exemplars.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

A TimeSeries table created with store_exemplars = 1 (table version 12) gets an optional exemplars inner table and an outer column exemplars, and remote write stores the exemplars that Prometheus 3.5 accepts instead of dropping them. /api/v1/query_exemplars answers like Prometheus: selectors are taken from query, exemplars are filtered by start/end, and the JSON shape and order are the same. Tables without the setting are unchanged.

Prometheus 3.5.0 (--enable-feature=exemplar-storage) was fed the same remote-write requests with 17 exemplars: all 9 query_exemplars answers of the new test 05617_timeseries_exemplars are byte-identical to its answers. Prometheus kept 10 exemplars, dropped 3 as out of order, ignored 2 duplicates and rejected 2; ClickHouse counts the same 3 out-of-order exemplars. Unlike Prometheus, ClickHouse keeps every exemplar (no ring buffer) and does not drop an exemplar that is older than one stored by an earlier request.

#122051 also introduces table version 12; whichever of the two lands second moves to 13.

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/130398]

valerypetrov and others added 4 commits November 9, 2026 12:01
…ry_exemplars

Remote write used to decode the exemplars of every series and drop them, and
there was no way to query them, so trace links from Grafana panels never
worked against ClickHouse.

A TimeSeries table of version 12 can now have an optional "exemplars" inner
table (`store_exemplars = 1` or an `EXEMPLARS` clause; off by default, so
existing tables and new tables without the setting are unchanged). It stores
one row per exemplar (`id`, `timestamp`, `value`, `labels`), and the table gets
an outer column `exemplars` that INSERT writes and SELECT reads.

Remote write keeps the exemplars Prometheus 3.5 keeps: empty labels are
removed, exemplars more than 10 minutes ahead or with label sets longer than
128 characters are dropped, and within a request a duplicate of the newest
exemplar of a series is ignored while an older one is dropped and counted in
the new PrometheusRemoteWriteOutOfOrderExemplars event. Ties on timestamp and
value are ordered by the labels hash of the default Prometheus build.

/api/v1/query_exemplars extracts the selectors of `query` like
parser.ExtractSelectors, filters exemplars by [start, end], and writes the
same JSON as Prometheus: series sorted by labels, exemplars in acceptance
order, 204 for an expression without selectors.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The annotations tests add the same /prometheus/api/v1 handler under the name
prometheus_api_v1.xml. Using that file and its install.sh line here keeps the two
changes identical, so they merge cleanly in either order. The test moves to
05617 because 05616 is used by the annotations test.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
PullingAsyncPipelineExecutor::pull can return a block without columns while
the query is still running. queryExemplars looked up its columns by name and
failed with "Not found column tags in block", so most requests returned 400
depending on timing. The other endpoints already skip such blocks.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The test prints the version of a table created AS a table of an older
version, which is the latest version, now 12.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@mintlify

mintlify Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit 4b00512.

Approve preview

@clickhouse-gh clickhouse-gh Bot added comp-promql PromQL / time-series subsystem: TimeSeries storage engine, PromQL parser, PromQL-to-SQL converter... external Author is not a member of the ClickHouse organization labels Nov 10, 2026
Resolve the conflict in the Prometheus interface docs: keep the federation endpoint from master and
the query_exemplars endpoint from this branch in the list of implemented endpoints.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Nov 15, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [4b00512]

Summary: ❌

job_name test_name status info comment
Stress test (amd_debug) FAIL
Hung check failed, possible deadlock found FAIL cidb

AI Review

Summary

Adds opt-in Prometheus exemplar storage to TimeSeries tables and the /api/v1/query_exemplars endpoint. Reviewed the current diff and all prior discussion; the seven previous findings are addressed, and no new actionable findings remain. Consumer coverage includes remote-write conversion, TimeSeriesSink, SQL reads and INSERT SELECT copies, HTTP result serialization, and target creation, backup, restore, rename, and deletion.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-feature Pull request with new product feature label Nov 15, 2026
… series in a request

`/api/v1/query_exemplars` reads the inner tables, so a user without a `SELECT` grant
on the `TimeSeries` table, or with a row policy on it, could read all exemplars. The
endpoint now checks the grant on the table and refuses a user with a row policy.

Remote write accepted the exemplars of each entry of a request on its own, so a second
entry of the same series could store an exemplar older than the first entry had, or
its duplicate. The entries of a series now share the newest accepted exemplar, like
the appender of Prometheus.

The test reads a counter of `system.events`, so it failed in the flaky check that
runs its copies in parallel: it is `no-parallel` now. The documentation linked to an
anchor that the generated page of the engine does not have yet.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Comment thread src/Parsers/CreateQueryUUIDs.cpp Resolved
valerypetrov and others added 4 commits November 15, 2026 22:14
- `TimeSeriesSettings::isExemplarsTargetEnabled` is marked `[[nodiscard]]` (clang-tidy).
- Remote write refuses a timestamp which overflows when it is converted to the scale of the table.
- `CREATE TABLE ... ON CLUSTER ... AS` generates the UUID of the exemplars table on the initiator, so that
  every replica gets the same UUID with `distributed_ddl_entry_format_version = 2` too.
- `/api/v1/query_exemplars` checks the grant on the table before the table is looked up.
- Entries of one request which differ only in an empty or a repeated label share the newest accepted exemplar.
- The test keeps its row policy on a separate table: with `throw_on_unmatched_row_policies` the policy made
  the other reads of the table fail.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
A table with `store_exemplars` joins its tags with its exemplars on a read, so a tag column named `exemplars`
from `tags_to_columns` made every such read fail with an ambiguous identifier. The name is now refused for
a table that stores exemplars, like the other reserved column names.

Also initialize `scaled` in `insertTimestamp` for clang-tidy.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Comment thread src/Parsers/CreateQueryUUIDs.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Commit 4b00512179ff8f2b5f1ed634431fc3b29078bcf4 was not compared: the CI logs cluster did not answer (the endpoint never became ready: the readiness probe timed out: HTTPSConnectionPool(host='t6h0zvqlg…).

See the job log for details.

valerypetrov and others added 2 commits November 16, 2026 16:47
…mplars column unambiguous

A table created `AS <other_table>` got a speculative UUID of the exemplars target even when its version
is pinned below the first one with the target. With `distributed_ddl_entry_format_version = 2` that UUID
travels in the DDL entry as `EXEMPLARS INNER UUID`, which a server without the target can't parse, so
the copy of a table of version 11 failed during a rolling upgrade. The UUID is now generated only for the
versions with the target.

A read of a table that stores exemplars joins the tags with the exemplars, so a column of the tags table
named `exemplars` made the outer column ambiguous. The outer column is now qualified with the join.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
clickhouse-gh[bot]
clickhouse-gh Bot previously approved these changes Nov 20, 2026
@clickhouse-gh
clickhouse-gh Bot dismissed their stale review November 20, 2026 03:00

AI review of a later commit does not approve the PR, see the AI Review comment.

valerypetrov and others added 3 commits November 22, 2026 20:42
The test created its `ON CLUSTER` copies with `distributed_ddl_entry_format_version = 2`
to also cover an initiator that ships the query without normalizing it. Entry format
versions below 3 are rejected now, so both statements failed with `UNKNOWN_FORMAT_VERSION`.

The copies are created with the default entry format. The checks stay the same: the entry
in `system.distributed_ddl_queue` carries the UUID of the exemplars table for a table
with exemplars, and no `EXEMPLARS` clause for a table of version 11.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
A read of a `TimeSeries` table which selects both `samples` and `exemplars`
was built as `samples INNER JOIN tags LEFT JOIN exemplars`, so a time series
with exemplars and no row in the "samples" table was lost before the
exemplars were joined. `SELECT metric_name, exemplars` returned it, while
`SELECT *` did not, and `INSERT INTO dst SELECT * FROM ts` dropped its
exemplars.

Now such a read joins the exemplars to the samples with a `FULL JOIN` by `id`
before the `INNER JOIN` with "tags", so the time series is returned with
empty `samples`. A time series with neither samples nor exemplars is still
not returned when `samples` is selected. The reads which do not select both
columns build the same query as before.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@vitlibar vitlibar self-assigned this Nov 23, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

PromQL Compliance Report

Baseline: S3 master df93bed59

Suite Baseline Current Delta
Prometheus compliance 100.00% 100.00% +0.00%
Extended support (upstream engine tests) 93.03% 93.17% +0.14%
Suite Passed Failed Unsupported
Prometheus compliance 539 -> 539 (+0) 0 -> 0 (+0) 0 -> 0 (+0)
Extended support (upstream engine tests) 681 -> 682 (+1) 17 -> 16 (-1) 34 -> 34 (+0)

Extended support (upstream engine tests): native-histogram exclusions: 149; excluded assertions: 248; upstream 3da2514eff5c.

Note: Prometheus compliance score is unchanged vs baseline.

Uploaded compliance JSON for this PR commit

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

can be tested Allows running workflows for external contributors comp-promql PromQL / time-series subsystem: TimeSeries storage engine, PromQL parser, PromQL-to-SQL converter... external Author is not a member of the ClickHouse organization pr-feature Pull request with new product feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants