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

[RAM][Maintenance Window] Maintenance window scoped query task manager changes #172252

Merged

Conversation

JiaweiWu
Copy link
Contributor

Summary

Resolves: #164255

This is part 3/3 of the maintenance window scoped query PR. This change contains only the task manager changes and has no dependency on other PRs. To test the changes in this PR, I recommend using this branch #172117 which has all of the frontend changes and the changes in this PR.

This PR adds support for maintenance window scoped query in the task manager. To do this, we need to perform a fetch on the new persisted alerts with the scoped query as filters. We then must save these alerts again with the update maintenance window IDs.

Checklist

@JiaweiWu JiaweiWu added release_note:skip Skip the PR/issue when compiling release notes Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) Feature:Alerting/RulesManagement Issues related to the Rules Management UX v8.12.0 labels Nov 30, 2023
@JiaweiWu JiaweiWu requested a review from a team as a code owner November 30, 2023 07:03
@elasticmachine
Copy link
Contributor

Pinging @elastic/response-ops (Team:ResponseOps)

Copy link
Contributor

@ymao1 ymao1 left a comment

Choose a reason for hiding this comment

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

Did an initial code review and a bare bones verification and I think the approach makes sense overall given the constraints we have to work with. Left a few nits

@JiaweiWu
Copy link
Contributor Author

@elasticmachine merge upstream

@JiaweiWu JiaweiWu requested a review from ymao1 December 1, 2023 02:27
Copy link
Contributor

@ymao1 ymao1 left a comment

Choose a reason for hiding this comment

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

Code is looking good! Left a bunch of nits and then one comment about handling possible unhandled promise rejection.

To verify, I created a maintenance window that applied to stack rules with kibana.alert.name: "test". Then I created an ES query rule with name "test" and with some logging, see it generate a new alert and the appropriate maintenance window ID gets set for the new alert in memory. However, when I check the alert document, I see "kibana.alert.maintenance_window_ids": null,, so it looks like the update by query is not working as expected?

x-pack/plugins/alerting/server/task_runner/task_runner.ts Outdated Show resolved Hide resolved
x-pack/plugins/alerting/server/task_runner/task_runner.ts Outdated Show resolved Hide resolved
});
});

describe('updateAlertsMaintenanceWindowIdByScopedQuery', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

can we add a test for behavior when ES throws an error on the update by query?

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 added a test to the inner function since we never await on updateAlertsMaintenanceWindowIdByScopedQuery so it's a bit hard to test the reject case.

@JiaweiWu
Copy link
Contributor Author

JiaweiWu commented Dec 1, 2023

@elasticmachine merge upstream

@JiaweiWu
Copy link
Contributor Author

JiaweiWu commented Dec 1, 2023

Code is looking good! Left a bunch of nits and then one comment about handling possible unhandled promise rejection.

To verify, I created a maintenance window that applied to stack rules with kibana.alert.name: "test". Then I created an ES query rule with name "test" and with some logging, see it generate a new alert and the appropriate maintenance window ID gets set for the new alert in memory. However, when I check the alert document, I see "kibana.alert.maintenance_window_ids": null,, so it looks like the update by query is not working as expected?

I had a small bug in the updateByQuery script. It has been fixed and I added a test to verify that the alert docs are indeed updated.

@JiaweiWu JiaweiWu requested a review from ymao1 December 1, 2023 20:04
@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

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 782 783 +1
Unknown metric groups

API count

id before after diff
alerting 813 814 +1

History

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

Copy link
Contributor

@ymao1 ymao1 left a comment

Choose a reason for hiding this comment

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

LGTM. Verified that MW with scoped query is correctly applied to new alerts that match the query and not applied to new alerts that don't match the query.

@JiaweiWu JiaweiWu merged commit 75e34f6 into elastic:main Dec 4, 2023
30 checks passed
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Dec 4, 2023
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:skip Skip the PR/issue when compiling release notes Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) v8.12.0
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

[Maintenance Windows] Support "filtering" what Rules/Alerts Maintenance Windows affect
5 participants