-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
in_tail may not send rotated logs when mv is used to rotate #3292
Comments
I'd sent a PR to fix the former "TailWatcher won't restart" issue: #3294 |
Thank you for the quick response! I'll answer the result of next log rotation tomorrow. |
@cosmo0920 #3294 fixed this problem. Thank you! |
Thanks for the confirmation, @aYukiSekiguchi ! |
I'd confirmed that the latter issue of |
Thank you for the quick fix! |
@cosmo0920 Will this PR also work for windows server? I'm trying to assess the impact on windows server. |
@hikkie3110 This problem occurs also on Windows. However only td-agent 4.1.0 (Fluentd 1.12.0, 1.12.1) has this problem. |
Describe the bug
After upgrading fluentd from 0.14.24 to 1.12.1, tail plugin + my script which rotates the watched log using
mv
sometimes won't watch the rotated log file and send the first part of rotated logs.To Reproduce
Watch
/tmp/script.log
mv
/tmp/script.log
to/tmp/script.log.20210314
and write to/tmp/script.log
Expected behavior
The content in
/tmp/script.log
should be sent.Your Environment
Your Configuration
Your Error Log
none (No rotate detection log)
Additional context
I'm trying to upgrade fluentd from 0.14.24 to 1.12.1 and faced two problems.
My script is called by cron every day. At the start of the script, it
mv
s log to rotate, do something great and dump logs to a new file.fluentd is watching the file name. My config is:
Here are problems I faced:
I debugged them using
mv
andcp
command.TailWatcher won't restart
When I run
mv
, the file of the filename becomes none. Then,TailWatcher#@rotate_handler
becomesnil
. This stops to watch the inode.https://github.com/fluent/fluentd/blob/v1.12.1/lib/fluent/plugin/in_tail.rb#L763
The comment says "moving to inodes will create new watcher, and old watcher will be closed by stop_watcher in refresh_watchers method". However, this only happens if
refresh_watchers()
runs when there is no file in the path andrefresh_watchers()
runs later when a file is created in the path. If a file ismv
ed and a new file is created betweenrefresh_watchers()
s,refresh_watchers()
won't runstart_watchers()
andstop_watchers()
for the path becausetarget_paths_hash
always contains the path.TailWatcher may not send the first part of rotated logs
refresh_watchers()
will create a newTailWatcher
if a new file is created.refresh_watchers()
runs everyrefresh_interval
seconds, 60 seconds as default.The problem is when a new file is created and logs are written to the file during
refresh_interval
, the newTimeWatcher
won't send the written logs because it watch the tail of the new file which contains the written logs.read_from_head true
fixes this problem, but I'm not sure whether this is intentional fix in #3182. Even if it is intentional, it would be better to write a document about this behaviour.Why fluentd 0.14.24 worked?
fluentd 0.14.24 creates a new
TailWatcher
soon even if a new file doesn't exist:https://github.com/fluent/fluentd/blob/v0.14.24/lib/fluent/plugin/in_tail.rb#L584
It looks like this is the reason why old fluentd detected the rotation but new fluentd doesn't.
Adding
FileUtils.touch(FILE_NAME)
to my script sometimes fixes these problems. However, sincemv
andtouch
aren't atomic, StatWatcher can detect the timing that there is no file for the filename, IIUC. Even ifenable_stat_watcher
isfalse
, there is rare timingTimerTrigger
callson_notify
when there is no file for a file name.The text was updated successfully, but these errors were encountered: