-
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] aws-s3 input - fix integration test with AWS #33893
[Filebeat] aws-s3 input - fix integration test with AWS #33893
Conversation
These tests verify the behavior by fetching metrics from the monitoring registry. After the fix in elastic#33259 the metrics were properly removed from the registry after the input's `Run()` method returned. This meant that the tests could not access the metrics. The fix is to keep reference to the inputMetrics struct within the input so that the tests can directly access the metrics without going through the monitoring registry.
The way the stub beat.Pipeline worked in the test code resulted in a panic because the both the test code and input code was closing the beat.Client that it produced. The test implementation had a Close() method that closed a channel. And since you can only close a channel once this caused a panic. The solution is to use the fakePipeline which is simpler because it produces a beat.Client implementation (ackClient) that only invokes ACK() on published events and does not use any channels. panic: close of closed channel goroutine 62186 [running]: github.com/elastic/beats/v7/libbeat/publisher/testing.(*ChanClient).Close(0xc0011e4bd0) /Users/akroh/code/beats/libbeat/publisher/testing/testing.go:71 +0x3c github.com/elastic/beats/v7/x-pack/filebeat/input/awss3.(*sqsS3EventProcessor).processS3Events(0xc00042e700, {0x103dc78d8, 0xc00049b280}, 0xc000aae820, {0xc001050380, 0x318}) /Users/akroh/code/beats/x-pack/filebeat/input/awss3/sqs_s3_event.go:327 +0x77c
4f1d4cc
to
611d60f
Compare
/test |
aws integrations tests are skipped in CI because they need the terraform output yml. beats/x-pack/filebeat/input/awss3/input_integration_test.go Lines 63 to 65 in 2fc3e81
|
@elastic/observablt-robots Regarding what @aspacca discovered about "stashing", is there a way to allow these cloud tests that depend on a terraform |
It should be possible to run these cloud tests that depend on terraform to run on CI by stashing the output file and unstashing it at the right moment before integration tests. |
This pull request is now in conflicts. Could you fix it? 🙏
|
I created a separate issue for the CI changes because I don't know how to fix it myself. These test fixes can merge independently of the CI fix. |
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
This pull request is now in conflicts. Could you fix it? 🙏
|
This merges the changes from main minus the conflicting changes from 065307c in elastic#33559 which fixed the tests in a manner that conflicts with these changes. That change also revert previous enhancements to report metrics under the "inputs" dataset.
@andrewkroh integration tests were fixed on https://github.com/elastic/beats/pull/33559/files#diff-c6b63b9cdaac006aa7c2fc1a148f81c69102e7eefc57bcf0a36aec3220c6b86f feel free to refactor my solution, that's far from to be elegant |
Pinging @elastic/security-external-integrations (Team:Security-External Integrations) |
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.
@andrewkroh the same has to be addressed in x-pack/filebeat/input/awscloudwatch/input_integration_test.go:142
Unregister metrics when the input stops. This ensures that when the input stops the metrics are removed. This allows the input to start again without encountering an issue that the metric ID is already registered. As a result the integration test needs modified to still be able to read the metrics after the input stops to allow it to runs some assertions. To accomplish this the inputMetrics struct is made directly accessible to the tests so they don't need to go through the monitoring registry.
c429c87
to
9545759
Compare
* [Filebeat] aws-s3 input - fix integration test with AWS These tests verify the behavior by fetching metrics from the monitoring registry. After the fix in #33259 the metrics were properly removed from the registry after the input's `Run()` method returned. This meant that the tests could not access the metrics. The fix is to keep reference to the inputMetrics struct within the input so that the tests can directly access the metrics without going through the monitoring registry. * [Filebeat] aws-s3 - fix panic in aws integ test The way the stub beat.Pipeline worked in the test code resulted in a panic because the both the test code and input code was closing the beat.Client that it produced. The test implementation had a Close() method that closed a channel. And since you can only close a channel once this caused a panic. The solution is to use the fakePipeline which is simpler because it produces a beat.Client implementation (ackClient) that only invokes ACK() on published events and does not use any channels. panic: close of closed channel goroutine 62186 [running]: github.com/elastic/beats/v7/libbeat/publisher/testing.(*ChanClient).Close(0xc0011e4bd0) /Users/akroh/code/beats/libbeat/publisher/testing/testing.go:71 +0x3c github.com/elastic/beats/v7/x-pack/filebeat/input/awss3.(*sqsS3EventProcessor).processS3Events(0xc00042e700, {0x103dc78d8, 0xc00049b280}, 0xc000aae820, {0xc001050380, 0x318}) /Users/akroh/code/beats/x-pack/filebeat/input/awss3/sqs_s3_event.go:327 +0x77c * Update terraform aws provider version to 4.46.0 * revert: fix integration tests from 33559 Revert 065307c * aws-cloudwatch - unregister metrics on close Unregister metrics when the input stops. This ensures that when the input stops the metrics are removed. This allows the input to start again without encountering an issue that the metric ID is already registered. As a result the integration test needs modified to still be able to read the metrics after the input stops to allow it to runs some assertions. To accomplish this the inputMetrics struct is made directly accessible to the tests so they don't need to go through the monitoring registry.
What does this PR do?
[Filebeat] aws-s3 input - fix integration test with AWS
These tests verify the behavior by fetching metrics from the monitoring
registry. After the fix in #33259 the metrics were properly removed
from the registry after the input's
Run()
method returned. This meantthat the tests could not access the metrics.
The fix is to keep reference to the
inputMetrics
struct within the inputso that the tests can directly access the metrics without going through
the monitoring registry.
[Filebeat] aws-s3 - fix panic in aws integ test
The way the stub beat.Pipeline worked in the test code resulted
in a panic because the both the test code and input code was closing
the
beat.Client
that it produced. The test implementation had aClose()
method that closed a channel. And since you can only close a channel
once this caused a panic.
The solution is to use the
fakePipeline
which is simpler because itproduces a
beat.Client
implementation (ackClient
) that only invokesACK()
on published events and does not use any channels.Why is it important?
Checklist
CHANGELOG.next.asciidoc
orCHANGELOG-developer.next.asciidoc
.Author's Notes
I don't know how CI could have been passing unless the cloudAWS job is not working or not running.
On the last PR to change the package the tests were skipped. This means that
-tags integration,aws
were used, but the test could not find the terraform output file.I checked the CI logs and terraform did run successfully. So checking the code that reads the terraform output file and I see some unusual code. I don't know why this was added. Could the test be looking in the wrong place?
beats/x-pack/filebeat/input/awss3/input_integration_test.go
Lines 61 to 62 in 611d60f
update 1: On the first run of this PR the test was skipped.
update 2: On the second run, after I removed the suspicious code above it still was skipped. This will need deeper investigation into what CI is doing.
update 3: @aspacca identified the cause to that the terraform local_file output is "stashed" before the Filebeat test runs. So the test cannot access the file that it needs to it skips itself. I have no idea how to fix that. Opening an issue to track that in #34003.
How to test this PR locally
Related issues