[OBX-UX-MGMT] Store Alert Muted Status Directly in Alert Documents #240996
[OBX-UX-MGMT] Store Alert Muted Status Directly in Alert Documents #240996fkanout merged 51 commits intoelastic:mainfrom
Conversation
|
Pinging @elastic/obs-ux-management-team (Team:obs-ux-management) |
| logger: context.logger, | ||
| }); | ||
| } catch (error) { | ||
| context.logger.error( |
There was a problem hiding this comment.
Failing to throw here can lead to a situation where one process is successful, while the other process is not. This can lead to out of sync statuses between the rule object and the alert document. I see this pattern in a few other paces as well.
There was a problem hiding this comment.
Good point. Updated all other alert doc operations; if it fails now, it will throw an error.
There was a problem hiding this comment.
Good point. Updated all other alert doc operations; if it fails now, it will throw an error.
I don't know if this was about some previous changes.
Doesn't this mean there should be a throw after the log?
There was a problem hiding this comment.
Pull Request Overview
This PR adds functionality to update the kibana.alert.muted field in Elasticsearch when muting/unmuting alert instances and rules. The changes introduce new methods in the AlertsService class to perform Elasticsearch updateByQuery operations and integrate these methods into the mute/unmute workflows.
Key changes:
- Adds new
AlertsServicemethods:muteAlertInstance,unmuteAlertInstance,muteAllAlerts, andunmuteAllAlerts - Introduces the
ALERT_MUTEDfield constant and field mapping - Updates mute/unmute operations to call the new AlertsService methods to update Elasticsearch
- Adds comprehensive unit tests covering the new functionality and error handling
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
x-pack/platform/plugins/shared/alerting/server/alerts_service/alerts_service.ts |
Implements four new methods to update muted status in Elasticsearch via updateByQuery |
x-pack/platform/plugins/shared/alerting/server/application/rule/methods/mute_alert/mute_instance.ts |
Integrates call to muteAlertInstance when muting individual alert instances |
x-pack/platform/plugins/shared/alerting/server/application/rule/methods/unmute_alert/unmute_instance.ts |
Integrates call to unmuteAlertInstance when unmuting individual alert instances |
x-pack/platform/plugins/shared/alerting/server/application/rule/methods/mute_all/mute_all.ts |
Integrates call to muteAllAlerts when muting all alerts for a rule |
x-pack/platform/plugins/shared/alerting/server/application/rule/methods/unmute_all/unmute_all.ts |
Integrates call to unmuteAllAlerts when unmuting all alerts for a rule |
x-pack/platform/plugins/shared/alerting/server/rules_client/tests/mute_instance.test.ts |
Adds unit tests verifying the mute instance functionality including Elasticsearch operations |
x-pack/platform/plugins/shared/alerting/server/application/rule/methods/unmute_alert/unmute_instance.test.ts |
Adds unit tests verifying the unmute instance functionality including Elasticsearch operations |
x-pack/platform/plugins/shared/alerting/server/application/rule/methods/mute_all/mute_all.test.ts |
Adds unit tests verifying the mute all functionality including Elasticsearch operations |
x-pack/platform/plugins/shared/alerting/server/application/rule/methods/unmute_all/unmute_all.test.ts |
Adds unit tests verifying the unmute all functionality including Elasticsearch operations |
src/platform/packages/shared/kbn-rule-data-utils/src/default_alerts_as_data.ts |
Adds and exports the ALERT_MUTED constant |
src/platform/packages/shared/kbn-alerts-as-data-utils/src/field_maps/alert_field_map.ts |
Adds the ALERT_MUTED field mapping definition |
| [ALERT_SEVERITY_IMPROVING]: true, | ||
| [ALERT_PREVIOUS_ACTION_GROUP]: 'default', | ||
| [ALERT_MAINTENANCE_WINDOW_IDS]: [], | ||
| // @ts-ignore |
There was a problem hiding this comment.
Why is this ignored?
cnasikas
left a comment
There was a problem hiding this comment.
LGMT! Thanks for addressing the comments.
rylnd
left a comment
There was a problem hiding this comment.
This looks good from the Detection Engine side 👍 . I believe this will also help our RBAC effort, since we can now retrieve muted alerts without needing rule access.
|
@fkanout once this is merged, can we update cc @umbopepato |
Flaky Test Runner Stats🟠 Some tests failed. - kibana-flaky-test-suite-runner#9965[❌] x-pack/platform/test/alerting_api_integration/spaces_only/tests/alerting/group4/config.ts: 23/50 tests passed. |
Flaky Test Runner Stats🟠 Some tests failed. - kibana-flaky-test-suite-runner#9967[❌] x-pack/platform/test/alerting_api_integration/spaces_only/tests/alerting/group4/config.ts: 21/50 tests passed. |
Flaky Test Runner Stats🟠 Some tests failed. - kibana-flaky-test-suite-runner#9970[❌] x-pack/platform/test/alerting_api_integration/spaces_only/tests/alerting/group4/config.ts: 75/100 tests passed. |
🟢 Flaky Test Runner Stats with 100/100 tests passed |
💛 Build succeeded, but was flaky
Failed CI Steps
Test Failures
Metrics [docs]Public APIs missing comments
Async chunks
Page load bundle
History
|
Hey @rylnd, I wanted to follow up with you on that, but I got pulled into fixing a couple of flaky tests. @cnasikas wdyt? |
Flaky Test Runner Stats🟠 Some tests failed. - kibana-flaky-test-suite-runner#9974[❌] x-pack/platform/test/alerting_api_integration/spaces_only/tests/alerting/group4/config.ts: 74/100 tests passed. |
Yep, sorry if I was unclear! The current behavior for retrieving muted alerts (on After this PR, it seems as though we can address this wrinkle (that reading muted alerts implicitly requires rule access) by retrieving them via the new alert fields (although behavior for historical alerts may be trickier, it's clear that this will at least work for future alerts). So: I was asking for clarification on:
|
|
Hey @rylnd!
Yes, your understanding is correct.
Not at the moment. They are for user phasing, but I could see use cases to use the new field in the application. One of the gotchas we have is that when we do an API call to mute the alerts, we do not wait for the ES query to be successful (
I checked the code of the
What are your thoughts? I opened this issue for ResponseOps to take care of it: #245228. |
…lastic#240996) ## Summary It fixes elastic#240514 by adding a mute field to the alert doc. This addition happens on mute, mute all, unmute, and unmute all actions. Also, the related tests are updated. ### Alert doc <img width="646" height="578" alt="Screenshot 2025-10-28 at 14 07 08" src="https://github.com/user-attachments/assets/1ea6528c-da54-4507-9515-ad82f4af8f2f" /> ### While the rule still have this info <img width="607" height="377" alt="Screenshot 2025-10-28 at 14 38 06" src="https://github.com/user-attachments/assets/ee055af4-cd57-47b4-b9c9-10e511779549" /> --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Dominique Belcher <dominique.clarke@elastic.co> Co-authored-by: Maryam Saeidi <maryam.saeidi@elastic.co> Co-authored-by: Christos Nasikas <xristosnasikas@gmail.com>
Summary
It fixes #240514 by adding a mute field to the alert doc.
This addition happens on mute, mute all, unmute, and unmute all actions. Also, the related tests are updated.
Alert doc
While the rule still have this info