Skip to content

feat: detect log rotation and reopen the rotated file - #13

Merged
dwego merged 3 commits into
devfrom
feat-logrotate
Jul 18, 2026
Merged

feat: detect log rotation and reopen the rotated file#13
dwego merged 3 commits into
devfrom
feat-logrotate

Conversation

@dwego

@dwego dwego commented Jul 18, 2026

Copy link
Copy Markdown
Owner

This pull request significantly improves the application's robustness in handling log rotation and adds comprehensive stress tests to ensure reliability under failure conditions. The main changes include enhancing the log source to detect and handle log file rotation (such as that performed by logrotate), updating documentation and acceptance criteria, and introducing new tests to verify these behaviors.

Log rotation handling and robustness:

  • The log source (src/source.rs) now detects when the log file has been rotated (renamed and replaced) by monitoring the file's inode. When a rotation is detected, it flushes any remaining lines from the old file and seamlessly switches to the new file, ensuring no logs are lost during rotation. [1] [2]
  • Improved comments and code structure clarify how the source handles downstream receiver shutdowns and log rotation events.

Testing improvements:

  • Added a new test (test_run_source_detects_log_rotation) to verify that the source correctly handles log rotation and continues processing new lines from the newly created file.
  • Introduced a new stress test (tests/stress_test.rs) that simulates a destination outage and verifies that no logs are lost, even under backpressure and repeated send failures. All logs are expected to be written to the dead-letter file.

Documentation and acceptance criteria:

  • Updated the README.md to clarify test organization, document the guarantees around log rotation and channel bounds, and note which acceptance criteria are now met or deferred.

These changes collectively make log processing more reliable in production scenarios, especially when dealing with log rotation and temporary sink outages.

dwego added 3 commits July 18, 2026 00:42
source now compares the inode at source_path against the one it has
open on every 200ms tick. On a mismatch (standard logrotate
rename-then-create behavior), it drains whatever was left in the old
file, reopens the new one from the start, and re-registers the
notify watcher — otherwise it stays bound to the old, now-orphaned
inode.

Doesn't yet handle copytruncate-style rotation (same inode, truncated
in place).
New tests/stress_test.rs — a separate category from the per-function
correctness tests elsewhere in this directory, meant for tests that
exercise the full pipeline under load/failure conditions rather than
one function in isolation.

Sends a burst of logs well beyond channel_capacity while the sink's
destination is unreachable for the whole test, and asserts the
dead-letter file ends up with exactly what was written — no loss, no
duplicates — after every batch exhausts its retries.
Checks off log rotation and the channel-boundedness criterion (the
latter proven by construction plus the new stress test rather than
direct memory measurement), and explicitly notes config validation
and metrics as deferred to v1.1 rather than leaving them as unexplained
open checkboxes. Also documents the tests/ layout now that
stress_test.rs exists as its own category.
@dwego
dwego merged commit 5842072 into dev Jul 18, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant