Skip to content

web/api: fix query cost timeout handling, feature discovery and docs - #20031

Merged
roidelapluie merged 2 commits into
prometheus:roidelapluie/query-cost-apifrom
aknuds1:arve/roidelapluie/query-cost-api
Oct 20, 2026
Merged

roidelapluie merged 2 commits into
prometheus:roidelapluie/query-cost-apifrom
aknuds1:arve/roidelapluie/query-cost-api

Conversation

@aknuds1

@aknuds1 aknuds1 commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

With query-cost enabled, a query that timed out or was canceled while waiting for a query slot during construction was reported as 400 bad_data (invalid parameter "query"). A timeout above --query.timeout was rejected even when query_max_duration was unset, contrary to the docs. A negative max_query_duration was silently ignored. With cost=true, the estimate had its own duration limit on top of the query's, so a request could take twice the limit, and the finished result was held in memory while the estimate waited for a slot. The features API did not report the feature, although the per-query overrides are silently ignored when it is off, and several doc statements did not match the code.

Report construction timeouts and cancellations as timeouts (503) and cancellations (499). Cap the timeout parameter at the effective duration ceiling, as before the feature; this reverses the reject-not-clamp choice for timeout only, and the new max_* parameters keep rejecting values above their ceilings. Reject a negative max_query_duration. For cost=true, estimate after building the query and before executing it, so the estimate counts against the query's duration limit and a malformed query fails before any estimation. Advertise the feature as query_cost in /api/v1/features. Document that the limits apply to rule evaluation, that duration rejections are usually timeouts, the max_query_duration ceiling and how remote read affects estimates; correct the samplesRead wording and drop the claim about UI support. Add an end-to-end test that the configured limits apply only with the feature enabled and follow a config reload.

Part of #20028. This PR targets roidelapluie/query-cost-api and contains two commits above Julien's branch: the fixes, and a separate test consolidation that can be dropped on its own.

NONE

@aknuds1
aknuds1 force-pushed the arve/roidelapluie/query-cost-api branch 6 times, most recently from c28e7ba to 06df941 Compare October 20, 2026 14:00
With query-cost enabled, the engine's deadline also covers waiting for a
concurrency slot while the query is built. A query that timed out or was
canceled there was reported as 400 bad_data `invalid parameter "query"`;
report it as a timeout or a cancellation instead.

Cap a `timeout` above the effective duration ceiling instead of rejecting
it, as before the feature. The rejection also fired against
--query.timeout when query_max_duration was unset, contrary to the docs.
The new max_* parameters keep rejecting values above their ceilings.
Reject a negative max_query_duration, which was silently ignored.

For cost=true, estimate after building the query and before executing
it. The estimation then counts against the query's duration limit, so
the request no longer takes up to twice that limit, a malformed query
fails before waiting for an estimation slot, and no finished result is
held in memory while the estimation waits for a slot.

Advertise the feature as `query_cost` in /api/v1/features, since the
per-query overrides are silently ignored when it is off. Document that
the limits apply to rule evaluation, that duration rejections are
usually timeouts, the max_query_duration ceiling and how remote read
degrades estimates. Test end to end that the configured limits apply
only with the feature enabled and follow a reload.

Signed-off-by: Arve Knudsen <[email protected]>
Fold TestQueryCostComparisonNonFatal into a table-driven
TestQueryCostComparisonGating that runs on both query endpoints. Fold
TestQueryCostOverrideParams into TestQueryCostEndpointParameterParity,
which covers all four endpoints, and TestQueryCostDisabledIgnoresCeilings.

Drop the flag-off "timeout above the ceiling is accepted" subtest: the
timeout parameter is capped regardless of the flag, so it no longer tests
anything specific to the feature being disabled.

Signed-off-by: Arve Knudsen <[email protected]>
@aknuds1
aknuds1 force-pushed the arve/roidelapluie/query-cost-api branch from 06df941 to 79c2445 Compare October 20, 2026 14:06
@aknuds1
aknuds1 marked this pull request as ready for review October 20, 2026 14:21
@aknuds1
aknuds1 requested a review from a team as a code owner October 20, 2026 14:21
@aknuds1
aknuds1 requested review from ArthurSens and roidelapluie and removed request for a team October 20, 2026 14:21
@roidelapluie
roidelapluie merged commit 07c0bd2 into prometheus:roidelapluie/query-cost-api Oct 20, 2026
32 of 33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants