-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
fix(inputs.tail): Retry opening file after permission denied #14357
fix(inputs.tail): Retry opening file after permission denied #14357
Conversation
Thanks so much for the pull request! |
!signed-cla |
7e9224b
to
ed70d7e
Compare
ed70d7e
to
4b867c5
Compare
Out of a concern the offsets would be affected and cause the wrong behavior, I did a further test:
|
What happens in the scenario the file becomes inaccessible, then few lines added, then accessible again? |
If the tail plugin has my log open, changing the permissions on the already-open file to something that would cause a problem for telegraf opening it later does not affect telegraf immediately. It already has the file open, and reads new lines written to the file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR @ericmiller-wpengine! One question and one suggestion from my side...
plugins/inputs/tail/tail.go
Outdated
@@ -236,6 +236,10 @@ func (t *Tail) tailNewFiles(fromBeginning bool) error { | |||
|
|||
if err := tailer.Err(); err != nil { | |||
t.Log.Errorf("Tailing %q: %s", tailer.Filename, err.Error()) | |||
if strings.HasSuffix(err.Error(), "permission denied") { | |||
t.Log.Errorf("Deleting tailer for %q", tailer.Filename) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about adding some details like
t.Log.Errorf("Deleting tailer for %q", tailer.Filename) | |
t.Log.Errorf("Deleting tailer for %q: %v", tailer.Filename, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved the previous log message into an else at the same time, hopefully this is adequately idiomatic.
Now that I pushed again, there is a failed check but the failure looks like its in linting a README I did not touch. I looked but don't see somewhere I can trigger it again without another push. Also some more checks failed after that, also in unrelated-looking ways. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for tackling this issue @ericmiller-wpengine! Very much appreciated!
@ericmiller-wpengine yeah something went wrong for multiple PRs today. Just merge latest master branch and it should be fine. |
Download PR build artifacts for linux_amd64.tar.gz, darwin_amd64.tar.gz, and windows_amd64.zip. 📦 Click here to get additional PR build artifactsArtifact URLs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for coming up with this!
Required for all PRs
resolves #13154
Gather() calls tailNewFiles() and creates a tailer for any that are not in the map of tailers already. Deleting the old one from the map on "permission denied" was sufficient to get the plugin to reopen the file.
a lightly redacted section of logs. in another terminal i forced a logrotate that left the log file with the wrong permissions (0600) and then immediately chmod'ed to 0644, easier to catch than the race condition.