Repository navigation
Prometheus HTTP API: implement /api/v1/format_query - #117159
Conversation
The endpoint parses the PromQL expression from the 'query' parameter and returns it serialized from the parsed tree (PrometheusQueryTree::toString): the whitespace is normalized, the comments are removed, the redundant parentheses are dropped, and the durations are converted to numbers of seconds. The endpoint only parses the expression, so it is dispatched before the TimeSeries table lookup and doesn't require a table. A minimal rewrite of #115757 Co-authored-by: Minh Vu <[email protected]> Co-Authored-By: Claude Fable 5 <[email protected]>
|
Preview deployment for your docs. Learn more about Mintlify Previews.
|
|
Workflow [PR], commit [f6b317c] Summary: ❌
AI ReviewSummaryAdds Tests
Final Verdict
LLVM Coverage Report |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 10 s compile time in total, 7 of them have a recent master baseline. |
`cluster.start()` waits for the native TCP port, and the Prometheus protocols port can start accepting connections slightly later. The other test modules of `test_prometheus_protocols` mask this window by creating tables and inserting data right after `cluster.start()`, but `test_format_query_api.py` sends its first HTTP request immediately, which failed with `Connection refused` in the slower sanitizer jobs: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=117159&sha=552c1f7bd1e3c1cccd1fe242519699ae33e9b8da&name_0=PR&name_1=Integration%20tests%20(amd_asan_ubsan%2C%20flaky) Poll the endpoint until the port accepts connections before running the tests. Co-Authored-By: Claude Fable 5 <[email protected]>
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=117159&sha=552c1f7bd1e3c1cccd1fe242519699ae33e9b8da&name_0=PR&name_1=Integration%20tests%20(amd_asan_ubsan%2C%20db%20disk%2C%20old%20analyzer%2C%206%2F6) and provide a fix in a separate PR. If the fix is already in progress, link it here.
|
|
Investigated. Not related to this pull request, and not a ClickHouse fault: one node's server process is killed from outside by a memcg OOM in the dind cgroup hierarchy. Measured on this run's own artifacts (
Worth having from the same job: on the retry at Your breadth reading matches mine: 23 failures on 2026-08-29 and 21 on 2026-08-30. One addition: all 44 are in the On the fix: #117104 ("Keep the kernel's memory-kill record when an integration test run fails"), merged today, is prerequisite diagnostics for this exact failure and not the fix, so a fix-PR search would not have surfaced it. Extending that record to cover the whole run (the 7.6% above) is in progress, and the node-death fix follows it. A fix task owns this at full effort, and I will post the fixing-PR link in this thread when it opens. |
|
Fixing PR for the The mechanism, to close out my earlier comment here. On a hung |
|
@groeneai why the tests failed? Investigate and link the fix PRs. |
|
Five reds on
False red, no product bug. Fixing PR: #117218. 17 distinct PRs have hit it since 2026-08-30 22:48Z. This check has no true-master runs at all (0 of 109304 CIDB rows in 30 days), so its breadth is only measurable across PRs.
Fixing PR: #113589, open. CIDB over 30 days: 74 rows, 57 distinct PRs, 8 true-master shas, across
Fixing PR: #117202, merged today at 11:05:36Z. This run's merge commit was resolved at 10:58:46Z, about seven minutes before that merge, so the tree predates the fix and a fresh run on an updated base picks it up. One caveat so the rebase is not a surprise: on true-master trees that provably contain #117202 (ancestry checked against its merge commit, 13 shas),
|
|
|
||
| # The endpoint only parses the PromQL expression, so no TimeSeries table is created: | ||
| # the tests also verify that the endpoint works without one. | ||
| node = cluster.add_instance( |
There was a problem hiding this comment.
/api/v1/format_query is advertised to work both as a dedicated Prometheus-port handler and through the prefixed prometheus_api_v1 route on the main HTTP port, but this new suite only exercises the dedicated query handler. The prefixed path goes through the separate APIv1Impl::getImpl dispatch, so there is still no regression coverage for half of the documented surface. Could we add a small test_http_port.py case for /prometheus/api/v1/format_query as well?
|
@groeneai investigate the test failures and link the PRs with fixes (implement them if needed). |
|
One red at Statement 2 of that test pins Pre-existing: 26 hits over 22 distinct PRs and 5 check variants in the last 7 days, including 2 true-master runs ( Fixing PR: #117326 (mine, open). To unblock this PR without waiting for that fix, re-running the one job should be enough: the in-job diagnostics rerun already passed 17/17 with the same randomized settings, since the overshoot needs concurrent load from the parallel suite. |
…uery-api-minimal # Conflicts: # docs/concepts/features/interfaces/prometheus.mdx
PromQL Compliance ReportBaseline: S3 master
Note: score is unchanged vs baseline. |
|
@nikitamikhaylov — ClickGap found the following in this PR:
Close anything that's wrong or already addressed. |
Related: #115757
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Implemented the
/api/v1/format_queryendpoint of the Prometheus HTTP API. It parses the given PromQL expression and returns it in a canonical form.Description
A minimal rewrite of #115757 (co-authored with @fallintoplace).
The endpoint reuses the existing canonical serialization
PrometheusQueryTree::toStringinstead of introducing a second PromQL formatter: the expression from thequeryparameter is parsed and returned serialized from the parsed tree, with the whitespace normalized, the comments removed, and the redundant parentheses dropped. Parse errors are reported with the standard Prometheus error envelope (HTTP 400,errorType: bad_data), like on the other query endpoints. The endpoint only parses the expression, so it is dispatched before theTimeSeriestable lookup and doesn't require a table.Unlike the Prometheus implementation, the output is always a single line, and the durations are printed as numbers of seconds (
rate(foo[5m])becomesrate(foo[300])), which is the canonical form already used by the PromQL round-trip in this codebase. Printing the durations with time units would be a follow-up change to the sharedtoString.Covered by 19 new integration tests in
test_format_query_api.py(all pass locally).Workflow [PR]
Sync PR [sync-upstream/pr/117159]
Version info
26.9.1.558(included in26.9and later)