in_tail: fix stream_offset not set when position restored from database#11674
in_tail: fix stream_offset not set when position restored from database#11674gkarpeev wants to merge 1 commit intofluent:masterfrom
Conversation
📝 WalkthroughWalkthroughFixed the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
plugins/in_tail/tail_file.c (1)
1061-1064: Consider adding a regression test for restart + DB +offset_key.The fix is correct; adding automated coverage for this path would help prevent regressions.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@plugins/in_tail/tail_file.c` around lines 1061 - 1064, Add a regression test that reproduces the restart + DB + offset_key codepath where decompression_context is NULL so stream_offset is set from offset; specifically, create a test that writes compressed and uncompressed input, configures the tail plugin with db enabled and a specific offset_key, perform a restart (stop/start) and assert that after restart the tracked file state (using file->offset and file->stream_offset behavior) resumes correctly (no data duplication or loss). Target the tail plugin integration tests that exercise offset persistence and reference the symbols offset_key, decompression_context, stream_offset and offset to ensure the case where decompression_context == NULL is covered and guarded against regressions.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@plugins/in_tail/tail_file.c`:
- Around line 1061-1064: Add a regression test that reproduces the restart + DB
+ offset_key codepath where decompression_context is NULL so stream_offset is
set from offset; specifically, create a test that writes compressed and
uncompressed input, configures the tail plugin with db enabled and a specific
offset_key, perform a restart (stop/start) and assert that after restart the
tracked file state (using file->offset and file->stream_offset behavior) resumes
correctly (no data duplication or loss). Target the tail plugin integration
tests that exercise offset persistence and reference the symbols offset_key,
decompression_context, stream_offset and offset to ensure the case where
decompression_context == NULL is covered and guarded against regressions.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: ab131576-7851-4bf4-ab8d-093e09ec14a9
📒 Files selected for processing (1)
plugins/in_tail/tail_file.c
Fixes fluent#11670 Signed-off-by: Gleb Karpeev <gkarpeev@amdocs.ru>
in_tail: fix offset_key reporting relative offset after DB position restore
Fixes #11670
Summary
When
offset_keyis configured and the file position is restored from the SQLite database (after restart),stream_offsetis not set from the DB value. It stays at 0, causingoffset_keyto report relative offsets instead of absolute byte positions.The fix sets
stream_offset = file->offsetin the DB branch ofset_file_position(), guarded by thedecompression_context == NULLcheck to match the existing pattern at the end of the function (compressed files track stream offset differently).Testing
Configuration:
Steps:
DB state confirming correct offset tracking:
Before fix -- offsets start from 0 instead of 9,840,308 after restart:
{"file_path":"/mnt/input/test.log","file_offset":0,"log":"..."} {"file_path":"/mnt/input/test.log","file_offset":143,"log":"..."}After fix -- offsets match the DB position:
{"file_path":"/mnt/input/test.log","file_offset":9840308,"log":"..."} {"file_path":"/mnt/input/test.log","file_offset":9840451,"log":"..."}Documentation
No documentation changes needed.
offset_keyalready documents that it reports the file byte offset; this fix makes the behavior match the documentation.Backporting
This bug has been present since
stream_offsetwas introduced in v3.0.0 (before that, v1.7-v2.x usedfile->offsetdirectly, which worked correctly). It affects all versions >= v3.0.0 withoffset_key+db. Confirmed on v3.0.0, v4.2.0, v5.0.0, v5.0.1. Backport to stable branches is recommended.Summary by CodeRabbit
Bug Fixes