Get TestData back into the metricsets#11818
Conversation
sayden
left a comment
There was a problem hiding this comment.
Thanks for contributing with this! Left a couple of comments
|
What bugs me about the current approach we have is that
It's easy to miss the second point in a review. It means all data could have been added but is not run properly and we will not detect it. I wonder if there is any other trick that we can make |
|
Having I agree with the second point,
|
I am trying it to be the minimal needed boilerplate, but I think that an explicit test is required, and even desired.
I think we can live with this risk 🙂 Something similar would happen with any other test that uses external files, one may add the files but forget the test. Another thing that mitigates the risk is that this way all metricsets continue having tests, it is easier for newcomers to understand how the module is being tested, they don't need to guess that there are some testdata files in _meta that are somehow used for tests. They can see a test, that calls the helpers, and then look at the docs (or the code) of the helpers. Relying on conventions is also prone to add things that are not interpreted as expected or ignored by the framework.
I'd like to end-up removing For initial migration, and sporadic checks we can follow @exekias recommendation of removing all expected files and run the tests with the generate flag. |
|
One thought I would like to add here: What happens in the future if we have modules without go code? I think if we keep the |
|
I'd still place the tests for these modules near these modules (we can have go test files in packages without other test code). But ok, we can delay this discussion, I will leave |
|
I added back the test methods but keeping The only problem with |
There was a problem hiding this comment.
This is the only thing that changed after regenerating all files.
There was a problem hiding this comment.
I'm surprised this changed (it shouldn't). @sayden I remember we had some discussion around apache and "whitelist" some files which should not be remove or similar?
There was a problem hiding this comment.
Yes, I finally added a config in TestAll to omit specific fields or fields group from the comparison because they were changing in each regenerate https://github.com/elastic/beats/pull/11714/files#diff-5b51ecdcb61bd7977eb4d2e2852178c0R32
There was a problem hiding this comment.
And why did it still change here?
77c7529 to
fb70ba0
Compare
| @@ -1,7 +0,0 @@ | |||
| type: http | |||
There was a problem hiding this comment.
We don't need this anymore?
There was a problem hiding this comment.
I couldn't find where this was being used, so I removed it.
Could this be the cause of the change in apache hostname?
There was a problem hiding this comment.
No. It was there as reference. Please, undo 🙂
There was a problem hiding this comment.
There was a problem hiding this comment.
Wdyt about adding it as example in the godocs? If my future self finds this file alone here he will probably wonder again what it is.
There was a problem hiding this comment.
Apache hostname is changing because it takes the hostname of the beat and writes it in each execution at the metricset level. We discussed about leaving it like this for compatibility reasons. Here you can see that
m.Hostis passed to theeventMappingwhich sets it here
Ok, I see it also changes when running TestAll with generate, I won't change this in this PR.
|
|
||
| "github.com/stretchr/testify/assert" | ||
|
|
||
| _ "github.com/elastic/beats/metricbeat/module/apache" |
There was a problem hiding this comment.
Why does the module need to be included? Does otherwise some functionality miss?
There was a problem hiding this comment.
This is needed for the fields checks, without this the module fields are not included and then the check fails. The TestAll version includes all modules when including github.com/elastic/beats/metricbeat/include.
I was tempted of just moving this include to mb/testing, but this way we check that each module defines its own fields.
Common fields are included from mb/testing.
Not sure if there is other way of including the module fields only.
ruflin
left a comment
There was a problem hiding this comment.
LGTM
I like the hybrid we have. I can see potential that in some cases the local tests will break because of some ECS fields needed which then are not there. But lets cross this bridge when we get there.
e6ba9ed to
721ac57
Compare
8110adb to
58345ed
Compare
exekias
left a comment
There was a problem hiding this comment.
Let's see if tests pass 🙏
Add helpers to the recently added testdata framework so modules can still
be tested with
go test ./metricbeat/module/foo/....It keeps by now the
TestAlltest, we can revisit this decission in the future,while this is kept these tests will be run twice on CI.