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

[Search] Fixes EQL search strategy #83064

Merged
merged 12 commits into from
Nov 16, 2020
Merged

Conversation

rylnd
Copy link
Contributor

@rylnd rylnd commented Nov 10, 2020

Summary

#82900
Between search types being too permissive and a lack of test coverage, a recent refactor altered the EQL search strategy responses such that some features in Security Solution were broken. This PR fixes those issues, and adds unit & functional tests to prevent regressions in this area. I also added some integration tests around EQL signal generation to generally bump coverage there as well.

Checklist

Delete any items that are not applicable to this PR.

For maintainers

The shared search utilities expect that response data exists in the
response's body field. However, in an EQL response this information also
exists as a sibling to the body field, and so we must normalize this data
into the body before we can leverage these utilities with EQL queries.
These were previously needed to work around an index resolution but, but
this has since been resolved upstream in elasticsearch via
elastic/elasticsearch#63573.
Previously, custom preview histograms were passing a data-test-subj prop
to our general histogram, but the general histogram did not know/care
about this prop and it did not become a data property on the underlying
DOM element. While most of our tests leveraged enzyme, they could still
query by this react prop and everything worked as expected.

However, now that we want to exercise this behavior in cypress, we need
something to propagate to the DOM so that we can determine which
histogram has rendered, so the prop has been updated to be
`dataTestSubj`, which then becomes a data-test-subj on the histogram's
panel. Tests have been updated accordingly.
* Asserts that the preview displays a histogram
* Asserts that no error toast is displayed
@rylnd rylnd added v8.0.0 Team:AppArch release_note:skip Skip the PR/issue when compiling release notes v7.11.0 Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. labels Nov 10, 2020
@rylnd rylnd self-assigned this Nov 10, 2020
@rylnd rylnd marked this pull request as ready for review November 10, 2020 17:02
@rylnd rylnd requested review from a team as code owners November 10, 2020 17:02
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app-arch (Team:AppArch)

@rylnd
Copy link
Contributor Author

rylnd commented Nov 10, 2020

@elasticmachine merge upstream

cy.get(EQL_QUERY_VALIDATION_SPINNER).should('not.exist');
cy.get(QUERY_PREVIEW_BUTTON).should('not.be.disabled').click({ force: true });
cy.get(EQL_QUERY_PREVIEW_HISTOGRAM).should('contain.text', 'Hits');
cy.get(NOTIFICATION_TOASTS).children().should('not.have.class', TOAST_ERROR_CLASS); // asserts no error toast on page
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@MadameSheema I wanted to call out this addition as it might be a nice sanity check throughout the suite

@@ -51,7 +51,7 @@ describe('PreviewCustomQueryHistogram', () => {

expect(wrapper.find('[data-test-subj="queryPreviewLoading"]').exists()).toBeTruthy();
expect(
wrapper.find('[data-test-subj="queryPreviewCustomHistogram"]').at(0).prop('subtitle')
wrapper.find('[dataTestSubj="queryPreviewCustomHistogram"]').at(0).prop('subtitle')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@yctercero I tried to make as few changes to these tests as possible to maintain behavior while allowing a custom data-test-subj on each histogram; see 471595f for details

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks great!

@@ -64,7 +67,7 @@ export const eqlSearchStrategyProvider = (
(response) => response.body.id,
request.id,
options
).pipe(utils.toKibanaSearchResponse());
).pipe(normalizeEqlResponse(), utils.toKibanaSearchResponse());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the crux of the fix; details are in 9e5abf4

@rylnd
Copy link
Contributor Author

rylnd commented Nov 12, 2020

@elasticmachine merge upstream


export const NOTIFICATION_TOASTS = '[data-test-subj="globalToastList"]';

export const TOAST_ERROR_CLASS = 'euiToast--danger';
Copy link
Contributor

Choose a reason for hiding this comment

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

Always a bummer when we have to use a class for part of a selector but I get when we have to do it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, this was the best identifier I could find for now. I'll make a note to add a data-test-subj upstream in notifications next time I come through here 👍

@@ -74,8 +74,6 @@ export const useEqlPreview = (): [
.search<EqlSearchStrategyRequest, EqlSearchStrategyResponse<EqlSearchResponse<Source>>>(
{
params: {
// @ts-expect-error allow_no_indices is missing on EqlSearch
allow_no_indices: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 Nice!

Copy link
Contributor

@FrankHassanabad FrankHassanabad left a comment

Choose a reason for hiding this comment

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

Reviewed code, everything looks great from my end 👍

Copy link
Contributor

@yctercero yctercero left a comment

Choose a reason for hiding this comment

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

This looks great! Pulled down and tested. The endpoint is intermittently giving a 404, but confirmed that it is due to an unrelated and known issue.

👍

@rylnd
Copy link
Contributor Author

rylnd commented Nov 13, 2020

@elasticmachine merge upstream

Copy link
Member

@lukasolson lukasolson left a comment

Choose a reason for hiding this comment

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

LGTM

@lukasolson
Copy link
Member

Just an FYI, we have another refactoring happening here: #82545. I'll update that PR with these changes, and thanks for adding the tests so we can be sure not to break this in the future!

@rylnd
Copy link
Contributor Author

rylnd commented Nov 16, 2020

@elasticmachine merge upstream

@apmmachine
Copy link
Contributor

💚 Build Succeeded

These were updated on an upstream refactor.
@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
securitySolution 7.9MB 7.9MB -141.0B

Distributable file count

id before after diff
default 42835 42836 +1

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
dataEnhanced 34.7KB 36.1KB +1.4KB

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@rylnd rylnd merged commit c6e984d into elastic:master Nov 16, 2020
@rylnd rylnd deleted the fix_eql_strategy branch November 16, 2020 21:05
rylnd added a commit that referenced this pull request Nov 17, 2020
* Ensure that data is not lost when parsing EQL responses

The shared search utilities expect that response data exists in the
response's body field. However, in an EQL response this information also
exists as a sibling to the body field, and so we must normalize this data
into the body before we can leverage these utilities with EQL queries.

* Remove unused EQL parameters

These were previously needed to work around an index resolution but, but
this has since been resolved upstream in elasticsearch via
elastic/elasticsearch#63573.

* Allow custom test subj for Preview Histogram to propagate to DOM

Previously, custom preview histograms were passing a data-test-subj prop
to our general histogram, but the general histogram did not know/care
about this prop and it did not become a data property on the underlying
DOM element. While most of our tests leveraged enzyme, they could still
query by this react prop and everything worked as expected.

However, now that we want to exercise this behavior in cypress, we need
something to propagate to the DOM so that we can determine which
histogram has rendered, so the prop has been updated to be
`dataTestSubj`, which then becomes a data-test-subj on the histogram's
panel. Tests have been updated accordingly.

* Exercise Query Preview during EQL rule creation

* Asserts that the preview displays a histogram
* Asserts that no error toast is displayed

* Add integration tests around EQL sequence signal generation

* Clearer assertion

* Simplify test assertion

* Fix typings

These were updated on an upstream refactor.

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
# Conflicts:
#	x-pack/plugins/security_solution/cypress/tasks/create_new_rule.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release_note:skip Skip the PR/issue when compiling release notes Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. v7.11.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants