Skip to content

loki: avoid skipping delayed logs and entries at page boundaries - #4835

Open
francescogionghi wants to merge 1 commit into
crowdsecurity:masterfrom
francescogionghi:fix/loki-streaming-tail
Open

francescogionghi wants to merge 1 commit into
crowdsecurity:masterfrom
francescogionghi:fix/loki-streaming-tail

Conversation

@francescogionghi

@francescogionghi francescogionghi commented Nov 17, 2026 •

Copy link
Copy Markdown

Loki can skip late logs and entries at page boundaries. Windowing and deduplication must change together to avoid gaps and duplicates; one paginator now serves streaming and replay.

What and why

  • Drain each window before advancing, preserving entries that share a timestamp and identical legitimate records.
  • Streaming reads settled windows with query_delay: 5s and poll_interval: 1s by default. This adds detection latency; replay keeps a fixed end and does not wait between pages.
  • query_delay applies to query_range; the existing delay_for remains a separate WebSocket-tail option.
  • Retry the same page with the existing backoff, capped at 10s. Clean shutdown keeps the reader's original error through the shared tomb.

Logs arriving later than query_delay can still be missed. If Loki rejects a larger page needed for timestamp ties, the reader reports the failure instead of skipping those records.

Related: #4498, #4501, #3690; #4757 discusses request timeouts.

How it was tested

  • Virtual-clock tests cover late streams, both acquisition modes, full pages across streams, identical records and exclusive window ends.
  • Tests cover HTTP/JSON failures, unchanged retry cursors, exponential backoff/reset, server page-limit rejection and shutdown/error propagation.
  • New replay and backoff tests fail on the previous PR commit: replay reads 1,000/1,505 records; retry waits 1s instead of increasing. They pass with this change.
  • TEST_LOCAL_ONLY=1 go test -buildvcs=false -race ./pkg/acquisition/modules/loki/... -count=1 -timeout=90s: passed on master and a v1.8.1 backport. Container-dependent integration tests excluded.
  • make lint: passed on Linux, Windows and FreeBSD with golangci-lint 2.13.0.
ok  github.com/crowdsecurity/crowdsec/pkg/acquisition/modules/loki 1.047s
ok  github.com/crowdsecurity/crowdsec/pkg/acquisition/modules/loki/internal/lokiclient 2.111s

Checklist

  • One concern only.
  • No break to LAPI/CAPI payloads, database schema, config keys, or cscli -o json|raw output.
  • A human has reviewed this diff line by line.
  • A human has tested this change, not only an agent.

AI assistance used: mostly.

@github-actions

Copy link
Copy Markdown

@francescogionghi: There are no 'kind' label on this PR. You need a 'kind' label to generate the release automatically.

  • /kind feature
  • /kind enhancement
  • /kind refactoring
  • /kind fix
  • /kind chore
  • /kind dependencies
Details

I 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.

@github-actions

Copy link
Copy Markdown

@francescogionghi: There are no area labels on this PR. You can add as many areas as you see fit.

  • /area agent
  • /area local-api
  • /area cscli
  • /area appsec
  • /area security
  • /area configuration
Details

I 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.

@francescogionghi

Copy link
Copy Markdown
Author

/kind fix
/area agent

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant