-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Modify clean_removed handling #3827
Conversation
1c223e5
to
d774da1
Compare
@elastic/beats Would be good to hear your thoughts on this change. |
@@ -94,24 +94,35 @@ func (l *Log) Run() { | |||
if l.config.CleanRemoved { | |||
for _, state := range l.Prospector.states.GetStates() { | |||
// os.Stat will return an error in case the file does not exist | |||
_, err := os.Stat(state.Source) | |||
stat, err := os.Stat(state.Source) | |||
if err != nil { |
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.
Should we be more strict here and check vs os.PathError
?
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.
Good idea. What should we do in all other cases? Log an error and not remove the state?
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.
Yea that's probably the best we can do. os.PathError
is all that can return right now but you never now..
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.
changed
// Only clean up files where state is Finished | ||
if state.Finished { | ||
state.TTL = 0 | ||
err := l.Prospector.updateState(input.NewEvent(state)) |
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.
We could return here and check the error in the caller, and also remove the else
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 changed it to return directly if state is not finished but I kept the error handling local.
Previously if a file could be found under the same name as a state, the state was not removed. But this could have been also an other file. With this change also the file itself is compared and if it is not the same file, the state will be removed. This has the affect that in case a file is renamed after monitoring the file finished, the state will be removed. In most cases this should not have any side affect. The positive effect of this change is that there will be less left over states in the registry. Closes elastic#3789
d774da1
to
f8f540b
Compare
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.
review changes implemented and rebase on master
// Only clean up files where state is Finished | ||
if state.Finished { | ||
state.TTL = 0 | ||
err := l.Prospector.updateState(input.NewEvent(state)) |
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 changed it to return directly if state is not finished but I kept the error handling local.
@@ -94,24 +94,35 @@ func (l *Log) Run() { | |||
if l.config.CleanRemoved { | |||
for _, state := range l.Prospector.states.GetStates() { | |||
// os.Stat will return an error in case the file does not exist | |||
_, err := os.Stat(state.Source) | |||
stat, err := os.Stat(state.Source) | |||
if err != nil { |
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.
changed
Previously if a file could be found under the same name as a state, the state was not removed. But this could have been also an other file. With this change also the file itself is compared and if it is not the same file, the state will be removed. This has the affect that in case a file is renamed after monitoring the file finished, the state will be removed. In most cases this should not have any side affect.
The positive effect of this change is that there will be less left over states in the registry.
Closes elastic#3789