-
Notifications
You must be signed in to change notification settings - Fork 505
METRON-1845 Correct Test Data Load in Elasticsearch Integration Tests #1247
Conversation
…nsformer Shade plugin transformer.
…ate properties for new client.
| } | ||
| bulkRequest.add(indexRequestBuilder); | ||
| } | ||
| public void add(UpdateDao updateDao, String indexName, String sensorType, Iterable<String> docs) |
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.
The Elasticsearch tests use this method to load test data. Rather than using the Transport client here, we use the UpdateDao to load the test data.
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.
Might it be better to just use IndexDao, which extends UpdateDao, SearchDao, RetrieveLatestDao, ColumnMetadataDao? To that end, if we're looking to route all of this through the ES component in that fashion, it might make sense to simply replace the internal private Client client; and instead use the new desired IndexDao for the proxied calls to ES. It could be setup at construction time of the component and remove the need to do the same thing for every test that uses the component class, unless they actually want to do something custom and pass in their own dao during init.
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.
Might it be better to just use IndexDao, which extends UpdateDao, SearchDao, RetrieveLatestDao, ColumnMetadataDao?
Why would that be better? It needs to do updates, so it needs an UpdateDao. Seemed logical to me.
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.
To that end, if we're looking to route all of this through the ES component in that fashion, it might make sense to simply replace the internal private Client client; and instead use the new desired IndexDao for the proxied calls to ES.
I don't think we're ready to do all that quite yet. There is still some legacy functionality in ElasticSearchComponent that uses the underlying client for the old Admin API. See close, createIndexWithMapping, and start. I would not want to update all that in this PR.
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.
The IndexDao handles all of the plumbing for the init that you're duplicating in this test class.
...est/java/org/apache/metron/elasticsearch/integration/ElasticsearchSearchIntegrationTest.java
Outdated
Show resolved
Hide resolved
...est/java/org/apache/metron/elasticsearch/integration/ElasticsearchSearchIntegrationTest.java
Outdated
Show resolved
Hide resolved
...form/metron-indexing/src/test/java/org/apache/metron/indexing/dao/UpdateIntegrationTest.java
Outdated
Show resolved
Hide resolved
| es.add(updateDao, snortIndex, "snort", snortDocuments); | ||
|
|
||
| // wait until the test documents are visible | ||
| assertEventually(() -> Assert.assertEquals(10, findAll(searchDao).getTotal())); |
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.
Unless I added this to hold up the test and wait for the tests data to be 'visible', some of the tests would reliably fail because the test data wasn't loaded.
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.
@nickwallen is it possible to parameterize the call to do something similar to this? https://github.com/apache/metron/pull/1242/files#diff-99b67fd77500d6232462dc7c27ecff67R148
It's possible this is only available on batch calls, but I wanted to mention it in case we can get away with the assertEventually calls.
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 have tried to do exactly this on a private branch that is closer to the code base in #1269. I made the integration tests supply a RefreshPolicy that was supposed to hold them up until the loaded data is discoverable/searchable.
Unfortunately, I was never able to get that to work consistently despite what the ES docs say. I still needed the assertEventually for the integration tests. I would have liked that to work.
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.
Are you able to get this to fail consistently? I ran it a number of times and couldn't get it to fail. I'm wondering if there are any other interesting entries in the logs when this occurs. These tests from ES might be of help - https://github.com/elastic/elasticsearch/pull/17986/files#diff-1c9f982dbd2f9ddb2853d135884621b5R112
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.
Are you able to get this to fail consistently? I ran it a number of times and couldn't get it to fail.
Can you describe what you did? You just removed the call to assertEventually (now line 162) and the tests continue to work reliably?
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 meant on the es client change PR, not on this PR. Yes, I had removed assertEventually calls and it consistently passed for me in the search integration test.
|
I have merged this with master to pull in the changes from #1242. This is ready for review. |
.../metron-solr/src/test/java/org/apache/metron/solr/integration/SolrUpdateIntegrationTest.java
Outdated
Show resolved
Hide resolved
...est/java/org/apache/metron/elasticsearch/integration/ElasticsearchSearchIntegrationTest.java
Outdated
Show resolved
Hide resolved
| } | ||
| bulkRequest.add(indexRequestBuilder); | ||
| } | ||
| public void add(UpdateDao updateDao, String indexName, String sensorType, Iterable<String> docs) |
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.
Might it be better to just use IndexDao, which extends UpdateDao, SearchDao, RetrieveLatestDao, ColumnMetadataDao? To that end, if we're looking to route all of this through the ES component in that fashion, it might make sense to simply replace the internal private Client client; and instead use the new desired IndexDao for the proxied calls to ES. It could be setup at construction time of the component and remove the need to do the same thing for every test that uses the component class, unless they actually want to do something custom and pass in their own dao during init.
.../metron-solr/src/test/java/org/apache/metron/solr/integration/SolrUpdateIntegrationTest.java
Outdated
Show resolved
Hide resolved
.../metron-solr/src/test/java/org/apache/metron/solr/integration/SolrUpdateIntegrationTest.java
Outdated
Show resolved
Hide resolved
…y loaded into Elasticsearch and not HBase, which matches the previous behavior
|
As a side note, I tend to like the approach of using the DAO layers to read/write the way you've done here @nickwallen . I've used this approach in the past, and it helped with test coverage and simplifying the amount of extra custom test code required. It might be worth an overall discussion on how we want to architect testing other similar endpoints going forward. |
…h to write test data, it now maintains its own. This simplifies usage of the ElasticsearchComponent by the integration tests
|
lgtm @nickwallen, +1 pending Travis |
…ation tests to define a refresh policy
|
Still +1 on latest commit - that's a nice improvement. Glad the retry policy ended up working out! |
The Elasticsearch integration tests use the Elasticsearch API to load the test data before running the tests. Loading the test data like this does not accurately reflect how the indices will appear in a production environment.
This should be changed to use our existing
ElasticsearchUpdateDaoto write the test data. This ensures that any changes made to the 'write' portion of our Elasticsearch code will function correctly with the 'read' portion. Said in a different way, this ensures that telemetry written into Elasticsearch by 'Indexing' can be read correctly by the Alerts UI.Testing
This only changes the integration tests. If the integration tests pass, we're golden.
Pull Request Checklist