Skip to content
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

Add tests for truncated and symlinked files #24425

Merged
merged 3 commits into from
Apr 14, 2021

Conversation

kvch
Copy link
Contributor

@kvch kvch commented Mar 8, 2021

What does this PR do?

Add support for better support truncated files with symlinks and adds migrates related tests from test_harvester.py.

Why is it important?

Increase coverage.

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
    - [ ] 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 in CHANGELOG.next.asciidoc or CHANGELOG-developer.next.asciidoc.

@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Mar 8, 2021
@kvch kvch requested a review from urso March 8, 2021 17:21
@kvch kvch changed the title Test filebeat filestream symlinking Add tests for truncated and symlinked files Mar 8, 2021
@andresrc andresrc added the Team:Elastic-Agent Label for the Agent team label Mar 8, 2021
@elasticmachine
Copy link
Collaborator

Pinging @elastic/agent (Team:Agent)

@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Mar 8, 2021
@elasticmachine
Copy link
Collaborator

elasticmachine commented Mar 8, 2021

💔 Build Failed

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview

Expand to view the summary

Build stats

  • Build Cause: Pull request #24425 updated

  • Start Time: 2021-04-13T16:21:44.008+0000

  • Duration: 57 min 44 sec

  • Commit: 179a7a1

Test stats 🧪

Test Results
Failed 0
Passed 13513
Skipped 2271
Total 15784

Trends 🧪

Image of Build Times

Image of Tests

Steps errors 3

Expand to view the steps failures

filebeat-packaging-arm-arm - mage package
  • Took 8 min 42 sec . View more details on here
  • Description: mage package
x-pack/filebeat-packaging-arm-arm - mage package
  • Took 5 min 19 sec . View more details on here
  • Description: mage package
Error signal
  • Took 0 min 0 sec . View more details on here
  • Description: Error 'hudson.AbortException: script returned exit code 1'

Log output

Expand to view the last 100 lines of log output

[2021-04-13T17:17:49.833Z] 8.74s call     x-pack/filebeat/tests/system/test_xpack_modules.py::XPackTest::test_fileset_file_283_tomcat
[2021-04-13T17:17:49.833Z] 8.72s call     x-pack/filebeat/tests/system/test_xpack_modules.py::XPackTest::test_fileset_file_093_ibmmq
[2021-04-13T17:17:49.833Z] 8.62s call     x-pack/filebeat/tests/system/test_xpack_modules.py::XPackTest::test_fileset_file_307_sonicwall
[2021-04-13T17:17:49.833Z] 8.62s call     x-pack/filebeat/tests/system/test_xpack_modules.py::XPackTest::test_fileset_file_285_sophos
[2021-04-13T17:17:49.833Z] 8.60s call     x-pack/filebeat/tests/system/test_xpack_modules.py::XPackTest::test_fileset_file_164_cisco
[2021-04-13T17:17:49.833Z] ======================= 323 passed in 1482.72s (0:24:42) =======================
[2021-04-13T17:17:50.096Z] >> python test: Integration Testing Complete
[2021-04-13T17:17:54.689Z] Cleaning up /var/lib/jenkins/workspace/PR-24425-6-48a13a3f-c5c1-44ce-bbc7-c8cca62844cc
[2021-04-13T17:17:54.689Z] Client: Docker Engine - Community
[2021-04-13T17:17:54.689Z]  Version:           20.10.3
[2021-04-13T17:17:54.689Z]  API version:       1.41
[2021-04-13T17:17:54.689Z]  Go version:        go1.13.15
[2021-04-13T17:17:54.689Z]  Git commit:        48d30b5
[2021-04-13T17:17:54.690Z]  Built:             Fri Jan 29 14:33:13 2021
[2021-04-13T17:17:54.690Z]  OS/Arch:           linux/amd64
[2021-04-13T17:17:54.690Z]  Context:           default
[2021-04-13T17:17:54.690Z]  Experimental:      true
[2021-04-13T17:17:54.690Z] 
[2021-04-13T17:17:54.690Z] Server: Docker Engine - Community
[2021-04-13T17:17:54.690Z]  Engine:
[2021-04-13T17:17:54.690Z]   Version:          20.10.3
[2021-04-13T17:17:54.690Z]   API version:      1.41 (minimum version 1.12)
[2021-04-13T17:17:54.690Z]   Go version:       go1.13.15
[2021-04-13T17:17:54.690Z]   Git commit:       46229ca
[2021-04-13T17:17:54.690Z]   Built:            Fri Jan 29 14:31:25 2021
[2021-04-13T17:17:54.690Z]   OS/Arch:          linux/amd64
[2021-04-13T17:17:54.690Z]   Experimental:     false
[2021-04-13T17:17:54.690Z]  containerd:
[2021-04-13T17:17:54.690Z]   Version:          1.4.4
[2021-04-13T17:17:54.690Z]   GitCommit:        05f951a3781f4f2c1911b05e61c160e9c30eaa8e
[2021-04-13T17:17:54.690Z]  runc:
[2021-04-13T17:17:54.690Z]   Version:          1.0.0-rc93
[2021-04-13T17:17:54.690Z]   GitCommit:        12644e614e25b05da6fd08a38ffa0cfe1903fdec
[2021-04-13T17:17:54.690Z]  docker-init:
[2021-04-13T17:17:54.690Z]   Version:          0.19.0
[2021-04-13T17:17:54.690Z]   GitCommit:        de40ad0
[2021-04-13T17:17:54.690Z] Change ownership of all files inside the specific folder from root/root to current user/group
[2021-04-13T17:17:54.690Z] Unable to find image 'alpine:3.4' locally
[2021-04-13T17:17:55.292Z] 3.4: Pulling from library/alpine
[2021-04-13T17:17:55.559Z] c1e54eec4b57: Pulling fs layer
[2021-04-13T17:17:56.136Z] c1e54eec4b57: Download complete
[2021-04-13T17:17:56.401Z] c1e54eec4b57: Pull complete
[2021-04-13T17:17:56.401Z] Digest: sha256:b733d4a32c4da6a00a84df2ca32791bb03df95400243648d8c539e7b4cce329c
[2021-04-13T17:17:56.401Z] Status: Downloaded newer image for alpine:3.4
[2021-04-13T17:17:58.996Z] Change permissions with write access of all files inside the specific folder
[2021-04-13T17:17:59.967Z] Running in /var/lib/jenkins/workspace/PR-24425-6-48a13a3f-c5c1-44ce-bbc7-c8cca62844cc/src/github.com/elastic/beats/build
[2021-04-13T17:18:00.272Z] + rm -rf ve
[2021-04-13T17:18:00.272Z] + find . -type d -name vendor -exec rm -r {} ;
[2021-04-13T17:18:00.610Z] + python .ci/scripts/pre_archive_test.py
[2021-04-13T17:18:03.220Z] Copy ./x-pack/filebeat/build into build/x-pack/filebeat/build
[2021-04-13T17:18:03.234Z] Running in /var/lib/jenkins/workspace/PR-24425-6-48a13a3f-c5c1-44ce-bbc7-c8cca62844cc/src/github.com/elastic/beats/build
[2021-04-13T17:18:03.251Z] Recording test results
[2021-04-13T17:18:04.706Z] [Checks API] No suitable checks publisher found.
[2021-04-13T17:18:05.052Z] + go clean -modcache
[2021-04-13T17:18:09.611Z] Cleaning up /var/lib/jenkins/workspace/PR-24425-6-48a13a3f-c5c1-44ce-bbc7-c8cca62844cc
[2021-04-13T17:18:09.611Z] Client: Docker Engine - Community
[2021-04-13T17:18:09.611Z]  Version:           20.10.3
[2021-04-13T17:18:09.611Z]  API version:       1.41
[2021-04-13T17:18:09.611Z]  Go version:        go1.13.15
[2021-04-13T17:18:09.611Z]  Git commit:        48d30b5
[2021-04-13T17:18:09.611Z]  Built:             Fri Jan 29 14:33:13 2021
[2021-04-13T17:18:09.611Z]  OS/Arch:           linux/amd64
[2021-04-13T17:18:09.611Z]  Context:           default
[2021-04-13T17:18:09.611Z]  Experimental:      true
[2021-04-13T17:18:09.611Z] 
[2021-04-13T17:18:09.611Z] Server: Docker Engine - Community
[2021-04-13T17:18:09.611Z]  Engine:
[2021-04-13T17:18:09.611Z]   Version:          20.10.3
[2021-04-13T17:18:09.611Z]   API version:      1.41 (minimum version 1.12)
[2021-04-13T17:18:09.611Z]   Go version:       go1.13.15
[2021-04-13T17:18:09.611Z]   Git commit:       46229ca
[2021-04-13T17:18:09.611Z]   Built:            Fri Jan 29 14:31:25 2021
[2021-04-13T17:18:09.611Z]   OS/Arch:          linux/amd64
[2021-04-13T17:18:09.611Z]   Experimental:     false
[2021-04-13T17:18:09.611Z]  containerd:
[2021-04-13T17:18:09.611Z]   Version:          1.4.4
[2021-04-13T17:18:09.611Z]   GitCommit:        05f951a3781f4f2c1911b05e61c160e9c30eaa8e
[2021-04-13T17:18:09.611Z]  runc:
[2021-04-13T17:18:09.611Z]   Version:          1.0.0-rc93
[2021-04-13T17:18:09.611Z]   GitCommit:        12644e614e25b05da6fd08a38ffa0cfe1903fdec
[2021-04-13T17:18:09.611Z]  docker-init:
[2021-04-13T17:18:09.611Z]   Version:          0.19.0
[2021-04-13T17:18:09.611Z]   GitCommit:        de40ad0
[2021-04-13T17:18:09.611Z] Change ownership of all files inside the specific folder from root/root to current user/group
[2021-04-13T17:18:16.241Z] Change permissions with write access of all files inside the specific folder
[2021-04-13T17:18:16.855Z] Running in /var/lib/jenkins/workspace/PR-24425-6-48a13a3f-c5c1-44ce-bbc7-c8cca62844cc
[2021-04-13T17:18:22.911Z] + gsutil --version
[2021-04-13T17:18:24.387Z] Masking supported pattern matches of $FILE_CREDENTIAL
[2021-04-13T17:18:24.706Z] + gcloud auth activate-service-account --key-file ****
[2021-04-13T17:18:25.279Z] Activated service account credentials for: [beats-ci-gcs-plugin@elastic-ci-prod.iam.gserviceaccount.com]
[2021-04-13T17:18:25.603Z] + gsutil -m -q cp -a public-read eC1wYWNrL2ZpbGViZWF0LWJ1aWxkMTc5YTdhMTYwMzI3NmM3YjdiYWUyNDI4NDAyMWUyMzI1MTYzMjVjOQ gs://beats-ci-temp/ci/cache/
[2021-04-13T17:18:27.123Z] Stage "Packaging" skipped due to earlier failure(s)
[2021-04-13T17:18:27.176Z] Running in /var/lib/jenkins/workspace/Beats_beats_PR-24425/src/github.com/elastic/beats
[2021-04-13T17:18:27.505Z] Running on Jenkins in /var/lib/jenkins/workspace/Beats_beats_PR-24425
[2021-04-13T17:18:27.548Z] [INFO] getVaultSecret: Getting secrets
[2021-04-13T17:18:27.646Z] Masking supported pattern matches of $VAULT_ADDR or $VAULT_ROLE_ID or $VAULT_SECRET_ID
[2021-04-13T17:18:28.342Z] + chmod 755 generate-build-data.sh
[2021-04-13T17:18:28.342Z] + ./generate-build-data.sh https://beats-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/Beats/beats/PR-24425/ https://beats-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/Beats/beats/PR-24425/runs/6 FAILURE 3404070
[2021-04-13T17:18:28.592Z] INFO: curl https://beats-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/Beats/beats/PR-24425/runs/6/steps/?limit=10000 -o steps-info.json
[2021-04-13T17:18:29.936Z] INFO: curl https://beats-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/Beats/beats/PR-24425/runs/6/tests/?status=FAILED -o tests-errors.json

💚 Flaky test report

Tests succeeded.

Expand to view the summary

Test stats 🧪

Test Results
Failed 0
Passed 13513
Skipped 2271
Total 15784

@kvch kvch force-pushed the test-filebeat-filestream-symlinking branch from 7d4b85d to bc1c3a2 Compare April 7, 2021 09:59
@kvch kvch force-pushed the test-filebeat-filestream-symlinking branch from bc1c3a2 to 371b1ba Compare April 7, 2021 15:06
@kvch
Copy link
Contributor Author

kvch commented Apr 8, 2021

jenkins run tests


// rotate symlink
env.mustRemoveFile(symlinkName)
env.mustSymlink(secondTestlogName, symlinkName)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. I would not expect the symlink to be removed when rotating it. Just change the location it points to. What would happen in that case? What would happen if the new log file is larger then the old one when we update the link?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have just ported blindly the test from the original Python one. There should not be any change in behaviour of Filebeat if the symlink is renamed.

If the log file is bigger than the previous, Filebeat cannot detect truncation regardless of what we do with the file symlink, rename, remove and create again. That is why we need the special copytruncate prospector.

Copy link

@urso urso Apr 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. So we do track the inode of the symlink file, and not the inode of the target file.

I have just ported blindly the test from the original Python one. There should not be any change in behaviour of Filebeat if the symlink is renamed.

I still would expect a slight difference. If we remove the symlink file before, then the symlink is a new file with a new inode. If we just overwrite the symlink with a new file the inode is not changed and filebeat would/should see it as a truncation event. Also the observable result (collect from offset 0) should be the same, the internal handling of these 2 cases differ, right? So it would be nice to have additonal tests for symlinks, but I would say these cases can be tested as unit tests in the prospector or file watcher.

I guess we need to rethink symlink support to some extent. Detecting changes on a symlink should not only depend on the file size. Have we also considered the case of a symlink becoming an actual file (or the other way around)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it OK if I add a test for the scenario you had described in a follow up PR? You are raising valid points. However, we should decide what we want to tackle in the default prospector and what we want to cover in the copytruncate prospector. I would rather give us a bit more time for that and address your concerns in a new PR. WDYT?

env.mustAppendLinesToFile(testlogName, line)

env.waitUntilEventCount(2)
env.requireOffsetInRegistry(testlogName, 2*len(line))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would happen if we have close...removed: true? Will remove act on the symlink state, or on the resolved file?

What happens on close...renamed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filebeat cares about the original file, not the symlink. The setting has no impact on the behaviour of the reader if the symlink is deleted. I am not sure why the original test contains it.

env.requireOffsetInRegistry(testlogName, len(line))

// remove symlink
env.mustRemoveFile(symlinkName)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if I don't remove/update the symlink, but the file the symlink points to? Do we even detect that case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the reader opens the original file and tracks everything the same way as done in ordinary files.

@urso
Copy link

urso commented Apr 13, 2021

ARM tests fail because we are hitting docker registry limits. Are we missing some images in our caches?

@kvch kvch merged commit a9279cd into elastic:master Apr 14, 2021
@kvch kvch added the needs_backport PR is waiting to be backported to other branches. label Apr 14, 2021
v1v added a commit to v1v/beats that referenced this pull request Apr 15, 2021
* upstream/master:
  packer cache support for the 7.x and 7.latestMinor branches (elastic#25091)
  Remove EventFetcher and EventsFetcher interface (elastic#25093)
  Update go-structform to 0.0.8 (elastic#25051)
  Update copy_fields.asciidoc (elastic#25053)
  [elastic-agent] ensure container is backwards compatible (elastic#25092)
  Add --fleet-server-service-token. Rename --fleet-server to --fleet-server-es. (elastic#25083)
  Add cgroup.cpuacct percentages (elastic#25057)
  Add tests for truncated and symlinked files in filestream input (elastic#24425)
  Fix panic when Hearbeat monitor initialization fails twice (elastic#25073)
  [Filebeat][httpjson] Change append transform to initiate new fields as a slice (elastic#25074)
  Osquerybeat: Result values type translation (elastic#25012)
  Update Osquerybeat spec to get it downloading from the correct artifactory path (elastic#25076)
  Fix changelog (elastic#25079)
  Strip Azure EventHub connection string in debug logs (elastic#25066)
  Change googlecloud to gcp in field names (elastic#25038)
  Bump stack version to 7.12.0 for testing (elastic#24957)
  packer-cache: cache the existing docker images on ARM and some more (elastic#25068)
  Disable logstash TestFetch flaky test (elastic#25044)
kvch added a commit to kvch/beats that referenced this pull request Apr 15, 2021
@kvch kvch added v7.13.0 and removed needs_backport PR is waiting to be backported to other branches. labels Apr 15, 2021
kvch added a commit that referenced this pull request Apr 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team:Elastic-Agent Label for the Agent team v7.13.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants