fluentd: Fluentd in_tail "unreadable" file causes "following tail of " to stop and no logs pushed
Describe the bug
After a warning of an “unreadable” (likely due to rotation), no more logs were pushed (in_tail + pos_file). Reloading config or restarting fluentd sorts the issue. All other existing files being tracked continued to work as expected.
To Reproduce
Not able to reproduce at will.
Expected behavior
Logs to be pushed as usual after file rotation as fluentd recovers from the temporary “unreadable” file.
Your Environment
- Fluentd version: 1.14.4
- TD Agent version: 4.2.0
- Operating system: Ubuntu 20.04.3 LTS
- Kernel version: 5.11.0-1022-aws
Your Configuration
<source>
@type tail
path /var/log/containers/*.log
pos_file /var/log/es-containers.log.pos
tag kubernetes.*
<parse>
@type regexp
expression /^(?<time>[^ ]+) (?<stream>[^ ]+) (?<logtag>[^ ]+) (?<log>.+)$/
time_key time
time_format %Y-%m-%dT%H:%M:%S.%N%z
</parse>
read_from_head true
</source>
Your Error Log
Relevant log entries with some context. When "detected rotation of ..." isn't followed by a "following tail of ..." then log file contents aren't being processed/pushed:
2022-02-01 01:26:33 +0000 [info]: #0 detected rotation of /var/log/containers/gateway-mtcw6_atom_pcms-gateway-e54ea9ee115f1127682b0d92e37404e4b1693c14edeea93e485f70b3110eecfc.log; waiting 5 seconds
2022-02-01 01:26:33 +0000 [info]: #0 following tail of /var/log/containers/gateway-mtcw6_atom_pcms-gateway-e54ea9ee115f1127682b0d92e37404e4b1693c14edeea93e485f70b3110eecfc.log
2022-02-01 01:32:53 +0000 [warn]: #0 /var/log/containers/gateway-mtcw6_atom_pcms-gateway-e54ea9ee115f1127682b0d92e37404e4b1693c14edeea93e485f70b3110eecfc.log unreadable. It is excluded and would be examined next time.
2022-02-01 01:32:54 +0000 [info]: #0 detected rotation of /var/log/containers/gateway-mtcw6_atom_pcms-gateway-e54ea9ee115f1127682b0d92e37404e4b1693c14edeea93e485f70b3110eecfc.log; waiting 5 seconds
2022-02-01 01:32:54 +0000 [info]: #0 following tail of /var/log/containers/gateway-mtcw6_atom_pcms-gateway-e54ea9ee115f1127682b0d92e37404e4b1693c14edeea93e485f70b3110eecfc.log
2022-02-01 01:38:04 +0000 [info]: #0 detected rotation of /var/log/containers/gateway-mtcw6_atom_pcms-gateway-e54ea9ee115f1127682b0d92e37404e4b1693c14edeea93e485f70b3110eecfc.log; waiting 5 seconds
2022-02-01 01:44:44 +0000 [info]: #0 detected rotation of /var/log/containers/gateway-mtcw6_atom_pcms-gateway-e54ea9ee115f1127682b0d92e37404e4b1693c14edeea93e485f70b3110eecfc.log; waiting 5 seconds
2022-02-01 01:53:15 +0000 [info]: #0 detected rotation of /var/log/containers/gateway-mtcw6_atom_pcms-gateway-e54ea9ee115f1127682b0d92e37404e4b1693c14edeea93e485f70b3110eecfc.log; waiting 5 seconds
[...]
---- after issuing a config reload (kill -SIGUSR2 <pid>) it starts to work fine again, i.e. "following tail of ..."
2022-02-01 11:36:19 +0000 [info]: Reloading new config
2022-02-01 11:36:19 +0000 [info]: using configuration file: <ROOT>
[...]
2022-02-01 11:36:19 +0000 [info]: shutting down input plugin type=:tail plugin_id="object:c6c0"
[...]
2022-02-01 11:36:19 +0000 [info]: adding source type="tail"
2022-02-01 11:36:19 +0000 [info]: #0 shutting down fluentd worker worker=0
2022-02-01 11:36:19 +0000 [info]: #0 shutting down input plugin type=:tail plugin_id="object:c6c0"
[...]
2022-02-01 11:36:20 +0000 [info]: #0 restart fluentd worker worker=0
---- the entry below seems to be related with the actual underlying issue... the ruby object which stopped pushing logs has now been terminated as a new one was created
2022-02-01 11:36:20 +0000 [warn]: #0 /var/log/containers/gateway-mtcw6_atom_pcms-gateway-e54ea9ee115f1127682b0d92e37404e4b1693c14edeea93e485f70b3110eecfc.log already exists. use latest one: deleted #<struct Fluent::Plugin::TailInput::Entry path="/var/log/containers/gateway-mtcw6_atom_pcms-gateway-e54ea9ee115f1127682b0d92e37404e4b1693c14edeea93e485f70b3110eecfc.log", pos=10740032, ino=1797715, seek=1530>
2022-02-01 11:36:20 +0000 [info]: #0 following tail of /var/log/containers/gateway-mtcw6_atom_pcms-gateway-e54ea9ee115f1127682b0d92e37404e4b1693c14edeea93e485f70b3110eecfc.log
2022-02-01 11:37:30 +0000 [info]: #0 detected rotation of /var/log/containers/gateway-mtcw6_atom_pcms-gateway-e54ea9ee115f1127682b0d92e37404e4b1693c14edeea93e485f70b3110eecfc.log; waiting 5 seconds
2022-02-01 11:37:30 +0000 [info]: #0 following tail of /var/log/containers/gateway-mtcw6_atom_pcms-gateway-e54ea9ee115f1127682b0d92e37404e4b1693c14edeea93e485f70b3110eecfc.log
2022-02-01 11:43:20 +0000 [info]: #0 detected rotation of /var/log/containers/gateway-mtcw6_atom_pcms-gateway-e54ea9ee115f1127682b0d92e37404e4b1693c14edeea93e485f70b3110eecfc.log; waiting 5 seconds
2022-02-01 11:43:20 +0000 [info]: #0 following tail of /var/log/containers/gateway-mtcw6_atom_pcms-gateway-e54ea9ee115f1127682b0d92e37404e4b1693c14edeea93e485f70b3110eecfc.log
Additional context
This issue seems be related with #3586 but unfortunately I didn’t check the pos
file while the issue was happening so can’t tell if it presented unexpected values for the failing file.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 4
- Comments: 73 (40 by maintainers)
Commits related to this issue
- in_tail: Show more information on skipping update_watcher In #3614 some users reported that in_tail rarely stops tailing. It seems it's caused when skipping update_watcher due to unexpected duplicate... — committed to fluent/fluentd by ashie 2 years ago
- in_tail: Fix for unexpected file close after logs rotate in update_watcher and stop_watcher The filesystem reuse of inodes and fluent using inode as the "key" for maintaining watches. However some 'w... — committed to kattz-kawa/fluentd by kattz-kawa a year ago
- in_tail: Fix for unexpected file close after logs rotate in update_watcher and stop_watcher The filesystem reuse of inodes and fluent using inode as the "key" for maintaining watches. However some 'w... — committed to kattz-kawa/fluentd by kattz-kawa a year ago
- in_tail: Fix for unexpected file close after logs rotate in update_watcher and stop_watcher Some 'watcher' method is using 'path' as the key in fluentd v1.16.1. It is strange to manage with path in f... — committed to kattz-kawa/fluentd by kattz-kawa a year ago
- test: in_tail: Add tests for rotation with follow_inodes Many problems related to rotation have been reported. These tests are to reproduce the problems with follow_inodes, especially talked in #3614... — committed to daipom/fluentd by daipom a year ago
- in_tail: Ensure to detach correct watcher on rotation with follow_inodes If `refresh_watchers` run before `update_watcher`, the old implementation of `update_watcher` detach wrongly the new TailWatch... — committed to daipom/fluentd by daipom a year ago
- in_tail: Ensure to detach correct watcher on rotation with follow_inodes If `refresh_watchers` run before `update_watcher`, the old implementation of `update_watcher` detach wrongly the new TailWatch... — committed to daipom/fluentd by daipom a year ago
- in_tail: Ensure to detach correct watcher on rotation with follow_inodes If `refresh_watchers` run before `update_watcher`, the old implementation of `update_watcher` detach wrongly the new TailWatch... — committed to daipom/fluentd by daipom a year ago
- in_tail: Fix a stall bug on !follow_inode case Fix #3614 Although known stall issues of in_tail on `follow_inode` case are fixed in v1.16.2, it has still a similar problem on `!follow_inode` case. ... — committed to fluent/fluentd by ashie 8 months ago
- in_tail: Fix a stall bug on !follow_inode case Fix #3614 Although known stall issues of in_tail on `follow_inode` case are fixed in v1.16.2, it has still a similar problem on `!follow_inode` case. ... — committed to fluent/fluentd by ashie 8 months ago
- in_tail: Fix a stall bug on !follow_inode case Fix #3614 Although known stall issues of in_tail on `follow_inode` case are fixed in v1.16.2, it has still a similar problem on `!follow_inode` case. ... — committed to fluent/fluentd by ashie 8 months ago
- in_tail: Fix a stall bug on !follow_inode case (#4327) Fix #3614 Although known stall issues of in_tail on `follow_inode` case are fixed in v1.16.2, it has still a similar problem on `!follow_ino... — committed to fluent/fluentd by ashie 8 months ago
- in_tail: Fix a stall bug on !follow_inode case (#4327) Fix #3614 Although known stall issues of in_tail on `follow_inode` case are fixed in v1.16.2, it has still a similar problem on `!follow_ino... — committed to daipom/fluentd by ashie 8 months ago
Thanks for your report!
To tell the truth, I was suspecting it but I couldn’t confirm it because I can’t yet reproduce it. Your report it very helpful for me.
Although I’m not yet sure the mechanism of this issue, you might be able to avoid this issue by disabling stat watcher (
enable_stat_watcher false
).Sorry, “We will check https://github.com/fluent/fluentd/pull/4185” was a typo ^^; I will check #4208!
I created a test case in
test/plugin/test_in_tail.rb
for just playing around with this exact event:In this case, it seems to be working properly. But maybe we can help each-other in reproducing the error?
UPDATE: Changed to multiple files of different sizes, and changed log rotation to how
kubelet
actually does it. UPDATE 2: Code updated! Now it seems I’ve got something that somehow reproduces the error, in this very state the tests works fine. But if you comment out the"follow_inodes" => "true",
line, the error comes up and the log lineSkip update_watcher because watcher has been....
mentioned by @ashie above, is logged all the time. So I think that thefollow_inodes
option is not only important for preventing duplicate log messages, but also for tail on wildcards, and symlinks to work properly!@vparfonov Could you provide your in_tail config? Do you use
follow_inode true
?We downgraded td-agent 4.3.0 (fluentd v1.14.3) to td-agent 4.2.0 (fluentd v1.13.3), and still have problems. We broadened monitoring targets to 500 servers (approx 1500 files) from 200 servers (approx 400 files) as a result of this issue. Then, we found the 2 servers (2 files) having this issue after a week from td-agent downgraded. Upgrading fluentd 1.13.3 -> 1.14.3 does not seem to be the cause, sorry.
It seemed that some of our log files were affected and some were not. The differences are as follows.
We are planning to change rotation policy and retry upgrading td-agent. And, we will comment some updates if we get.
We have encountered the same problem twice. Last month we upgraded fluentd from 1.13.3 (td-agent 4.2.0) to 1.14.3 (td-agent 4.3.0), and then we have got the problem.
In our case, we are tracking more than 3 log files with the tail plugin, and only the file with the highest log flow has this problem. From the metrics produced by prometheus plugin, the file position always fluctuates by at least 400000/sec and the rotation happens at least once every 10 minutes.
The input source is set as follows:
I will also share the record of the investigation when the problem occurs. First, fluentd suddenly, without warning, stops tracking new rotated files and only logs the following in the stdout log.
Normally, it would have been followed by an announcement that a new file was being tracked, as follows
However, we have not seen this announcement at all after the problem occurs. Also, when I view the file descriptors that fluentd is tracking, I see the following:
This is the rotated file, and we see that fluentd is still tracking the old file, not the new one. Also, looking at the position file, we see the following:
As far as the situation is concerned, it seems that something triggers fluentd to stop tracking new files altogether during rotate. We have about 300 servers running 24/7 and have only had two problems in the past month, so it seems to be pretty rare for problems to occur. However, since we haven’t had any problems with fluentd 1.13.3 for 6 months, it seems likely that there was some kind of regression in fluentd 1.13.3 -> 1.14.3.
We are planning to downgrade fluentd.
The mechanism of #4190 doesn’t depend on
follow_inode
, so it definitely affects tofollow_inode false
case too and #4208 should fixes it. I believe #4190 is the root cause of this issue.I’ll close this issue after we check it.
@masaki-hatada
I would appreciate it if you could check #4208 too. I want to merge one of #4208 and #4185. (I will review #4191 later) Both would improve this problem. I think #4208 would be a more direct solution, but I want to hear opinions.
I can create #4208 thanks to #4185 and #4191! Until these PRs were created, I had no idea what was causing this problem. Thank you all for your contributions!
Reply to @kattz-kawa and @k-keiichi-rh
Ideally, when follow_inode is on, all things should be tracked by inode, instead of partial by inode, partial by path. So, I vote for your PR (I actually want to do a similar PR 😃 )
In recent days, I’m heavily testing your PR. It runs good with a high log throughput and high log file rotation rate (running in k8s , log rotation pattern : old log file will be renamed and new log file will be created with same name) My testing env is 20K rows / sec, 2KB / row, ~10 sec log rotation interval. No log dup, no log missing.
On the other hand, certainly I also think that it is strange to manage with path in
follow_inode true
case. In addition, probably the case we experienced before is mixed other conditions. I’m digging out it.This is my proposed patch for the customer.
@jcantrill Thank you for validating this patch.
@ashie
This issue is observed by Jeff’s primitive test code. Additionally this issue also is observed on the popular enviroment like as using ‘logrotate’ program. (such as k8s)
I attach the simple reproducer program using ‘logrotate’.
the reproducible way is below:
I will try to create a pull request on this issue later. Could you review it? I hope this attached program is helpful to you to validate my patch. reproducer.tar.gz
@jcantrill Thanks for your information! We’ll check it.
@ashie I believe the issue is because the filesystem reuse of inodes and fluent using inode as the “key” for maintaining watches. Our customer provided the following where then position entry is converted to decimal:
Note there are multiple entries with the same inode where one is identified as “unwatched” and the other is still open. The logic then closes the watch on the inode even though it is still in use
@ashie we have a customer who claims they applied the following patch and the issue goes away. I do not have a reliable way to reproduce the problem. We are using v1.14.6
our typical config is:
One significant difference I do see with the original report of the issue and how we collect logs is the symlink. Collecting from
/var/log/pods
which is the preferred kubernetes location AFAIK does not utilize symlinks as was done with/var/log/containers
.For what’s worth: after adding
enable_stat_watcher false
back in March (as mentioned by @ashie here) none of my 120+ servers experienced this issue again.