Per-request timeout clamped to server-side --query.timeout limit
0 reputation · 12 Sept 2020, 09:48 UTC
0 reputation · 12 Sept 2020, 09:48 UTC
Prometheus accepts a timeout query parameter on /api/v1/query and /api/v1/query_range, but the value can only shorten evaluation; it is silently capped at the server‑side --query.timeout flag (default 2 m). This behavior bounds memory and CPU yet surprises clients that expect to extend the limit for long‑range or high‑cardinality queries.
Cancellation relies on the HTTP request context: when the client disconnects the engine should stop, yet the server‑side timeout still governs the worst‑case duration. The exact point at which memory, CPU, and the concurrency slot are released varies across releases and interacts with --query.max-concurrency and --query.max-samples.
What is the precise clamping rule for the timeout parameter in the current release? Does a client disconnect reliably free the concurrency slot before the server timeout fires? How should --query.max-concurrency and --query.max-samples be tuned together with the timeout to avoid slot exhaustion?
37275 reputation · 12 Sept 2020, 11:00 UTC
The effective timeout for /api/v1/query and /api/v1/query_range is the minimum of the client-specified timeout query parameter and the server's --query.timeout flag (default 2 minutes). If a client passes timeout=300s but the server runs with --query.timeout=120s, the query will be terminated after 120 seconds. The cap is applied silently; Prometheus logs the actual timeout value used at level=info when the query starts.
When a client disconnects, Prometheus should cancel the HTTP request context and interrupt query evaluation. In practice, the concurrency slot is released as soon as the query engine detects context cancellation. However, if the engine reaches a non-interruptible phase (e.g., deep storage reads), it may continue until the server-side timeout fires. Monitoring query_running and query_execution_duration_seconds can confirm whether slots are freed promptly.
min(cores, available_memory_gb / 0.5), assuming each query uses ~500 MB at peak.prometheus_tsdb_head_chunks and go_goroutines metrics to detect slot pressure or memory growth.--query.timeout=30s and --query.max-concurrency=5.timeout=60s; confirm termination at 30 seconds via response timing or logs.query_running drops by one immediately, not after 30 seconds.Requires current verification: The exact behavior around slot release timing may vary between Prometheus versions 2.40–2.50. If you observe delays in slot freeing after client disconnect, consider upgrading to the latest stable release.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.