[RAM] Add bulk action to Untrack selected alerts#167579
[RAM] Add bulk action to Untrack selected alerts#167579XavierM merged 54 commits intoelastic:mainfrom
Conversation
🤖 GitHub commentsExpand to view the GitHub comments
Just comment with:
|
| } | ||
| } | ||
|
|
||
| public async setAlertsToUntracked(opts: SetAlertsToUntrackedOpts) { |
There was a problem hiding this comment.
I'm unsure that this method actually belongs in AlertsService rather than AlertsClient, because it interacts with and updates alert data. However, we want to make it available without being connected to a Rule (which is a prerequisite for creating an AlertsClient), and it also doesn't actually need a corresponding Rule to operate.
Not sure if there's a specific design goal re: Service vs. Client that I'm violating here with this, but it was the most expedient way I could think of to get this to work.
There was a problem hiding this comment.
This is probably fine for now. The initial intent was for the AlertService to handle all of the framework level resource installation that's required to write alerts for a rule and then AlertsClient to be the way for the alerting task runner to interact with those alerts. As you point out, there are use cases for users interacting directly with alerts. In the future, we may want to consolidate all of those interactions into a separate client but this is fine for now.
|
Pinging @elastic/response-ops (Team:ResponseOps) |
There was a problem hiding this comment.
Tested locally and for happy path it worked fine.
- But the Mark as untracked option for recovered alerts:
When I applied it, it showed a successful message:
Can you please fix that?
- Another issue was related to AlertSummaryWidget component:
Number of active alerts includes the untracked alerts as well, can it be fixed in this PR? If it is out of scope, would you please create an issue?
Questions:
- What is the difference between
AlertsClientandAlertsService? - @maciejforcone @katrin-freihofner Should we count untracked alerts in the total number of alerts in the Alert Summary Widget? [Out of scope of this PR]
| Alert Summary Widget | Alerts |
|---|---|
![]() |
![]() |
| </EuiContextMenuItem> | ||
| ), | ||
| ], | ||
| ...(ruleSavePermissions |
There was a problem hiding this comment.
What exactly is this permission? Is this different from the permission for adding an alert to a case?
There was a problem hiding this comment.
I think this is the permission for editing rules. I didn't see a permissions requirement spec'd out at all so I wasn't sure which one to use, but I can switch it to the case permission, that probably makes more sense.
There was a problem hiding this comment.
@maryam-saeidi How's tying this to the update case permission sound? Or do we need to create an entirely new permission for this?
There was a problem hiding this comment.
Talked to @XavierM, turns out we don't need permissions on the client side because the user can only see alerts from rules that they're authorized to interact with. I need to implement some auth checking on the server side though.
x-pack/plugins/alerting/server/alerts_service/lib/set_alerts_to_untracked.ts
Outdated
Show resolved
Hide resolved
I was wondering that myself. As far as I can tell the The EDIT Sorry missed @ymao1's explanation: #167579 (comment) |
| ) => { | ||
| router.post( | ||
| { | ||
| path: `${INTERNAL_BASE_ALERTING_API_PATH}/rules/_bulk_untrack`, |
There was a problem hiding this comment.
I think we should not use rules but alerts here
| path: `${INTERNAL_BASE_ALERTING_API_PATH}/rules/_bulk_untrack`, | |
| path: `${INTERNAL_BASE_ALERTING_API_PATH}/alerts/_bulk_untrack`, |
...ugins/triggers_actions_ui/public/application/sections/alerts_table/hooks/use_bulk_actions.ts
Show resolved
Hide resolved
| }, | ||
| ]; | ||
|
|
||
| if (ensureAuthorized) { |
There was a problem hiding this comment.
ensureAuthorized should always be there if we can, we need to enforce this check!
There was a problem hiding this comment.
setAlertsToUntracked is sometimes called through untrackRuleAlerts, which is only ever called after a different ensureAuthorized method has run
There was a problem hiding this comment.
let's go with the way it is and we can refactor it later on
ymao1
left a comment
There was a problem hiding this comment.
Tried out all the disable/delete/untrack scenarios. Left some comments about unit tests that I'm fine with being addressed as a follow up issue.
Would like to see two things addressed:
- try/catch around the callback function that updates the task manager state
- deleting a rule did not mark the associated active alerts as untracked when I tested it.
x-pack/plugins/alerting/server/alerts_service/lib/set_alerts_to_untracked.test.ts
Show resolved
Hide resolved
x-pack/plugins/alerting/server/application/rule/methods/bulk_untrack/bulk_untrack_alerts.ts
Outdated
Show resolved
Hide resolved
|
Pinging @elastic/apm-ui (Team:APM) |
…into bulkaction-164059
achyutjhunjhunwala
left a comment
There was a problem hiding this comment.
LGTM from APM side
💛 Build succeeded, but was flaky
Failed CI Steps
Test Failures
Metrics [docs]Module Count
Public APIs missing comments
Async chunks
Page load bundle
History
To update your PR or re-run it, just comment with: |




Summary
Part of #164059
This PR:
setAlertStatusToUntrackedfunction from theAlertsClientinto theAlertsService. This function doesn't actually need any Rule IDs to do what it's supposed to do, only indices and Alert UUIDs. Therefore, we want to make it possible to use outside of a createdAlertsClient, which requires a Rule to initialize.alertUuidspresent onindices. Both of these pieces of information are readily available from the ECS fields sent to the alert table component, from where this bulk action will be called.setAlertStatusToUntrackedquery to look for alert UUIDs instead of alert instance IDs. [RAM] Mark disabled alerts as Untracked in both Stack and o11y #164788 dealt with untracking alerts that were bound to a single rule at a time, but this PR could be untracking alerts generated by many different rules at once. Multiple rules may generate the same alert instance ID names with different UUIDs, so using UUID increases the specificity and prevents us from untracking alert instances that the user didn't intend.bulkUpdateStatemethod to the task scheduler. [RAM] Mark disabled alerts as Untracked in both Stack and o11y #164788 modified thebulkDisablemethod to clear untracked alerts from task states, but this new method allows us to untrack a given set of alert instances without disabling the task that generated them.Why omit rule ID from this API?
The rule ID is technically readily available from the alert table, but it becomes redundant when we already have immediate access to the alert document's index. #164788 used the rule ID to get the
ruleTypeIdand turn this into a corresponding index, which we don't have to do anymore.Furthermore, it helps to omit the rule ID from the
updateByQueryrequest, because the user can easily select alerts that were generated by a wide variety of different rules, and untrack them all at once. We could include the rule ID in a separateshouldquery, but this adds needless complexity to the query.We do need to know the rule ID after performing
updateByQuery, because it corresponds to the task state we want to modify, but it's easier to retrieve this using the same query params provided.Checklist
Delete any items that are not applicable to this PR.