Skip to content

in_tail: only rely on fstat() to detect file rotation#10405

Merged
edsiper merged 1 commit intofluent:masterfrom
david-garcia-garcia:10276
Jul 8, 2025
Merged

in_tail: only rely on fstat() to detect file rotation#10405
edsiper merged 1 commit intofluent:masterfrom
david-garcia-garcia:10276

Conversation

@david-garcia-garcia
Copy link
Copy Markdown
Contributor

@david-garcia-garcia david-garcia-garcia commented May 30, 2025

When reading logs from NFS the results obtained by calling fstat() might be outdated. This leads to looped ingest as the plugin detects truncation over and over again when the file has not been truncated because it compares the current stream offset with the file size reported in the metadata (which is stale).

This PR solves this by relying exclusively on the information provided by fstat() to decide wether or not to rotate, where before it used offset and fstat()->file_size (offset could be larger the the file_size reported by fstat as fstat comes from cache and takes some time to update).

Fixes #10276

Enter [N/A] in the box, if an item is not applicable to your change.

Testing
Before we can approve your change; please submit the following in a comment:

  • Example configuration file for the change
  • Debug log output from testing the change
  • Attached Valgrind output that shows no leaks or memory corruption was found

If this is a change to packaging of containers or native binaries then please confirm it works for all targets.

  • Run local packaging test showing all targets (including any new ones) build.
  • Set ok-package-test label to test for all targets (requires maintainer to do).

Documentation

  • Documentation required for this feature

Backporting

  • Backport to latest stable release.

Fluent Bit is licensed under Apache 2.0, by submitting this pull request I understand that this code will be released under the terms of that license.

---------
Signed-off-by: deivid.garcia.garcia@gmail.com <deivid.garcia.garcia@gmail.com>
@david-garcia-garcia
Copy link
Copy Markdown
Contributor Author

Example configuration file

[SERVICE]
    Flush                     6
    Log_Level                 debug
    Parsers_File              parsers.conf
    log_file                  /dev/stdout  

[INPUT]
    Name             tail
    DB               /data/flb_logs.db
    DB.locking       true
    Path             /processlogs/aks-dev/traefik/traefikapp/access.log
    Parser           json_traefik
    Tag              logs.traefik
    Refresh_Interval 120
    Mem_Buf_Limit    16MB
    Skip_Long_Lines  On
    Inotify_Watcher  false
    Read_from_Head   false
    Buffer_Max_Size  64k
    Offset_Key       offset
    Path_Key         path
    read_newly_discovered_files_from_head false

[FILTER]
    Name modify
    Match *
    Set cluster_name ${NEW_RELIC_METADATA_KUBERNETES_CLUSTER_NAME}

[OUTPUT]
    Name            newrelic
    Match           *
    Alias           newrelic-logs-forwarder
    licenseKey      ${LICENSE_KEY}
    endpoint        ${ENDPOINT}
    SendMetrics     ${SEND_METRICS}

Debug logs file truncation

[2025/05/03 05:20:57] [debug] [input:tail:tail.1] adjust_counters: inode=9223444303974498304 file truncated /processlogs/aks-dev/traefik/traefikapp/access.log (diff: -881916 bytes)                                                                                                 

@edsiper edsiper added this to the Fluent Bit v4.0.4 milestone Jul 8, 2025
@edsiper edsiper merged commit 548b99b into fluent:master Jul 8, 2025
2 checks passed
@edsiper
Copy link
Copy Markdown
Member

edsiper commented Jul 8, 2025

reviewed, all looks good, thanks!

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.

Tail Input Incorrectly Detects rotation in NFS with Metadata Cache

2 participants