-
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
Port two Harvester tests of log input to filestream in Golang #24190
Port two Harvester tests of log input to filestream in Golang #24190
Conversation
Pinging @elastic/agent (Team:Agent) |
437d52d
to
15d61e4
Compare
💚 Build Succeeded
Expand to view the summary
Build stats
Test stats 🧪
Trends 🧪💚 Flaky test reportTests succeeded. Expand to view the summary
Test stats 🧪
|
err = ioutil.WriteFile(testlogPath, []byte("new first log line\nnew second log line\n"), 0644) | ||
if err != nil { | ||
t.Fatalf("cannot write log lines to test file: %+v", 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.
Maybe this is too much for this test case?Given the test name we just want to validate that the original harvester is closed when the file is renamed. Yet the test simulates a file rotation scenario. Although I agree we need that kind of test, I wonder if we want to have a separate set of tests that deal with different configuration-combinations and file rotation.
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.
Indeed. But in the first round of moving tests to Golang I would prefer to keep this functionality. This helps me keep track of what tests I have ported from the log
input. When I move on to supporting various log rotation methods, I am OK with renaming or moving the test around.
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.
Maybe you want to add an 'indicator' comment that you do not forget this particular line/test. e.g. // TODO: ...
or XXX: ...
Although it is nice to see the test coverage increased, these tests have quite a few moving pieces and might even be sensitive to timing. How about naming the file I wonder how 'stable' the test coverage is. Depending on timing I would presume coverage going up or down a little.
+100 Out of curiosity... how does the translation to go impact the runtime of the particular tests? |
It is significantly faster in Golang:
(The values above are the averages of 5 test runs in both languages.) |
Nice... it's like a factor of 20 |
be careful with the filename. Not sure, but |
func TestFilestreamCloseRenamed(t *testing.T) { | ||
if runtime.GOOS == "windows" { | ||
t.Skip("renaming files while Filebeat is running is not supported on Windows") | ||
} |
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.
Really? I wonder if the issue is due to use trying to write to the "original" path after the rotation.
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 got this error when I ran os.Rename
: The process cannot access the file because it is being used by another process.
I think no because the test tried to rename the file after it had written lines to the file. It rather fails because the filestream
input keeps the file open as it is waiting for new events to show up. To test my theory I closed the file on EOF, afterwards, I was able to rename the file on Windows as well.
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.
When reopening restarting the input, is that detected as a rename? Can we create a test to validate the expected behavior?
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.
If someone is able to rename a file on Windows while Filebeat is keeping it open, it is detected by the checker goroutine of logReader
. So the reader is going to behave correctly.
When reopening restarting the input, is that detected as a rename? Can we create a test to validate the expected behavior?
What is the expected behaviour? If the input is restarted, it does not make sense to check if a file was renamed because close_renamed
applies to opened files that are renamed during Filebeat running a Harvester
for.
When the input is restarted, it finds the state in the registry for the renamed file, unless path
file_identity
strategy is selected, it will not start a new Harvester
for the file because it is still the same file it encountered during the previous run.
These test cases are not special, we either already have tests for it or going to have them when all tests of log
input is ported to use filestream
.
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 still would expect that the meta-data in the registry are updated... meaning that the prospector detects the file was renamed. Maybe it is rather worth an unit test for the prospector
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.
OK, I will address this in a separate PR.
…c#24190) This PR ports the following Python tests of the `log` input to `filestream` to Golang: - `test_harvester.py:test_close_renamed` - `test_harvester.py:test_close_eof` The checks no longer rely on messages on Filebeat logs. Increased the test coverage of `filestream`: File | Before | After ----- | ----- | ----- `filebeat/input/filestream/input.go` | 0% | 57.4% `filebeat/input/filestream/prospector.go` | 86.2% | 90.0% `filebeat/input/filestream/filestream.go` | 67.1% | 79.1% `filebeat/input/filestream/fswatch.go` | 51.9% | 74.8% (cherry picked from commit c3b5a17)
#24604) This PR ports the following Python tests of the `log` input to `filestream` to Golang: - `test_harvester.py:test_close_renamed` - `test_harvester.py:test_close_eof` The checks no longer rely on messages on Filebeat logs. Increased the test coverage of `filestream`: File | Before | After ----- | ----- | ----- `filebeat/input/filestream/input.go` | 0% | 57.4% `filebeat/input/filestream/prospector.go` | 86.2% | 90.0% `filebeat/input/filestream/filestream.go` | 67.1% | 79.1% `filebeat/input/filestream/fswatch.go` | 51.9% | 74.8% (cherry picked from commit c3b5a17)
What does this PR do?
This PR ports the following Python tests of the
log
input tofilestream
to Golang:test_harvester.py:test_close_renamed
test_harvester.py:test_close_eof
The checks no longer rely on messages on Filebeat logs.
Why is it important?
Increased the test coverage of
filestream
:filebeat/input/filestream/input.go
filebeat/input/filestream/prospector.go
filebeat/input/filestream/filestream.go
filebeat/input/filestream/fswatch.go
Checklist
- [ ] I have made corresponding changes to the documentation- [ ] I have made corresponding change to the default configuration files- [ ] I have added tests that prove my fix is effective or that my feature works- [ ] I have added an entry inCHANGELOG.next.asciidoc
orCHANGELOG-developer.next.asciidoc
.