Skip to content

loki: prevent duplicate log ingestion and improve timestamp handling#4498

Open
Anulo2 wants to merge 2 commits into
crowdsecurity:masterfrom
Anulo2:fix/loki-duplicate-ingestion
Open

loki: prevent duplicate log ingestion and improve timestamp handling#4498
Anulo2 wants to merge 2 commits into
crowdsecurity:masterfrom
Anulo2:fix/loki-duplicate-ingestion

Conversation

@Anulo2

@Anulo2 Anulo2 commented Jun 3, 2026

Copy link
Copy Markdown
  • Scan all streams for maxTS instead of only the first stream's last entry
  • Use strconv.ParseInt/FormatInt for nanosecond timestamps to avoid 32-bit Atoi overflow on platforms where int is 32-bit
  • Align entry.go timestamp parsing with types.go (time.Unix(0, t))

Fixes duplicate log lines appearing 2-3x in CrowdSec alerts when using Loki datasource in streaming mode.

…ling

Remove the 'else if infinite' branch in updateURI() that reset the query
start timestamp backward by 1 minute when no new results were returned.
This caused the same Loki log entries to be re-fetched and ingested
multiple times, inflating event counts and triggering false bucket
overflows.

Also improve robustness:
- Scan all streams for maxTS instead of only the first stream's last entry
- Use strconv.ParseInt/FormatInt for nanosecond timestamps to avoid 32-bit
  Atoi overflow on platforms where int is 32-bit
- Align entry.go timestamp parsing with types.go (time.Unix(0, t))

Fixes duplicate log lines appearing 2-3x in CrowdSec alerts when using
Loki datasource in streaming mode.
@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown

@Anulo2: 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

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown

@Anulo2: 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.

@Anulo2

Anulo2 commented Jun 3, 2026

Copy link
Copy Markdown
Author

/kind fix

@Anulo2

Anulo2 commented Jun 3, 2026

Copy link
Copy Markdown
Author

/area agent

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.

2 participants