Skip to content

in_tail: drop redundant fstat() on event collection#11692

Open
edsiper wants to merge 1 commit intomasterfrom
openai-tail
Open

in_tail: drop redundant fstat() on event collection#11692
edsiper wants to merge 1 commit intomasterfrom
openai-tail

Conversation

@edsiper
Copy link
Copy Markdown
Member

@edsiper edsiper commented Apr 9, 2026

The event collection path in in_tail_collect_event() performed an early fstat() only to remove the file on failure, then immediately called flb_tail_file_chunk(), which already reaches adjust_counters() and does its own fstat()-based validation and counter update.

Removing the pre-check reduces one fstat() per event-driven collection cycle without changing truncation, rotation, deletion, or pending-byte handling. Those behaviors remain in the backend-specific handlers and in adjust_counters().

This change is intentionally narrow and is based on a conversation about Fluent Bit tail syscall cost with Fabian Ponce from OpenAI (@FabianPonce).


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.

Summary by CodeRabbit

  • Refactor
    • Optimized file collection event handling by removing redundant file operations and streamlining error handling logic.

The event collection path in in_tail_collect_event() performed an early
fstat() only to remove the file on failure, then immediately called
flb_tail_file_chunk(), which already reaches adjust_counters() and does
its own fstat()-based validation and counter update.

Removing the pre-check reduces one fstat() per event-driven collection
cycle without changing truncation, rotation, deletion, or pending-byte
handling. Those behaviors remain in the backend-specific handlers and in
adjust_counters().

This change is intentionally narrow and is based on a conversation about
Fluent Bit tail syscall cost with Fabian Ponce from OpenAI (@FabianPonce).

Verification:
- cmake -S . -B build -DFLB_TESTS_RUNTIME=On -DFLB_TESTS_INTERNAL=On
- cmake --build build -j8 --target flb-rt-in_tail
- ./build/bin/flb-rt-in_tail inotify_watcher_false
- ./build/bin/flb-rt-in_tail db

Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
@edsiper edsiper requested a review from cosmo0920 as a code owner April 9, 2026 19:17
@edsiper edsiper changed the title in_tail: drop redundant fstat on event collection in_tail: drop redundant fstat() on event collection Apr 9, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 9, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fec31583-c5eb-4842-8d2a-a97c4f988eff

📥 Commits

Reviewing files that changed from the base of the PR and between 40a6d4a and 58fce33.

📒 Files selected for processing (1)
  • plugins/in_tail/tail.c
💤 Files with no reviewable changes (1)
  • plugins/in_tail/tail.c

📝 Walkthrough

Walkthrough

The change removes an upfront fstat() validation check from in_tail_collect_event(), instead relying on flb_tail_file_chunk() to handle error conditions directly. The function now bypasses the early error path and delegates file descriptor validation to downstream processing.

Changes

Cohort / File(s) Summary
Event Collection Refactoring
plugins/in_tail/tail.c
Removed fstat() validation call and its associated -1 error handling path from in_tail_collect_event(). Error detection now depends on flb_tail_file_chunk() return values (FLB_TAIL_ERROR, FLB_TAIL_OK, FLB_TAIL_WAIT).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Suggested reviewers

  • koleini
  • fujimotos

Poem

🐰 No fstat check at the gate today,
Let the chunk handler show the way!
Streamlined paths where errors dwell,
Simpler logic, cleaner spell! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely describes the main change: removing a redundant fstat() call during event collection in the in_tail plugin.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch openai-tail

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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