-
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
Filebeat only checks for closed or renamed files when reaching EOF #5556
Comments
If you have a look at Perhaps you can share some more background on the issue you see and what you worried about? Please also open an issue for that on discuss so we can move to Github in case we can confirm it's a bug or a feature request. Closing this, happy to follow further on discuss. |
@ruflin
err == nil function returned , but if filename changed it can't know! |
Knowing about the renaming of files is "best effort". File are harvester by file handler and not based on the file name. So if a file name changes it's not required for filebeat to know about it immidiately as the file handler stays the same. Can you share some more on your use case and where the above is a problem? |
@ruflin |
If you want to stop reading the file when it's removed / renamed, you should use |
I did this, but I found it execute in errorChecks if a file is so big that not read the end ! how can I give up it? |
The error check is done for each line it reads, so as soon as the next line is read, it should detect the change. Perhaps I miss something here? |
I'm sorry. If a file is very very large and filebeat is reading it at the same moment. If suddenly the file name was changed or the file was deleted at that time, For example, when the code run at |
@ZhiqinYang Thanks a lot for bearing with me on this one. I know finally understand what you are getting at. In case of a successful read, it's never checked if the file was renamed or closed only at the end of the file. TBH I don't think it's intentional that we have it this way and it is not the expected behaviour. On interesting property of having it the way it is, is that I'm reopening this as an issue and will change the title to be more fitting. |
@ruflin Thank you! |
@ZhiqinYang Have u resolved it? I also encountered a file removed, but the file handler is always opened. close_removed and clean_removed are true. |
@GaryHuangBD There is no fix for this yet as it requires quite a bit of change in the logic that close_* options work. I assume in your case you also have a very large file? |
@ruflin Actually, I have dozens of files to collect at the same time,and the size of each file is about ten Gb. I have to tell u a strange thing, filebeat.harvester.open_files is correct, but lsof shows that filebeat opens a lot of deleted files.
lsof always shows:
One day later, it still like this, so i have to kill filebeat. Do you have any suggestions to avoid this problem? |
@GaryHuangBD I think your best temporary fix here is to use |
i did like follow, i don't think it's a good way ! `
} func (f *Log) Read(buf []byte) (int, error) {
... ` |
@ZhiqinYang The long term fix I have in mind is to change the way the close_* options are checked. Instead of checking them only on each iteration, there is also an external go routine running which checks from time to time if one of the close options is met and closes the handler. Very similar to what we do with |
@ruflin It's the same as I thought. I add another goroutine to check close_* options periodically, and it looks normal now. |
@GaryHuangBD Would be great if you could share your code. Depending on the change you did, make sure to use Go 1.9 as there was a change in Go 1.9 with the closing file handlers which lead to races before but now should work. |
@ruflin Yeah~ i think i can do it after the Spring Festival, if it's still needed. |
Thanks, would be great. |
@ruflin Hi ! Im facing the same situation now. Is this fixed by now? so far we have to restart filebeat process in order to release disk usage. |
Right now there is a big refactoring going on in the log input. This part of the code is not yet touched. But any feedback and problems are welcome to make sure as many problems as possible can be resolved. |
Hi, do we still need this feature? I have submitted the pull request here #8627 |
Any updates on this issue? |
This issue should be fixed with #13907, it is already available in some released versions. Closing this. |
https://github.com/elastic/beats/blob/master/filebeat/prospector/log/log.go#line49
why f.errorChecks method not follow n, err := f.fs.Read(buf) ? if file is ready and name is changed or remove how it know the action? because err == nil you return it back .
why not do as follow:
n, err := f.fs.Read(buf)
err = f.errorChecks(err)
The text was updated successfully, but these errors were encountered: