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

[Alert Summaries] [FE] Move “Notify When” and throttle from rule to action #145637

Merged
merged 113 commits into from
Jan 10, 2023

Conversation

Zacqary
Copy link
Contributor

@Zacqary Zacqary commented Nov 17, 2022

Summary

Closes #143369 (blocked by #143376)

This PR updates the Stack Management UI and Observability UI to show Notify When and Throttle parameters at the action level instead of the rule level.

The rule-level Check Every dropdown is moved to the end of the rule, right above the actions form

The Security Solution UX remains unchanged, as it has a unique way of displaying action notification frequencies at the rule level. Instead, the API request has changed so that the selected action frequency will now be stored in each action's frequency param instead of at the rule level.

In all three UIs, existing rules that have legacy rule-level notifyWhen and frequency params will have these parameters seamlessly migrated to the action level when the user edits a rule.

The Rule Details page is also updated to show Notify frequencies in the Actions column instead of in the first, rule-level column.

Rule Details Page update

Screen Shot 2022-11-17 at 4 23 02 PM

Rule Form update

Screen Shot 2022-11-17 at 4 23 10 PM

Screen Shot 2022-12-27 at 1 18 12 PM

Checklist

Zacqary and others added 30 commits October 27, 2022 11:15
…tion

# Conflicts:
#	x-pack/plugins/alerting/server/routes/lib/index.ts
…tion

# Conflicts:
#	x-pack/plugins/alerting/server/task_runner/task_runner.ts
…tion

# Conflicts:
#	x-pack/plugins/alerting/server/routes/create_rule.ts
#	x-pack/plugins/alerting/server/routes/lib/index.ts
#	x-pack/plugins/alerting/server/routes/update_rule.ts
#	x-pack/plugins/alerting/server/rules_client/rules_client.ts
@XavierM
Copy link
Contributor

XavierM commented Jan 5, 2023

We tried to see if we were able to do some minimal change with the APIs to move forward in the wanted direction. However, @xcrzx is right that it won't work, so in the mean time we are going to avoid any changes in security solutions APIs. In the task runner, we will check the consumer of the rule and if the consumer is security solution then we will use/pick the global throttle and notifyWhen attributes for all the actions. We will wait on security folks to implement the full changes on the UI and detection engine APIs. Also Zachary already added this logic that we will always default the global attributes to the first actions and then if actions does NOT have frequency then we will use the global ones.

I think we will need to re-think about the bulk actions in security solution. Maybe they might be able to re-use our actions settings to make it easier for their users.

Comment on lines 227 to 229
if ('actions' in editPayload.value) {
editPayload.value.actions = editPayload.value.actions.map((a) => omit(a, 'frequency'));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this transformation needed? According to the type of actions, there is no frequency field:

(property) actions: {
    group: string;
    id: string;
    params: SavedObjectAttributes;
}[]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You asked me to remove frequency from this type definition, but the UI components from Triggers Actions UI are still going to send a frequency anyway. From what I can understand, the type system Security Solution built before Alerting/TriggersActionsUI was feature-complete includes a NormalizedRuleAction which is supposed to pull double duty for what we expect to receive from the Triggers Actions UI, and what we expect to send through Security Solution's now-redundant alerting API.

I do not know how to untangle this. I've added a comment explaining it, but at this point I have to consider perfect type definitions out of scope for this PR and recommend that your team fix it in #148414

Copy link
Contributor

Choose a reason for hiding this comment

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

I got it. Thank you for adding a comment and creating a ticket to address the discrepancy in types.

@Zacqary Zacqary requested a review from xcrzx January 9, 2023 16:58
@Zacqary Zacqary requested review from XavierM and ersin-erdal January 9, 2023 19:55
(newValue: RuleNotifyWhenType) => {
onNotifyWhenChange(newValue);
setNotifyWhenValue(newValue);
setTimeout(
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we need the setTimeout here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Needed to call both onNotifyWhenChange and onThrottleChange in the same function, otherwise React gets weird. Trying to avoid refactoring the entire form in order to make this PR work. I can add a comment

Copy link
Contributor

Choose a reason for hiding this comment

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

make sense!, let's add a comment/issue to refactor it later on

Copy link
Contributor

@XavierM XavierM left a comment

Choose a reason for hiding this comment

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

I tested it locally by creating a rule from main and then upgrade to this PR and everything is/was working as expected.
Thank you for your hard work on this BIG PR! Good job as always! and nicely done!

in this file x-pack/plugins/triggers_actions_ui/public/application/sections/action_connector_form/action_notify_when.tsx, I still think we can remove the notifyWhenValue. ;)

@Zacqary
Copy link
Contributor Author

Zacqary commented Jan 10, 2023

@elasticmachine merge upstream

@dhurley14
Copy link
Contributor

I think @elastic/security-solution-platform just needs another 24 hours to test out some edge cases around bulk-editing actions for rules but I don't see any issues coming up. I believe @banderror will comment if anything looks out of the ordinary otherwise I can approve then 👍 thanks!!

@Zacqary
Copy link
Contributor Author

Zacqary commented Jan 10, 2023

@XavierM We still need the notifyWhenValue internal state for initializing the form for a legacy alert

@kibana-ci
Copy link
Collaborator

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] Security Solution Tests #3 / timeline flyout button the (+) button popover menu owns focus

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
triggersActionsUi 477 479 +2

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
alerting 421 423 +2

Async chunks

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

id before after diff
securitySolution 12.7MB 12.7MB +304.0B
triggersActionsUi 689.2KB 698.7KB +9.6KB
total +9.9KB

Page load bundle

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

id before after diff
alerting 39.5KB 39.6KB +166.0B
triggersActionsUi 114.1KB 114.3KB +239.0B
total +405.0B
Unknown metric groups

API count

id before after diff
alerting 430 432 +2

ESLint disabled line counts

id before after diff
securitySolution 434 433 -1
triggersActionsUi 135 136 +1
total -0

Total ESLint disabled count

id before after diff
securitySolution 509 508 -1
triggersActionsUi 138 139 +1
total -0

History

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

@Zacqary Zacqary merged commit ff6024d into elastic:main Jan 10, 2023
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Jan 10, 2023
@Zacqary
Copy link
Contributor Author

Zacqary commented Jan 10, 2023

@dhurley14 Sorry this was on auto-merge and I didn't realize the Platform review was non-blocking. Let me know if any issues come up with edge cases and I'll prioritize them

@dhurley14
Copy link
Contributor

no worries! cc: @banderror

jennypavlova pushed a commit to jennypavlova/kibana that referenced this pull request Jan 13, 2023
…ction (elastic#145637)

## Summary

Closes elastic#143369 (~blocked by
elastic#143376)

This PR updates the Stack Management UI and Observability UI to show
Notify When and Throttle parameters at the **action level** instead of
the **rule level**.

The rule-level Check Every dropdown is moved to the end of the rule,
right above the actions form

The Security Solution UX remains unchanged, as it has a unique way of
displaying action notification frequencies at the rule level. Instead,
the API request has changed so that the selected action frequency will
now be stored in each action's `frequency` param instead of at the rule
level.

In all three UIs, existing rules that have legacy rule-level
`notifyWhen` and `frequency` params will have these parameters
seamlessly migrated to the action level when the user edits a rule.

The Rule Details page is also updated to show Notify frequencies in the
Actions column instead of in the first, rule-level column.

### Rule Details Page update
<img width="781" alt="Screen Shot 2022-11-17 at 4 23 02 PM"
src="https://user-images.githubusercontent.com/1445834/202573067-bc55630d-f767-4a93-8d7c-752748da25c2.png">

### Rule Form update
<img width="605" alt="Screen Shot 2022-11-17 at 4 23 10 PM"
src="https://user-images.githubusercontent.com/1445834/202573057-5d50e573-1453-4b63-8e1e-6505fa0261c6.png">
<img width="605" alt="Screen Shot 2022-12-27 at 1 18 12 PM"
src="https://user-images.githubusercontent.com/1445834/209712784-34c2384b-bcc8-4db9-a42d-052d81099a40.png">

### Checklist

- [x] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [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

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Xavier Mouligneau <xavier.mouligneau@elastic.co>
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:Alerting/RulesManagement Issues related to the Rules Management UX release_note:feature Makes this part of the condensed release notes Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) v8.7.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Alert Summaries] [FE] Move “Notify When” and throttle from rule to action