Skip to content

Implement Prometheus /api/v1/series, /labels, /label/values endpoints - #97032

Closed
ajonkisz wants to merge 60 commits into
ClickHouse:masterfrom
ajonkisz:feature/prometheus-api-endpoints
Closed

ajonkisz wants to merge 60 commits into
ClickHouse:masterfrom
ajonkisz:feature/prometheus-api-endpoints

Conversation

@ajonkisz

@ajonkisz ajonkisz commented Feb 15, 2026 •

Copy link
Copy Markdown

Implement the three remaining Prometheus HTTP API metadata endpoints for the TimeSeries engine, which previously threw NOT_IMPLEMENTED. These endpoints are required by Grafana's Prometheus data source for label autocomplete and the metric browser.

  • /api/v1/series: returns all series with their full label sets by querying the tags table, filtered by the match[] series selectors. Each row is normalized to its logical Prometheus label set (a tags_to_columns tag can live in the dedicated column or in the residual tags Map of a supported external table) with the same rules as timeSeriesStoreTags: both carriers are merged, exact duplicates collapse, empty values are dropped, and conflicting carrier values are rejected with bad_data, so deduplication is by series identity rather than by the raw table layout.
  • /api/v1/labels: returns all distinct label names from the tags Map column and from the tags_to_columns columns, always including __name__ as a virtual label. An empty label value means the label is absent, so a map entry with an empty value (possible in a supported external tags table, e.g. tags = {'env': ''}) does not surface its key as a label name and does not count toward limit, consistently with the other endpoints.
  • /api/v1/label/<name>/values: returns the distinct values for a specific label, reading the metric_name column for __name__, the dedicated tags_to_columns column (falling back to the residual tags Map) for a configured tag, or the tags Map otherwise.

Both of these endpoints validate the carriers of the labels they materialize the same way /api/v1/series and the query endpoints do, so a row holding different non-empty values for one tag in its dedicated column and in the residual tags Map is rejected with bad_data instead of being silently reported.

The optional limit parameter is supported on all the endpoints, and a present-but-empty limit=, start=, or end= is rejected with bad_data rather than being treated as an omitted parameter. The limit is enforced in the emission layer rather than as a SQL LIMIT, so the carrier validation above sees every matched row and a corrupted row cannot be hidden by a small limit and a favorable row order.

The optional start/end parameters filter by the min_time/max_time columns of the tags table and are accepted only when both store_min_time_and_max_time and filter_by_min_time_and_max_time are enabled - the same gate as the query path's tags-table prefilter. When either setting is disabled (including an external tags table that still physically has the bound columns while store_min_time_and_max_time = 0), a ranged metadata request is rejected instead of silently diverging from /api/v1/query and /api/v1/query_range.

The match[] parameter accepts full Prometheus series selectors (a bare metric name or an instant selector with =, !=, =~, !~ label matchers, e.g. cpu_usage{host="server1"}), parsed with the same PromQL parser as /api/v1/query and translated into the same tags-table filter the query endpoints use, so all three metadata endpoints select exactly the series the query endpoints would read. A repeated match[] is the union of the selectors, as in Prometheus. A matcher on a tags_to_columns tag resolves the tag with the same carrier normalization as the endpoints themselves: the dedicated column wins when non-empty (NULL is normalized to the empty label value), the residual tags Map is used otherwise, and a row carrying different non-empty values in the two carriers is rejected with bad_data instead of silently preferring one of them. Regexp matchers are fully anchored (^(?:...)$), and non-legacy (UTF-8) label names are written as quoted string literals, e.g. {"http.status_code"="200"}, both as in Prometheus. A selector whose matchers all match the empty label value (e.g. {host=~".*"}) is rejected with bad_data, as in Prometheus - at least one matcher must not match the empty string, so a match[] cannot degenerate into an unfiltered scan - and an invalid regexp anywhere in a selector is likewise rejected with bad_data at parse time.

Label names and values are JSON-escaped on output and string literals interpolated into the generated SQL are quoted, so values containing quotes, backslashes, or control characters are handled correctly.

Changelog category (leave one):

  • New Feature

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

Implemented the Prometheus /api/v1/series, /api/v1/labels, and /api/v1/label/<name>/values metadata endpoints for the TimeSeries engine.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

…dpoints

The Prometheus HTTP API had placeholder implementations for the series,
labels, and label-values endpoints that threw NOT_IMPLEMENTED. This
makes them functional by querying the TimeSeries tags table:

- /api/v1/series: Returns all series with their full label sets by
  querying metric_name and tags from the tags table. Supports optional
  match[] parameter for metric name filtering.

- /api/v1/labels: Returns all unique label names by extracting distinct
  keys from the tags Map column. Always includes __name__ as a virtual
  label. Supports optional match[] filtering.

- /api/v1/label/<name>/values: Returns distinct values for a specific
  label. For __name__, queries the metric_name column directly. For
  other labels, extracts values from the tags Map column.

These endpoints are required for Grafana's Prometheus data source to
function properly (label autocomplete, metric browser, etc.).
@CLAassistant

CLAassistant commented Feb 15, 2026 •

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
0 out of 2 committers have signed the CLA.

❌ ajonkisz
❌ alexey-milovidov
You have signed the CLA already but the status is still pending? Let us recheck it.

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Feb 15, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member

Please sign the CLA.

@clickhouse-gh

clickhouse-gh Bot commented Feb 15, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [0126adf]

Summary: ❌

job_name test_name status info comment
Stress test (amd_tsan) FAIL
Logical error: Join is supported only for pipelines with one output port, got A and B (STID: 4488-4e11) FAIL cidb
Stress test (arm_release) FAIL
Logical error: Initiator received more initial requests than there are replicas: replica_num=A (STID: 7334-5b92) FAIL cidb

AI Review

Summary

This PR fills out the Prometheus metadata endpoints for the TimeSeries engine and closes most of the earlier compatibility gaps around selectors, tags_to_columns, escaping, range filters, and query-cache handling. I still see two user-facing behavior problems in the current implementation, so this is not ready to merge as-is.

Findings

⚠️ Majors

  • [src/Storages/TimeSeries/PrometheusHTTPProtocolAPI.cpp:1187] The conflicting-carrier validation for /api/v1/label/<name>/values is embedded in value_expr, and value_expr != '' is placed ahead of the selector / range predicates in WHERE. With short_circuit_function_evaluation defaulting to disable, that validation runs on every row before match[] / start / end can discard unrelated rows. One corrupt row in some other series can therefore make an otherwise unrelated label-values request fail with bad_data.
    Suggested fix: filter by selector / range in a subquery first, then compute and validate label_value in the outer query.

  • [src/Server/PrometheusRequestHandler.cpp:469] The new optional-parameter parsing no longer matches Prometheus' wire contract. Upstream Prometheus treats limit= as the default 0, treats empty start= / end= as omitted bounds, and rejects limit once it overflows int; this branch now rejects blank optional parameters and accepts huge UInt64 limits instead. That is a compatibility break in both directions for clients expecting Prometheus behavior.
    Suggested fix: mirror Prometheus' parseLimitParam / parseTimeParam semantics here, or document the differences as intentional incompatibilities and stop describing the new behavior as "like Prometheus".

Final Verdict

⚠️ Request changes

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.70% 86.70% +0.00%
Functions 92.00% 92.00% +0.00%
Branches 79.10% 79.10% +0.00%

Changed lines: Changed C/C++ lines covered: 744/782 (95.14%) · Uncovered code

Full report · Diff report

@ajonkisz

Copy link
Copy Markdown
Author

/rerun

@clickhouse-gh clickhouse-gh Bot added the manual approve Manual approve required to run CI label Feb 15, 2026
@alexey-milovidov alexey-milovidov added the close in a month if not active This will be closed in case of no information label Feb 16, 2026
@JTCunning JTCunning added the comp-promql PromQL / time-series subsystem: TimeSeries storage engine, PromQL parser, PromQL-to-SQL converter... label Feb 18, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member

Corporate CLA is signed.

@JTCunning

Copy link
Copy Markdown
Contributor

@ajonkisz: greetings, I'm the product manager for PromQL support and the TimeSeries table engine.

I'm happy to see this contribution through and attribute it to you if you were to resolve the merge conflicts.

If you would like me to take it over, solve the conflicts, shepherd it through CI, and get it merged, I can also do that.

@vitlibar vitlibar self-assigned this May 7, 2026
@alexey-milovidov alexey-milovidov removed manual approve Manual approve required to run CI close in a month if not active This will be closed in case of no information labels May 31, 2026
alexey-milovidov and others added 2 commits May 31, 2026 21:05
…api-endpoints

# Conflicts:
#	src/Storages/TimeSeries/PrometheusHTTPProtocolAPI.cpp
- `getLabelValues`: the `__name__` branch produced no `WHERE` clause, yet a
  non-empty `match[]` parameter appended ` AND ...`, yielding invalid SQL
  (`... FROM table AND metric_name = ...`). Collect conditions into a list and
  emit `WHERE`/`AND` correctly so the query is valid in every branch.
- JSON-escape all label names and values written by `getSeries`, `getLabels`,
  and `getLabelValues` using `writeJSONString`, matching `writeTags`. Raw
  `writeString` of column data could emit invalid JSON when a value contained a
  quote, backslash, or control character.
- Quote string literals interpolated into the generated SQL with `quoteString`
  instead of bare `'{}'`, so metric names and label names containing a quote no
  longer break the query.
- Use a raw string literal for the `__name__` JSON prefix (`modernize-raw-string-literal`).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@clickhouse-gh clickhouse-gh Bot added the pr-feature Pull request with new product feature label May 31, 2026
@alexey-milovidov alexey-milovidov self-assigned this May 31, 2026
alexey-milovidov and others added 3 commits June 1, 2026 20:09
The `tags` column of the tags target table is a `Map`, which materializes
as `ColumnMap`, not `ColumnArray`. The previous `typeid_cast<const ColumnArray *>`
always failed, so `getSeries` silently dropped every label and `/api/v1/series`
returned only `__name__`. Read the nested array via `ColumnMap::getNestedColumn`
and `ColumnMap::getNestedData` instead.

The tags target is usually `AggregatingMergeTree`/`ReplacingMergeTree` and stores
a row per write, so the same series can appear multiple times until parts are
merged. Use `SELECT DISTINCT` to deduplicate by series identity, and drop the
arbitrary `LIMIT 10000` that silently truncated the result.

Also remove the now-unused `NOT_IMPLEMENTED` error code (fixes the style check).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…meter

`request.getURI()` includes the query string, so a request such as
`/api/v1/label/host/values?match[]=cpu_usage` no longer ended with `/values`
and fell through to a 404 before `getLabelValues` was reached. Route on the
path component (the URI with the query string stripped) instead.

`match[]` was not reserved in `QueryAPIImpl::isSettingLikeParameter`, so it was
treated as a ClickHouse setting in `makeContext` and a request like
`/api/v1/series?match[]=cpu_usage` failed with an unknown-setting error. Reserve
`match[]` so it is handled as an endpoint parameter.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The `setup` fixture never created the `prometheus` `TimeSeries` table, so every
test errored with `Table default.prometheus does not exist` (the remote-write
endpoint returned 404). Create the table before sending test data.

The `/api/v1/label/<name>/values` handler rule used `<url>/api/v1/label/*/values</url>`,
but the URL filter matches non-regex values exactly (`*` is a literal, not a
wildcard), so dynamic label names never matched and the endpoint returned 404.
Use a `regex:` rule instead.

Add regression tests covering the fixes: `/api/v1/series` now returns the full
label set, `match[]` filtering works, `/api/v1/label/<name>/values?match[]=...`
routes correctly with a query string, and series are deduplicated.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Aug 9, 2026
alexey-milovidov and others added 2 commits August 9, 2026 16:24
…api-endpoints

# Conflicts:
#	src/Parsers/Prometheus/tests/gtest_PromQLParser.cpp
#	src/Server/PrometheusRequestHandler.cpp
#	src/Storages/TimeSeries/PrometheusHTTPProtocolAPI.cpp
#	src/Storages/TimeSeries/PrometheusHTTPProtocolAPI.h
The branch explicitly rejected the `lookback_delta` parameter while it
was not implemented. `master` now implements it for `/api/v1/query` and
`/api/v1/query_range`, so the explicit rejection (an auto-merged
semantic conflict) would have disabled the new feature. Keep rejecting
only the still-unimplemented `timeout` and `stats` parameters, and
update the test and the documentation accordingly.

Co-Authored-By: Claude Fable 5 <[email protected]>
Comment thread src/Server/PrometheusRequestHandler.cpp Resolved
Comment thread src/Storages/StorageTimeSeries.cpp Resolved
…tadata endpoints

Three findings of the AI review on `79a7ea14bb9c`:

1. `getLimitParam` read the `limit` parameter with `params->get("limit", "")`, so a
present-but-empty `limit=` was indistinguishable from an omitted one and silently
turned a malformed request into an unbounded response. It is now rejected with
`BAD_ARGUMENTS` (`bad_data`), the same way `start=` / `end=` already are.

2. `/api/v1/labels` and `/api/v1/label/<name>/values` materialized labels straight
from the raw carriers, so a row holding different non-empty values for a
`tags_to_columns` tag in the dedicated column and in the residual `tags` Map was
reported by them while `/api/v1/query`, `/api/v1/series`, and the write path
(`timeSeriesStoreTags`) reject it - the metadata endpoints hid the corruption.
Both endpoints now evaluate the same `throwIf` carrier check that
`timeSeriesTagNameToAST` applies to matchers, for the labels they materialize:
`/api/v1/labels` for every configured tag, `/api/v1/label/<name>/values` for the
requested one. A request that reads neither carrier (e.g. the values of a
Map-only label) is unaffected.

3. The `lookback_delta` parameter is supported since the master merge, but the
documentation block registered in `StorageTimeSeries.cpp` still listed it as not
implemented, contradicting `time-series.mdx` and the behavior.

Tests: new `test_series_labels_api_empty_limit_param.py` (empty `limit=` rejected on
all three metadata endpoints and on `/api/v1/query` / `/api/v1/query_range`, absent
and valid values still work), and the conflicting-carrier fixture now also asserts
`bad_data` from `/api/v1/labels` and `/api/v1/label/host/values`.
…bels

`/api/v1/labels` derived the map-backed label names from raw `mapKeys(tags)`,
so a supported external `tags` table row like `tags = {'env': ''}` surfaced
`env` as a label name even though the rest of the implementation treats an
empty label value as "label absent" (`/api/v1/series` drops such entries,
matcher translation treats them as the missing case, and
`/api/v1/label/<name>/values` filters them). The spurious name also counted
toward `limit`. Build the map-backed side of the label-keys array from
key/value pairs filtered to non-empty values before the `LEFT ARRAY JOIN`,
in both the plain and the `tags_to_columns` variants of the expression.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=97032&sha=984be728783e19cc624fb7e60acb45a15471aa3a

Co-Authored-By: Claude Fable 5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Pushed 699f63d12882 addressing the AI review's ⚠️ Request changes major on head 984be728783e.

/api/v1/labels no longer surfaces keys of empty-valued tags Map entries — the map-backed side of the label-keys array is now built from key/value pairs filtered to non-empty values before the LEFT ARRAY JOIN, in both the plain and the tags_to_columns variants, so a supported external tags table row like tags = {'env': ''} is treated as "label absent" here exactly as in /api/v1/series, the matcher translation, and /api/v1/label/<name>/values, and the spurious name no longer counts toward limit. A matching series whose every map entry has an empty value still signals its existence, so the virtual __name__ label still appears for it. Added the focused regression test_series_labels_api_empty_map_value_label.py and verified all assertions live against a local server (both table layouts).

Both CI failures on 984be728783e are unrelated to this PR:

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=97032&sha=984be728783e19cc624fb7e60acb45a15471aa3a

@groeneai

Copy link
Copy Markdown
Collaborator

The SettingsImpl LeakSanitizer half (STID 2064-22d0) is owned by #113397, still open. That is the MaterializedCTE/QueryPlan reference cycle you attached this signature to.

I did not open a competing PR. I root-caused it independently first and landed on the same two edges, then found #113397 already covered them plus a third file I had missed (addPlansForMaterializingCTEs.cpp), which is load-bearing. The corroboration is in #113954.

So this artifact will keep reproducing here until #113397 merges. Both halves of your request now have an owner.

alexey-milovidov and others added 2 commits August 12, 2026 06:44
…equests

Two fail-close fixes for the Prometheus metadata endpoints:

- Reject 'start'/'end' whenever the `store_min_time_and_max_time` setting is
  disabled, before consulting the external table schema. Disabling only that
  setting leaves `filter_by_min_time_and_max_time` reading as `true`, and a
  supported external 'tags' table can still physically keep the
  `min_time`/`max_time` columns, so the endpoints would otherwise apply a
  prefilter over stale bounds that `StorageTimeSeriesSelector::readImpl`
  explicitly skips in this mode.

- Stop pushing the 'limit' parameter down as a SQL `LIMIT` on
  `/api/v1/series`, `/api/v1/labels`, and `/api/v1/label/<name>/values`: the
  mixed-carrier `bad_data` validation must see every matched row, and a
  SQL-side `LIMIT` lets the scan stop early, so whether a corrupted row was
  detected depended on the caller's 'limit' and on row order. The limit is
  now enforced only in the emission layer, like on `/api/v1/query`. With the
  `LIMIT limit + 1` arithmetic gone, the `UInt64` max value of 'limit' no
  longer needs to be rejected and behaves as an ordinary huge limit.

New integration tests: `test_series_labels_api_store_disabled_external_bounds.py`
(ranged requests rejected with `store_min_time_and_max_time = 0` on an external
tags table that still has the bound columns, unranged requests keep working) and
`test_series_labels_api_limit_conflicting_row.py` (a conflicting-carrier row that
sorts after more than 'limit' valid series still fails the request with
`bad_data` on all three endpoints, and truncation still works when the selector
excludes the malformed row).

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=97032&sha=699f63d1288291ae74bc740eada27a394b8b5b3e
PR: ClickHouse#97032

Co-Authored-By: Claude Fable 5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Pushed 4ad6cfd7e276 addressing the AI review's ❌ Request changes verdict (1 Blocker, 1 Major) on head 699f63d12882, after merging master.

Blocker — ranged metadata requests now gate on store_min_time_and_max_time: appendTimeRangeConditions rejects start/end whenever the setting is disabled, before consulting the external table schema, matching the filter_by_min_time_and_max_time && store_min_time_and_max_time gate of StorageTimeSeriesSelector::readImpl. Previously a supported external tags table that still physically had min_time/max_time columns with store_min_time_and_max_time = 0 would get a prefilter over stale bounds that the query path skips. New regression: test_series_labels_api_store_disabled_external_bounds.py.

Major — limit no longer bounds the scan: the limit parameter is not pushed down as a SQL LIMIT on the three metadata endpoints anymore; it is enforced only in the emission layer, like on /api/v1/query, so the mixed-carrier bad_data validation sees every matched row regardless of limit and row order. With the LIMIT limit + 1 arithmetic gone, the special rejection of the UInt64 max limit value lost its basis and was removed. New regression: test_series_labels_api_limit_conflicting_row.py (a conflicting row sorting after more than limit valid series still fails with bad_data on all three endpoints). All assertions of both new tests verified live against a local server.

CI on 699f63d12882 had 3 failures, all unrelated to this PR:

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=97032&sha=699f63d1288291ae74bc740eada27a394b8b5b3e

…point test

Commit 4ad6cfd moved the limit enforcement of the metadata endpoints
to the emission layer and removed the UInt64-max rejection in
`PrometheusRequestHandler::getLimitParam` (replacing
`test_limit_uint64_max_is_rejected` with `_is_accepted`), but
`test_invalid_limit_is_rejected_on_query_endpoints` still expected 400
for `limit=18446744073709551615` on `/api/v1/query`, which now correctly
returns 200 - the only failure of CI run
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=97032&sha=4ad6cfd7e276d7a45cdc7688b041012e78b55f82&name_0=PR
(the same test in 6 jobs). Also pin the accepted behavior on
`/api/v1/query` in `test_limit_uint64_max_is_accepted`.
…alue

Prometheus rejects a series selector in which every matcher matches the
empty label value (e.g. `{job=~".*"}`), because such a selector does not
narrow the series set at all; accepting it made `match[]={job=~".*"}`
behave like an unfiltered scan on the metadata endpoints, bypassing the
"'match[]' is required" guard on `/api/v1/series`. Now
`makeMatchCondition` requires at least one matcher per selector that
cannot match the empty label value, with regexp matchers evaluated
against the empty string using the same fully-anchored RE2 semantics as
the generated `match` condition. Every matcher is checked (no
short-circuit), so an invalid regexp anywhere in a selector is also
rejected with `bad_data` at parse time instead of failing later inside
the generated SQL. Addresses the AI review Major on
src/Storages/TimeSeries/PrometheusHTTPProtocolAPI.cpp.

`test_negative_alternation_regexp_is_fully_anchored` gains a metric name
matcher (its bare `{host!~"server1|server2"}` selector is now rejected,
as in Prometheus), and the new
`test_series_labels_api_empty_matching_selector.py` covers the rejected
and accepted selector shapes, the union behavior, and invalid regexps.
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Pushed 0126adf1c8db addressing the AI review's ⚠️ Request changes Major on head 4ad6cfd7e276 and the CI failure of run 31573974449.

match[] selectors whose matchers all match the empty label value are now rejected — {job=~".*"} and the like returned an effectively unfiltered scan on the three metadata endpoints, bypassing the "match[] is required" guard on /api/v1/series; now each selector must contain at least one matcher that cannot match the empty label value (bad_data otherwise), exactly the Prometheus rule. Regexp matchers are evaluated against the empty string with the same fully-anchored RE2 semantics as the generated match condition, all matchers are checked without short-circuiting (so an invalid regexp anywhere in a selector also fails upfront with bad_data), and the docs sentence that documented the old relaxation now documents the rejection. New test_series_labels_api_empty_matching_selector.py; test_negative_alternation_regexp_is_fully_anchored gained a metric-name matcher, since its bare {host!~"server1|server2"} selector is rejected by Prometheus too.

The 6 red CI jobs were all one stale test case (99189f82d1ff): 4ad6cfd7e276 removed the UInt64-max limit rejection together with the SQL-side LIMIT, but test_invalid_limit_is_rejected_on_query_endpoints still expected 400 for limit=18446744073709551615 on /api/v1/query, which now correctly returns 200. The case is dropped and the accepted behavior is pinned in test_limit_uint64_max_is_accepted instead.

All the endpoint behaviors were verified live against a local build (rejected and accepted selector shapes, union of a valid and an invalid match[] value, invalid regexps, limit parsing on the query endpoints).

quoteString(label_name),
makeTagCarrierConflictCheck(label_name, column_name));
query = fmt::format("SELECT DISTINCT {} AS label_value FROM {}", value_expr, tags_table_id.getFullTableName());
conditions.push_back(fmt::format("{} != ''", value_expr));

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.

value_expr now contains throwIf(...), and this WHERE starts by evaluating value_expr != '' before the later match[] / start / end predicates. With short_circuit_function_evaluation defaulting to disable, that means the conflicting-carrier check runs on every row of the tags table, not just on the rows selected by this request. A single bad host row in some unrelated series would therefore make /api/v1/label/host/values?match[]=cpu_usage fail even when the corrupt row is outside the requested selector or time range. Please filter by match[] / range in a subquery first and only then compute and validate label_value.

/// An absent parameter means "no limit", but a present-and-empty one (e.g. "limit=") is malformed:
/// treating it as absent would silently turn a broken request into an unbounded response, so reject
/// it - Prometheus answers such requests with a `bad_data` error as well.
UInt64 getLimitParam() const

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.

This parser no longer matches Prometheus' own optional-parameter semantics. Upstream Prometheus treats limit= as the default 0 (no limit), treats empty start= / end= as omitted bounds, and rejects limit once it overflows int; this branch instead 400s on blank optional parameters and accepts huge UInt64 limits such as 18446744073709551615. That makes the API stricter in some cases and looser in others than the Prometheus-compatible behavior the new tests are claiming. If the goal here is compatibility, this helper should mirror Prometheus' parsing rather than define a different wire contract.

@clickhouse-gh

clickhouse-gh Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Dear @nikitamikhaylov, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself.

@nikitamikhaylov

Copy link
Copy Markdown
Member

All of them were implemented in separate PRs.

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... hold Skip for auto-updating. manual approve Manual approve required to run CI pr-autogenerated-docs PR that regenerates docs artifacts from source; exempt from the autogenerated-region edit guard pr-feature Pull request with new product feature submodule changed At least one submodule changed in this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants