Repository navigation
loki: time out query_range requests so a hung one is retried - #4757
NoahSurprenant wants to merge 1 commit into
Conversation
The Loki client used http.DefaultClient, which has no timeout. A query_range request that Loki accepts but never answers (e.g. a query frontend losing a sub-query when a query-scheduler restarts) blocked the source forever: nothing logged, retry logic never reached. Add request_timeout (yaml and DSN; default 2m, above Loki's 1m query timeout). A timed out request logs a warning and goes through the existing shouldRetry/backoff path. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@NoahSurprenant: There are no 'kind' label on this PR. You need a 'kind' label to generate the release automatically.
DetailsI am a bot created to help the crowdsecurity developers manage community feedback and contributions. You can check out my manifest file to understand my behavior and what I can do. If you want to use this for your project, you can check out the BirthdayResearch/oss-governance-bot repository. |
|
@NoahSurprenant: There are no area labels on this PR. You can add as many areas as you see fit.
DetailsI am a bot created to help the crowdsecurity developers manage community feedback and contributions. You can check out my manifest file to understand my behavior and what I can do. If you want to use this for your project, you can check out the BirthdayResearch/oss-governance-bot repository. |
|
/area agent |
|
The Loki side is being fixed too (grafana/loki#25154 fixes the other end), but a client timeout is still needed: older Loki versions, a proxy in front of Loki, or a dropped connection can leave a request unanswered the same way. |
What and why
The Loki datasource's client used
http.DefaultClient, which has no timeout. Aquery_rangethat Loki accepts but never answers blocks that source forever: no error, no log, andmax_failure_durationnever applies. We hit this three times. Each time, a Loki rollout lost the request (grafana/loki#25153) and the traefik/unifi sources read nothing until the agent was restarted, once for 4.5 days.Adds
request_timeout(yaml and DSN) for the Loki client's HTTP requests, default 2m: above Loki's own 1m query timeout, so Loki gives up on a slow query first. A timed-out request logs a warning and is retried from the same position through the existingshouldRetrybackoff, so no lines are lost and it counts againstmax_failure_durationlike any other error: two failed polls in a row more thanmax_failure_duration(default 30s) apart make the source give up, as already happens when Loki is unreachable. A request that never returns now ends that way instead of hanging forever. The websocket tail dialer gets the same value as its handshake timeout.How it was tested
New tests in
pkg/acquisition/modules/loki/loki_test.go.TestRequestTimeoutRecoversserves aquery_rangethat hangs the first time and answers after that. It checks the source reads every line in tail and one-shot mode.TestRequestTimeoutConfigcovers the defaults, explicit and invalid values, and the DSN.The same test with the old
loki_client.goput back (from the parent commit) fails, so it catches the hang:golangci-lint (v2.13.0): 0 issues for linux, windows and freebsd.
Checklist
cscli -o json|rawoutput.AI assistance used: mostly
🤖 Generated with Claude Code