Repository navigation
Conversation
|
Workflow [PR], commit [19e1823] Summary: ✅
AI ReviewSummaryThis PR adds Findings
Tests
Final VerdictStatus: Minimum required actions: narrow |
| || handler_type == "expose_metrics" | ||
| || handler_type == "remote_write" | ||
| || handler_type == "remote_read" | ||
| || handler_type == "query_api") |
There was a problem hiding this comment.
@vitlibar: Referring to an offline conversation, this is where I got confused. We register the prometheus handler type but none of the others.
I'm unsure if we should register every handler type as it exists today, or if we should just have a generic prometheus type that case-switches. That would allow us to end up with a single registered prefix, ie:
<handler>
<type>prometheus</type>
<prefix>/prometheus</table> //could be an implicit default
<table>default.prometheus</table>
</handler>I feel like this is what we should ultimately end up with since it cuts down on a lot of configuring in XML. I'm definitely willing to do it in a series of PRs instead of one big jump if that's how we should go about it.
There was a problem hiding this comment.
I think the right solution here is to add another handler type api_v1 here which handles all prometheus /api/v1 protocols (/api/v1/write, /api/v1/read, /api/v1/query, /api/v1/query_range, etc.):
<http_port>8123</http_port>
<http_handlers>
<my_rule_1>
<url>/prometheus/api/v1</url>
<handler>
<type>prometheus.api_v1</type>
<table>db.time_series_table_name</table>
</handler>
</my_rule_1>
</http_handlers>
I'll finish this PR
03d2e26 to
d9f51a5
Compare
|
Waiting for #107492 |
Dispatch handler.type=prometheus rules from literal <url> path suffixes so bare and prefixed remote write, read, and query API paths can coexist on 8123. Reject regex: <url> values at config load instead of silently serving exposition, and route Query API sub-endpoints by path suffix. Add integration coverage in test_prometheus_protocols. Co-authored-by: Cursor <[email protected]>
Register remote_write, remote_read, and query_api in http_handlers and build rules through parseHandlerConfig instead of inferring protocols from <url> suffixes. Update integration and http_handlers configs to use explicit types, treat prometheus as an expose_metrics alias, and drop the regex startup test that depended on URL-based dispatch. Co-authored-by: Cursor <[email protected]>
Restore the factory header metrics example, keep PromQL Params named params, parse label values from the trailing /values suffix, and add prefixed query_range integration coverage. Co-authored-by: Cursor <[email protected]>
Co-authored-by: Cursor <[email protected]>
Target a dedicated prometheus_http TimeSeries table on 8123, add prefixed query_range and label-values routing checks, and keep the http_handlers prometheus handler fixture on type=prometheus. Co-authored-by: Cursor <[email protected]>
…> prometheus_write, prometheus_query_api -> prometheus_query
d9f51a5 to
64e39ba
Compare
64e39ba to
d95c929
Compare
There was a problem hiding this comment.
Pull request overview
Adds support for serving Prometheus HTTP API endpoints (including /api/v1/*) on the main HTTP port via http_handlers, with the ability to mount them behind a URL prefix (e.g. /prometheus/api/v1/*). This is implemented by extending the Prometheus handler configuration/types and adding an api_v1 dispatcher handler.
Changes:
- Extend Prometheus handler type parsing to support new canonical names (
metrics/write/read/query) plus deprecated aliases, and introduce anapi_v1handler type. - Add request dispatch logic so
/api/v1/*endpoints can work both “bare” and behind a configured prefix. - Update integration test configs and add a new integration test validating prefixed operation on the main HTTP port.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
tests/integration/test_prometheus_protocols/test_query_api.py |
Refactors imports; adjusts query API tests (but currently leaves a missing assertion). |
tests/integration/test_prometheus_protocols/test_http_port.py |
New integration test covering prefixed /prometheus/api/v1/* on port 8123 and coexistence with bare endpoints. |
tests/integration/test_prometheus_protocols/configs/prometheus.xml |
Updates handler type names to the new canonical identifiers (write/read/query). |
tests/integration/test_prometheus_protocols/configs/http_port.xml |
New http_handlers config mounting Prometheus API v1 under a prefix on the main HTTP port. |
src/Storages/TimeSeries/PrometheusHTTPProtocolAPI.h |
Updates class comment to reflect broader Prometheus HTTP API scope. |
src/Storages/TimeSeries/PrometheusHTTPProtocolAPI.cpp |
Updates internal comment referencing the renamed query handler impl. |
src/Server/PrometheusRequestHandlerFactory.h |
Updates documentation/examples for new handler types (contains a malformed XML example). |
src/Server/PrometheusRequestHandlerFactory.cpp |
Adds handler type parsing/aliases and api_v1 config parsing (currently includes a compile-breaking call). |
src/Server/PrometheusRequestHandlerConfig.h |
Adds APIv1/renames handler types; updates documentation (needs small doc correction). |
src/Server/PrometheusRequestHandler.h |
Renames impl classes and adds APIv1Impl (needs doc comment update). |
src/Server/PrometheusRequestHandler.cpp |
Implements suffix-based path dispatch for prefixed URLs and adds APIv1Impl dispatcher. |
src/Server/HTTPHandlerFactory.cpp |
Routes prometheus* handler types to the Prometheus handler factory. |
Comments suppressed due to low confidence (1)
tests/integration/test_prometheus_protocols/test_query_api.py:219
- The test assigns
errorbut never asserts anything about it, so the last check becomes a no-op and will pass even if the handler returns an unexpected error.
error = execute_query_via_http_api(
node.ip_address, 9093, "/api/v1/query", query, timestamp=timestamp,
params={"database": "other"}, expect_error=True,
)
9ee1c72 to
19e1823
Compare
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 154/174 (88.51%) | Lost baseline coverage: none · Uncovered code |
|
Example: config: request: Notes:
|
Prometheus handlers configured without a pinned <table> now resolve the target TimeSeries table from the X-ClickHouse-Database / X-ClickHouse-Table HTTP headers, in addition to the existing ?database=&table= URL query parameters (added in ClickHouse#104975). Per-field precedence (database and table resolved independently): 1. XML <table> config (pinned; a conflicting query param still errors) 2. ?database= / ?table= URL query parameters 3. X-ClickHouse-Database / X-ClickHouse-Table headers (lowest priority) Header values are consulted only when a name is left unset by both the configuration and the query parameters, are sanitized (ASCII control characters removed) to prevent CRLF header injection, and never error on a conflict with a pinned value. When nothing resolves the table the request fails with a clear error (no implicit default table).
Replace the dedicated <prometheus> protocols port in the documented server setup with a single prometheus_api_v1 http_handlers rule mounted under a url_prefix on the main HTTP port, following ClickHouse/ClickHouse#104975. One rule serves all /api/v1 protocols (remote write, query, query_range), replacing the three per-endpoint handler rules. The runner's default --urls becomes http://localhost:8123/prometheus to match.
This allows us to handle prom endpoints on the main http port, but adds the ability to use a prefix (like
/prometheus) so that we aren't establishing a pattern of someone issuing queries toclickhouse:8123/api/v1/*and establishing more of an industry standard approach to issue queries likeclickhouse:8123/prometheus/api/v1/*.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Allow for attaching prometheus handlers on the main http port with an optional prefix.
Version info
26.6.1.1137