Skip to content

Cherry-pick #24424 to 7.x: Add tests and support for truncated files in filestream input#24959

Merged
kvch merged 1 commit intoelastic:7.xfrom
kvch:backport_24424_7.x
Apr 7, 2021
Merged

Cherry-pick #24424 to 7.x: Add tests and support for truncated files in filestream input#24959
kvch merged 1 commit intoelastic:7.xfrom
kvch:backport_24424_7.x

Conversation

@kvch
Copy link
Copy Markdown
Contributor

@kvch kvch commented Apr 7, 2021

Cherry-pick of PR #24424 to 7.x branch. Original message:

What does this PR do?

Add support for truncated files and adds migrates related tests from test_harvester.py. It also adds more tests to cover the following cases:

  • truncation is detected only by the Prospector
  • truncation is detected first by the Harvester then by the Prospector
  • truncation is detected first by the Prospector then by the Harvester
  • file gets truncated when the output is not able to accept events

Why is it important?

The support for stopping reading from truncated files was already implemented. However, filestream input could not start reading it from the beginning.

A new file system event is added called OpTruncate. When the size of a file has shrinked compared to the last time the scanner has encountered it, an OpTruncate event is emitted. When the prospector gets this event, the HarvesterGroup is restarting the Harvester of the file. Restarting basically means that the new Harvester cancels the previous reader and starts a new one.

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.

…c#24424)

## What does this PR do?

Add support for truncated files and adds migrates related tests from `test_harvester.py`. It also adds more tests to cover the following cases:

* truncation is detected only by the `Prospector`
* truncation is detected first by the `Harvester` then by the `Prospector`
* truncation is detected first by the `Prospector` then by the `Harvester`
* file gets truncated when the output is not able to accept events

## Why is it important?

The support for stopping reading from truncated files was already implemented. However, `filestream` input could not start reading it from the beginning.

A new file system event is added called `OpTruncate`. When the size of a file has shrinked compared to the last time the scanner has encountered it, an `OpTruncate` event is emitted. When the prospector gets this event, the `HarvesterGroup` is restarting the `Harvester` of the file. Restarting basically means that the new `Harvester` cancels the previous reader and starts

(cherry picked from commit 2875faf)
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/agent (Team:Agent)

@botelastic botelastic bot added needs_team Indicates that the issue/PR needs a Team:* label and removed needs_team Indicates that the issue/PR needs a Team:* label labels Apr 7, 2021
@kvch
Copy link
Copy Markdown
Contributor Author

kvch commented Apr 7, 2021

Failing test is unrelated.

@kvch kvch merged commit 3dfbbb3 into elastic:7.x Apr 7, 2021
@elasticmachine
Copy link
Copy Markdown
Contributor

💔 Tests 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 #24959 opened

  • Start Time: 2021-04-07T09:45:48.618+0000

  • Duration: 181 min 51 sec

  • Commit: 7164903

Test stats 🧪

Test Results
Failed 1
Passed 12494
Skipped 2137
Total 14632

Trends 🧪

Image of Build Times

Image of Tests

Test errors 1

Expand to view the tests failures

Build&Test / filebeat-windows-8-windows-8 / test_tcp_with_custom_word_delimiter – filebeat.tests.system.test_tcp.Test
    Expand to view the error details

     beat.beat.TimeoutError: Timeout waiting for 'cond' to be true. Waited 10 seconds. 
    

    Expand to view the stacktrace

     self = <test_tcp.Test testMethod=test_tcp_with_custom_word_delimiter>
    
        def test_tcp_with_custom_word_delimiter(self):
            """
            Test TCP input with a custom single char delimiter
            """
    >       self.send_events_with_delimiter("<END>")
    
    tests\system\test_tcp.py:26: 
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
    tests\system\test_tcp.py:62: in send_events_with_delimiter
        self.wait_until(lambda: self.log_contains("Started listening for TCP connection"))
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
    
    self = <test_tcp.Test testMethod=test_tcp_with_custom_word_delimiter>
    cond = <function Test.send_events_with_delimiter.<locals>.<lambda> at 0x000000E0F8F0C8B0>
    max_timeout = 10, poll_interval = 0.1, name = 'cond'
    
        def wait_until(self, cond, max_timeout=10, poll_interval=0.1, name="cond"):
            """
            Waits until the cond function returns true,
            or until the max_timeout is reached. Calls the cond
            function every poll_interval seconds.
        
            If the max_timeout is reached before cond() returns
            true, an exception is raised.
            """
            start = datetime.now()
            while not cond():
                if datetime.now() - start > timedelta(seconds=max_timeout):
    >               raise TimeoutError("Timeout waiting for '{}' to be true. ".format(name) +
                                       "Waited {} seconds.".format(max_timeout))
    E               beat.beat.TimeoutError: Timeout waiting for 'cond' to be true. Waited 10 seconds.
    
    ..\libbeat\tests\system\beat\beat.py:362: TimeoutError 
    

Steps errors 3

Expand to view the steps failures

filebeat-windows-8-windows-8 - mage build unitTest
  • Took 7 min 39 sec . View more details on here
  • Description: mage build unitTest
gsutil -m -q cp -a public-read test-build-artifacts-filebeat-windows-8-windows-8-tgz gs://beats-ci-t
  • Took 0 min 10 sec . View more details on here
  • Description: @echo off gsutil -m -q cp -a public-read test-build-artifacts-filebeat-windows-8-windows-8-tgz gs://beats-ci-temp/Beats/beats/PR-24959-1
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-07T10:42:48.367Z] 9.84s call     x-pack/filebeat/tests/system/test_xpack_modules.py::XPackTest::test_fileset_file_016_cisco
[2021-04-07T10:42:48.367Z] 9.76s call     x-pack/filebeat/tests/system/test_xpack_modules.py::XPackTest::test_fileset_file_245_ibmmq
[2021-04-07T10:42:48.367Z] 9.76s call     x-pack/filebeat/tests/system/test_xpack_modules.py::XPackTest::test_fileset_file_268_panw
[2021-04-07T10:42:48.367Z] 9.67s call     x-pack/filebeat/tests/system/test_xpack_modules.py::XPackTest::test_fileset_file_269_panw
[2021-04-07T10:42:48.367Z] 9.18s call     x-pack/filebeat/tests/system/test_xpack_modules.py::XPackTest::test_fileset_file_241_oracle
[2021-04-07T10:42:48.367Z] 9.08s call     x-pack/filebeat/tests/system/test_xpack_modules.py::XPackTest::test_fileset_file_224_gcp
[2021-04-07T10:42:48.367Z] 9.04s call     x-pack/filebeat/tests/system/test_xpack_modules.py::XPackTest::test_fileset_file_142_zscaler
[2021-04-07T10:42:48.367Z] 9.00s call     x-pack/filebeat/tests/system/test_xpack_modules.py::XPackTest::test_fileset_file_262_fortinet
[2021-04-07T10:42:48.367Z] 8.98s call     x-pack/filebeat/tests/system/test_xpack_modules.py::XPackTest::test_fileset_file_264_squid
[2021-04-07T10:42:48.367Z] 8.96s call     x-pack/filebeat/tests/system/test_xpack_modules.py::XPackTest::test_fileset_file_037_cisco
[2021-04-07T10:42:48.367Z] ================ 323 passed, 310 warnings in 1490.05s (0:24:50) ================
[2021-04-07T10:42:48.367Z] >> python test: Integration Testing Complete
[2021-04-07T10:42:48.841Z] Cleaning up /var/lib/jenkins/workspace/PR-24959-1-0df60a85-5e7d-41a4-a158-f978df78de39
[2021-04-07T10:42:48.841Z] Client: Docker Engine - Community
[2021-04-07T10:42:48.841Z]  Version:           20.10.3
[2021-04-07T10:42:48.841Z]  API version:       1.41
[2021-04-07T10:42:48.842Z]  Go version:        go1.13.15
[2021-04-07T10:42:48.842Z]  Git commit:        48d30b5
[2021-04-07T10:42:48.842Z]  Built:             Fri Jan 29 14:33:13 2021
[2021-04-07T10:42:48.842Z]  OS/Arch:           linux/amd64
[2021-04-07T10:42:48.842Z]  Context:           default
[2021-04-07T10:42:48.842Z]  Experimental:      true
[2021-04-07T10:42:48.842Z] 
[2021-04-07T10:42:48.842Z] Server: Docker Engine - Community
[2021-04-07T10:42:48.842Z]  Engine:
[2021-04-07T10:42:48.842Z]   Version:          20.10.3
[2021-04-07T10:42:48.842Z]   API version:      1.41 (minimum version 1.12)
[2021-04-07T10:42:48.842Z]   Go version:       go1.13.15
[2021-04-07T10:42:48.842Z]   Git commit:       46229ca
[2021-04-07T10:42:48.842Z]   Built:            Fri Jan 29 14:31:25 2021
[2021-04-07T10:42:48.842Z]   OS/Arch:          linux/amd64
[2021-04-07T10:42:48.842Z]   Experimental:     false
[2021-04-07T10:42:48.842Z]  containerd:
[2021-04-07T10:42:48.842Z]   Version:          1.4.4
[2021-04-07T10:42:48.842Z]   GitCommit:        05f951a3781f4f2c1911b05e61c160e9c30eaa8e
[2021-04-07T10:42:48.842Z]  runc:
[2021-04-07T10:42:48.842Z]   Version:          1.0.0-rc93
[2021-04-07T10:42:48.842Z]   GitCommit:        12644e614e25b05da6fd08a38ffa0cfe1903fdec
[2021-04-07T10:42:48.842Z]  docker-init:
[2021-04-07T10:42:48.842Z]   Version:          0.19.0
[2021-04-07T10:42:48.842Z]   GitCommit:        de40ad0
[2021-04-07T10:42:48.842Z] Change ownership of all files inside the specific folder from root/root to current user/group
[2021-04-07T10:42:50.755Z] Change permissions with write access of all files inside the specific folder
[2021-04-07T10:42:52.175Z] Running in /var/lib/jenkins/workspace/PR-24959-1-0df60a85-5e7d-41a4-a158-f978df78de39/src/github.com/elastic/beats/build
[2021-04-07T10:42:52.514Z] + rm -rf ve
[2021-04-07T10:42:52.514Z] + find . -type d -name vendor -exec rm -r {} ;
[2021-04-07T10:42:52.900Z] + python .ci/scripts/pre_archive_test.py
[2021-04-07T10:42:54.810Z] Copy ./x-pack/filebeat/build into build/x-pack/filebeat/build
[2021-04-07T10:42:54.845Z] Running in /var/lib/jenkins/workspace/PR-24959-1-0df60a85-5e7d-41a4-a158-f978df78de39/src/github.com/elastic/beats/build
[2021-04-07T10:42:54.897Z] Recording test results
[2021-04-07T10:42:55.820Z] [Checks API] No suitable checks publisher found.
[2021-04-07T10:42:56.305Z] + go clean -modcache
[2021-04-07T10:42:59.986Z] Cleaning up /var/lib/jenkins/workspace/PR-24959-1-0df60a85-5e7d-41a4-a158-f978df78de39
[2021-04-07T10:42:59.986Z] Client: Docker Engine - Community
[2021-04-07T10:42:59.986Z]  Version:           20.10.3
[2021-04-07T10:42:59.986Z]  API version:       1.41
[2021-04-07T10:42:59.986Z]  Go version:        go1.13.15
[2021-04-07T10:42:59.986Z]  Git commit:        48d30b5
[2021-04-07T10:42:59.986Z]  Built:             Fri Jan 29 14:33:13 2021
[2021-04-07T10:42:59.986Z]  OS/Arch:           linux/amd64
[2021-04-07T10:42:59.986Z]  Context:           default
[2021-04-07T10:42:59.986Z]  Experimental:      true
[2021-04-07T10:42:59.986Z] 
[2021-04-07T10:42:59.986Z] Server: Docker Engine - Community
[2021-04-07T10:42:59.986Z]  Engine:
[2021-04-07T10:42:59.986Z]   Version:          20.10.3
[2021-04-07T10:42:59.986Z]   API version:      1.41 (minimum version 1.12)
[2021-04-07T10:42:59.986Z]   Go version:       go1.13.15
[2021-04-07T10:42:59.986Z]   Git commit:       46229ca
[2021-04-07T10:42:59.986Z]   Built:            Fri Jan 29 14:31:25 2021
[2021-04-07T10:42:59.986Z]   OS/Arch:          linux/amd64
[2021-04-07T10:42:59.986Z]   Experimental:     false
[2021-04-07T10:42:59.986Z]  containerd:
[2021-04-07T10:42:59.986Z]   Version:          1.4.4
[2021-04-07T10:42:59.986Z]   GitCommit:        05f951a3781f4f2c1911b05e61c160e9c30eaa8e
[2021-04-07T10:42:59.986Z]  runc:
[2021-04-07T10:42:59.986Z]   Version:          1.0.0-rc93
[2021-04-07T10:42:59.986Z]   GitCommit:        12644e614e25b05da6fd08a38ffa0cfe1903fdec
[2021-04-07T10:42:59.986Z]  docker-init:
[2021-04-07T10:42:59.986Z]   Version:          0.19.0
[2021-04-07T10:42:59.986Z]   GitCommit:        de40ad0
[2021-04-07T10:42:59.986Z] Change ownership of all files inside the specific folder from root/root to current user/group
[2021-04-07T10:43:06.574Z] Change permissions with write access of all files inside the specific folder
[2021-04-07T10:43:06.652Z] Running in /var/lib/jenkins/workspace/PR-24959-1-0df60a85-5e7d-41a4-a158-f978df78de39
[2021-04-07T10:43:12.065Z] + gsutil --version
[2021-04-07T10:43:13.594Z] Masking supported pattern matches of $FILE_CREDENTIAL
[2021-04-07T10:43:13.953Z] + gcloud auth activate-service-account --key-file ****
[2021-04-07T10:43:14.528Z] Activated service account credentials for: [beats-ci-gcs-plugin@elastic-ci-prod.iam.gserviceaccount.com]
[2021-04-07T10:43:14.918Z] + gsutil -m -q cp -a public-read eC1wYWNrL2ZpbGViZWF0LWJ1aWxkNzE2NDkwMzhkYzIxZTQyYWU2YjUyOWU5MWFhNmJlODEyMjliNmZhYg gs://beats-ci-temp/ci/cache/
[2021-04-07T12:46:36.706Z] Cancelling nested steps due to timeout
[2021-04-07T12:46:36.748Z] Failed in branch x-pack/filebeat-windows-2008-windows-2008-r2
[2021-04-07T12:46:37.548Z] Stage "Packaging" skipped due to earlier failure(s)
[2021-04-07T12:46:37.713Z] Running in /var/lib/jenkins/workspace/Beats_beats_PR-24959/src/github.com/elastic/beats
[2021-04-07T12:46:38.300Z] Running on Jenkins in /var/lib/jenkins/workspace/Beats_beats_PR-24959
[2021-04-07T12:46:38.407Z] [INFO] getVaultSecret: Getting secrets
[2021-04-07T12:46:38.550Z] Masking supported pattern matches of $VAULT_ADDR or $VAULT_ROLE_ID or $VAULT_SECRET_ID
[2021-04-07T12:46:39.544Z] + chmod 755 generate-build-data.sh
[2021-04-07T12:46:39.544Z] + ./generate-build-data.sh https://beats-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/Beats/beats/PR-24959/ https://beats-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/Beats/beats/PR-24959/runs/1 FAILURE 10850647
[2021-04-07T12:46:39.795Z] INFO: curl https://beats-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/Beats/beats/PR-24959/runs/1/steps/?limit=10000 -o steps-info.json
[2021-04-07T12:46:41.138Z] INFO: curl https://beats-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/Beats/beats/PR-24959/runs/1/tests/?status=FAILED -o tests-errors.json

🐛 Flaky test report

❕ There are test failures but not known flaky tests.

Expand to view the summary

Test stats 🧪

Test Results
Failed 1
Passed 12494
Skipped 2137
Total 14632

Genuine test errors 1

💔 There are test failures but not known flaky tests, most likely a genuine test failure.

  • Name: Build&Test / filebeat-windows-8-windows-8 / test_tcp_with_custom_word_delimiter – filebeat.tests.system.test_tcp.Test

@zube zube bot removed the [zube]: Done label Jul 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport Team:Elastic-Agent Label for the Agent team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants