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

[Security Solution] [Platform] Fix bug where rule form would remove index field when switching between index pattern + data view #134783

Merged
merged 20 commits into from
Jul 11, 2022

Conversation

dhurley14
Copy link
Contributor

@dhurley14 dhurley14 commented Jun 20, 2022

Summary

Fixes: #135513

reset index field on rule form to empty array when it presents as null / undefined in the defaultValues prop.

Cypress tests were added as "skip" for now. Will work on them at a later date.

Checklist

Delete any items that are not applicable to this PR.

@dhurley14
Copy link
Contributor Author

@elasticmachine merge upstream

@dhurley14 dhurley14 changed the title [WIP] [Security Solution] [Platform] reset index field on rule form to empty array when it presents as nul… [Security Solution] [Platform] Fix bug where rule form would remove index field when switching between index pattern + data view Jun 29, 2022
@dhurley14 dhurley14 added v8.4.0 Feature:Detection Rules Security Solution rules and Detection Engine Team:Security Solution Platform Security Solution Platform Team review release_note:skip Skip the PR/issue when compiling release notes labels Jun 29, 2022
@dhurley14 dhurley14 marked this pull request as ready for review June 29, 2022 15:05
@dhurley14 dhurley14 requested review from a team as code owners June 29, 2022 15:05
Copy link
Contributor

@rylnd rylnd left a comment

Choose a reason for hiding this comment

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

A few things to clean up, but the attention to detail and the bugfix are mucho appreciated.

@@ -200,6 +207,101 @@ describe('Custom query rules', () => {
cy.get(ALERT_GRID_CELL).contains(this.rule.name);
});
});
describe.skip('Custom detection rules creation with data view', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a note about why these were skipped, and delete the commented code?

…re adding an exception from the rule details table alerts table would not utilize the data view defined on that rule when rendering available fields to define an exception on.
@dhurley14 dhurley14 requested a review from a team as a code owner June 30, 2022 19:13
@dhurley14
Copy link
Contributor Author

@elasticmachine merge upstream

@dhurley14
Copy link
Contributor Author

@elasticmachine merge upstream

@@ -176,14 +176,29 @@ export const AddExceptionFlyout = memo(function AddExceptionFlyout({

useEffect(() => {
const fetchSingleDataView = async () => {
if (dataViewId != null && dataViewId !== '') {
const dv = await data.dataViews.get(dataViewId);
const notNullDataViewId =
Copy link
Contributor

Choose a reason for hiding this comment

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

Hey, I have a couple of questions here.

If I look at the type AddExceptionFlyoutProps, I seedataViewId?: string;
meaning that it can be string or undefined, but in the code, you are explicitly checking for null, does there some specific reason for that?

nit: Personally I often found it difficult to read nested ternary expressions, I maybe use for this case something like:
const notNullDataViewId = dataViewId || maybeRule?.data_view_id || null

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree the ternary isn't the clearest. I'll try to re-work it. Where exactly am I doing and explicit null check? Having trouble finding that. Looks like all the checks are nullish != not !== or were you referencing somewhere else?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I get it! It was != not !== :)

}, [data.dataViews, dataViewId, setIndexPattern]);
}, [data.dataViews, dataViewId, maybeRule?.data_view_id, setIndexPattern]);

const getIndexPattern = useCallback(
Copy link
Contributor

Choose a reason for hiding this comment

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

Also here, do we really need to use getIndexPattern as a function and useCallback here?
I saw that we invoke this function once, and exactly in this component render

Probably is simplier way to write this is -

const  selectedIndexPattern= (dataViewId || maybeRule?.data_view_id) ? indexPattern
        : indexIndexPatterns

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.

Pulled down and tested - just wanted to confirm that the following is all desired behavior:

  • in rule creation:
    • switching between data views and index patterns resets the index patterns to the default
  • in rule edit:
    • (rule using data views) switching from data views to index patterns and back, index patterns show up as empty and data views remains as original value
    • (rule using index patterns) switching from index pattern to data views, my index pattern is back to the default index pattern

I know the original bug was that the form would blow up switching from the edit tabs and such, so definitely fixed here! Thanks for fighting through the forms code on this one.

@nkhristinin nkhristinin self-requested a review July 8, 2022 18:36
Copy link
Contributor

@nkhristinin nkhristinin left a comment

Choose a reason for hiding this comment

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

LGTM!

@dhurley14
Copy link
Contributor Author

@elasticmachine merge upstream

@dhurley14
Copy link
Contributor Author

Test Failures
[job] [logs] Security Solution Tests #2 / EQL rules Detection rules, EQL Creates and enables a new EQL rule
[job] [logs] Security Solution Tests #2 / Exceptions flyout flyout errors When updating an item for a list that has since been deleted Displays missing exception list error
[job] [logs] Security Solution Tests #2 / Exceptions flyout flyout errors When updating an item for a list that has since been deleted Displays missing exception list error
[job] [logs] Security Solution Tests #2 / Exceptions flyout flyout errors When updating an item with version conflict Displays version conflict error
[job] [logs] Security Solution Tests #2 / Exceptions flyout flyout errors When updating an item with version conflict Displays version conflict error

Looks like some kind of flake with cypress. These tests are passing locally..

@dhurley14 dhurley14 enabled auto-merge (squash) July 11, 2022 18:53
@kibana-ci
Copy link
Collaborator

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] Security Solution Tests #2 / Related integrations integrations not installed "before all" hook for "should display a badge with the installed integrations on the rule management page"

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 5.2MB 5.2MB +149.0B

History

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

cc @dhurley14

Copy link
Member

@spong spong left a comment

Choose a reason for hiding this comment

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

Code review LGTM! Didn't check out and test as looked like other reviewers already took care of that. Thanks for this fix @dhurley14! 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting Feature:Detection Rules Security Solution rules and Detection Engine release_note:skip Skip the PR/issue when compiling release notes review Team:Security Solution Platform Security Solution Platform Team v8.4.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Security Solution]Red Banner on switching from data view to index pattern
7 participants