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

[Detection Engine] ML Rule Alert Suppression - Followup #188267

Merged
merged 11 commits into from
Jul 23, 2024

Conversation

rylnd
Copy link
Contributor

@rylnd rylnd commented Jul 12, 2024

Summary

This PR is a followup to #181926. A demo instance can be found here. It includes the following changes:

  • Refactoring some Rule Form logic with useMemo
  • Adds FTR tests validating ML Suppression supports alert enrichment
  • Disables ML Suppression fields as a group
  • Only disables ML Suppression UI when no fields info is available
    • After discussing this behavior with @vitaliidm , I was going to add a special case for a single job being selected that has field info (and not disabling then), but since those fields are tied specifically to the selected jobs, I see no reason not to base the enablement of that UI purely on the presence/absence of field information (rather than on jobs status, as it was previously). The warning when not all jobs are started will still be displayed. cc @approksiu .
    • Addressed in f0bd4b9.

Checklist

  • Unit or functional tests were updated or added to match the most common scenarios
  • Any UI touched in this PR is usable by keyboard only (learn more about keyboard accessibility)
  • Any UI touched in this PR does not create any new axe failures (run axe in browser: FF, Chrome)

rylnd added 2 commits July 12, 2024 15:33
It would be painful to try to write a pure function that captures this
same logic (see the deps lists), but as a compromise we can at least
encapsulate these in functions and use more expressive implementation.
This was requested during review of elastic#181926, and I'm circling back to
that now.
@rylnd rylnd self-assigned this Jul 12, 2024
We did not previously extend our full disabling logic to all suppression
fields. Now, when we determine that alert suppression is
invalid/disabled, we disable all those relevant fields together.

This commit accomplishes the above, and also factors out some shared
boolean logic into the more general `areSuppressionFieldsDisabled`
boolean, which is shared by most of these fields.
@rylnd
Copy link
Contributor Author

rylnd commented Jul 16, 2024

/ci

@rylnd rylnd marked this pull request as ready for review July 16, 2024 21:47
@rylnd rylnd requested a review from a team as a code owner July 16, 2024 21:47
@rylnd rylnd requested a review from vitaliidm July 16, 2024 21:47
@rylnd rylnd added v8.15.0 backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) chore Feature:ML Rule Security Solution Machine Learning rule type Feature:Alert Suppression Security Solution Alert Suppression feature release_note:skip Skip the PR/issue when compiling release notes labels Jul 16, 2024
/**
* If we don't have ML field information, users can't meaningfully interact with these fields */
const areSuppressionFieldsDisabledByMlFields =
isMlRule(ruleType) && (noMlJobsStarted || mlFieldsLoading || !mlSuppressionFields.length);
Copy link
Contributor

Choose a reason for hiding this comment

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

Screenshot 2024-07-17 at 12 05 43

I added two jobs (one running, one not). Selected field, configured suppression and then removed running job.
So, suppression config is disabled, but field actually was from a running job.

If I save rule, with "disabled" suppression and start job - suppression would work, but the field stored there would be from another job.

I can't clear this suppression on form , because when I removed job, it is still disabled
Screenshot 2024-07-17 at 12 13 15

So, I have to add the same running job to clear it.

Similar can happen when user changes index, without adjusting suppression fields. But in this case, suppression controls are not disabled and user can easily change those fields
Here, after removing running job, controls become disabled. It requires user to add this job again to change fields or start another.
I am not sure, how critical it can be - just an observation on behaviour.
What do you think about 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.

Thanks for calling this out. I agree that the UX wasn't great, so I fixed it in 8b6c460.

rylnd added 3 commits July 17, 2024 16:19
…rrectly enabled

When a non-threshold suppression field had been selected, the previous
logic was causing the duration input to be enabled, because it was based
on the non-threshold suppression input.
This commit abstracts a `areSuppressionFieldsSelected` boolean to
capture the case where we can't disable fields due to the user needing
to be able to change them. We then refactored the relevant predicates in
terms of that new boolean.
Now that these are refactored in terms of more general predicates, it
doesn't make much sense to enumerate all these situations for each
variable, nor are these lists particularly helpful to understanding the
code.

So that we only have one source of truth to maintain moving forward (the
code itself), I'm removing these "leaf" comments and instead annotating
their parents.
@rylnd rylnd requested a review from vitaliidm July 17, 2024 21:43
@rylnd
Copy link
Contributor Author

rylnd commented Jul 17, 2024

@vitaliidm thanks for the feedback, your comments should now be addressed. Please take another look when you can!

@elasticmachine
Copy link
Contributor

elasticmachine commented Jul 17, 2024

⏳ Build in-progress, with failures

Failed CI Steps

Test Failures

  • [job] [logs] Serverless Detection Engine - Security Solution Cypress Tests #5 / Detection threshold rules, edit with suppression enabled displays suppress options correctly on edit form displays suppress options correctly on edit form
  • [job] [logs] Detection Engine - Security Solution Cypress Tests #5 / Detection threshold rules, edit with suppression enabled displays suppress options correctly on edit form displays suppress options correctly on edit form
  • [job] [logs] Serverless Detection Engine - Security Solution Cypress Tests #5 / Detection threshold rules, edit without suppression enables suppression on time interval enables suppression on time interval
  • [job] [logs] Detection Engine - Security Solution Cypress Tests #5 / Detection threshold rules, edit without suppression enables suppression on time interval enables suppression on time interval
  • [job] [logs] Jest Tests #11 / Template fields renders template fields with existing value
  • [job] [logs] Serverless Detection Engine - Security Solution Cypress Tests #4 / Threshold rules Creates a new threshold rule with suppression enabled Creates a new threshold rule with suppression enabled
  • [job] [logs] Detection Engine - Security Solution Cypress Tests #4 / Threshold rules Creates a new threshold rule with suppression enabled Creates a new threshold rule with suppression enabled

History

cc @rylnd

@rylnd
Copy link
Contributor Author

rylnd commented Jul 18, 2024

@vitaliidm hold off on that review. As the latest build shows, I've still got some bugs 👀

@vitaliidm vitaliidm removed their request for review July 18, 2024 13:13
rylnd added 2 commits July 18, 2024 13:37
Besides `areSuppressionFieldsSelected` not being defined as the comment
documents, we had an issue where threshold suppression fields were not
properly disabled in the default state (which also had some consequences
for switching between rule types). This is now fixed, and IMO these
predicates now read much better as well.
@rylnd rylnd enabled auto-merge (squash) July 18, 2024 20:22
@rylnd rylnd requested a review from vitaliidm July 18, 2024 20:23
!isAlertSuppressionLicenseValid ||
!groupByFields.length;
areSuppressionFieldsDisabled || isThresholdSuppressionDisabled || !areSuppressionFieldsSelected;
const isMissingFieldsDisabled = areSuppressionFieldsDisabled || !areSuppressionFieldsSelected;

Copy link
Contributor

@vitaliidm vitaliidm Jul 19, 2024

Choose a reason for hiding this comment

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

Screen.Recording.2024-07-19.at.09.54.54.mov

I see some confusing behaviour here.

a1 job is started
Spike in logon job is not installed

When only one selected everything seemed to work as expected.

When both of them - behaviour becomes unpredictable. When I removed a1 job, selected field still there, dropdown shows list of available fields(presumably from removed a1 job). No warnings that some of the job not started
When I deselect suppression fields - control becomes disabled with tooltip message

Copy link
Contributor

Choose a reason for hiding this comment

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

Spike in logon events is not installed, when selected with running job, no warning is displayed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@vitaliidm did you notice that this behavior was specific to custom ML jobs? I can't reproduce that with just prebuilt ones.

  1. Can you provide the steps you took to create that a1 job?
  2. Can you reproduce this behavior in main, or just on this branch?

Copy link
Contributor

@vitaliidm vitaliidm Jul 19, 2024

Choose a reason for hiding this comment

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

@rylnd

  1. Job was created through wizard
Screen.Recording.2024-07-19.at.17.02.40.mov
  1. This is behaviour in main
Screen.Recording.2024-07-19.at.16.59.43.mov

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@vitaliidm this is certainly an interesting one that I hadn't encountered. I'm still not able to reproduce; after creating a custom job (and getting it in a persistent "started" state), I see the expected behavior:

Screen.Recording.2024-07-19.at.4.51.00.PM.mov

And you can see in the following screenshot that the custom job shows up with the rest of the jobs and is otherwise treated no differently (which was my previous theory on this behavior):

Screenshot 2024-07-19 at 4 48 39 PM

So perhaps there's something in your job's state that's different than what I'm seeing, or our environments are otherwise different? Let's pair on Monday and figure it out.

rylnd added 2 commits July 22, 2024 12:17
We continue to show a warning if not all of the selected jobs are
running, but we no longer disable the UI based purley on whether none of
the selected jobs are running; it's now based purely on whether we have
fields to display.
I had previously used the concept of "some jobs started" because that is
the case that we want to warn users about, and it was conceptually
simpler than "not all jobs started."

However, from both the perspective of the hook and the consumer, it
makes more sense to return an "all jobs started" boolean and use that as
necessary.

This is logically equivalent to the previous commit, just nicer to read.
@rylnd rylnd requested a review from a team as a code owner July 22, 2024 17:31
@kibana-ci
Copy link
Collaborator

💚 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 17.3MB 17.3MB -39.0B

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

cc @rylnd

@rylnd rylnd requested a review from vitaliidm July 22, 2024 19:02
@rylnd rylnd merged commit e2150de into elastic:main Jul 23, 2024
39 checks passed
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Jul 23, 2024
## Summary

This PR is a followup to elastic#181926. It includes the following changes:

- Refactoring some Rule Form logic with `useMemo`
- Requested [in this
discussion](elastic#181926 (comment))
  - Addressed in a5fcf4d
- Adds FTR tests validating ML Suppression supports alert enrichment
- Requested [during previous
review](elastic#181926 (comment))
  - Addressed in d5aa551
- Disables ML Suppression fields as a group
- Requested in [this
comment](elastic#181926 (comment))
  - Addressed by 983945b

### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [x] Any UI touched in this PR is usable by keyboard only (learn more
about [keyboard accessibility](https://webaim.org/techniques/keyboard/))
- [x] Any UI touched in this PR does not create any new axe failures
(run axe in browser:
[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),
[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))

(cherry picked from commit e2150de)
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.15

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

@vitaliidm
Copy link
Contributor

Issue has been discovered: ML warning appears at other rule types
Screenshot 2024-07-23 at 10 33 35

@rylnd rylnd deleted the rylnd/ml_suppression_followup branch July 25, 2024 19:06
rylnd added a commit that referenced this pull request Jul 25, 2024
… for non-ML rule types (#189003)

Followup to #188267. A demo
instance with these changes can be found
[here](https://rylnd-pr-189003-fix-sticky-ml-warning.kbndev.co/app/security/rules/create).

When not all ML jobs are started, we display a message conveying that
the list of suppression fields might not be complete. In the case of a
non-ML rule, this warning isn't helpful and should be hidden. It also
only shows the warning if one more more ML jobs have been selected.
rylnd added a commit to rylnd/kibana that referenced this pull request Jul 25, 2024
## Summary

This PR is a followup to elastic#181926. It includes the following changes:

- Refactoring some Rule Form logic with `useMemo` 
- Requested [in this
discussion](elastic#181926 (comment))
  - Addressed in a5fcf4d
- Adds FTR tests validating ML Suppression supports alert enrichment
- Requested [during previous
review](elastic#181926 (comment))
  - Addressed in d5aa551
- Disables ML Suppression fields as a group
- Requested in [this
comment](elastic#181926 (comment))
  - Addressed by 983945b


### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [x] Any UI touched in this PR is usable by keyboard only (learn more
about [keyboard accessibility](https://webaim.org/techniques/keyboard/))
- [x] Any UI touched in this PR does not create any new axe failures
(run axe in browser:
[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),
[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))
rylnd added a commit to rylnd/kibana that referenced this pull request Jul 25, 2024
… for non-ML rule types (elastic#189003)

Followup to elastic#188267. A demo
instance with these changes can be found
[here](https://rylnd-pr-189003-fix-sticky-ml-warning.kbndev.co/app/security/rules/create).

When not all ML jobs are started, we display a message conveying that
the list of suppression fields might not be complete. In the case of a
non-ML rule, this warning isn't helpful and should be hidden. It also
only shows the warning if one more more ML jobs have been selected.
rylnd added a commit that referenced this pull request Jul 25, 2024
## Summary

This is a manual backport of both #188267 and #189003 (both of which are
now in `main`) into the 8.15 branch.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) chore Feature:Alert Suppression Security Solution Alert Suppression feature Feature:ML Rule Security Solution Machine Learning rule type release_note:skip Skip the PR/issue when compiling release notes v8.15.0 v8.16.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants