Repository navigation
Store Prometheus exemplars in TimeSeries tables and serve /api/v1/query_exemplars - #130398
valerypetrov wants to merge 15 commits into
Conversation
…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]>
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
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]>
|
Workflow [PR], commit [4b00512] Summary: ❌
AI ReviewSummaryAdds opt-in Prometheus exemplar storage to Final VerdictStatus: ✅ Approve |
… 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]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>
- `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]>
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]>
Build profile diff (arm_release)Commit See the job log for details. |
…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]>
AI review of a later commit does not approve the PR, see the AI Review comment.
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]>
PromQL Compliance ReportBaseline: S3 master
Extended support (upstream engine tests): native-histogram exclusions: 149; excluded assertions: 248; upstream Note: Prometheus compliance score is unchanged vs baseline. |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
TimeSeriestables can store Prometheus exemplars (settingstore_exemplars), and the Prometheus HTTP API serves them at/api/v1/query_exemplars.Documentation entry for user-facing changes
A
TimeSeriestable created withstore_exemplars = 1(table version 12) gets an optionalexemplarsinner table and an outer columnexemplars, and remote write stores the exemplars that Prometheus 3.5 accepts instead of dropping them./api/v1/query_exemplarsanswers like Prometheus: selectors are taken fromquery, exemplars are filtered bystart/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 9query_exemplarsanswers of the new test05617_timeseries_exemplarsare 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]