-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[RAM] Mark disabled alerts as Untracked in both Stack and o11y #164788
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
Merged
Ikuni17
merged 62 commits into
elastic:main
from
Zacqary:164059-untracked-disabled-alerts
Sep 27, 2023
Merged
Changes from all commits
Commits
Show all changes
62 commits
Select commit
Hold shift + click to select a range
a801e1e
[RAM] Mark disabled alerts as Untracked in both Stack and o11y
Zacqary 8ac28c3
Add untracked filter to alerts list
Zacqary 1db7232
Fix types
Zacqary 7ef4cd7
Update registered task type test
Zacqary 8488fe9
Fix disable rule event test
Zacqary a4ac597
Fix jest and typecheck
Zacqary 5ff37f3
Merge remote-tracking branch 'upstream/main' into 164059-untracked-di…
Zacqary 3cf2e5a
Fix jest
Zacqary 839d858
Fix jest snapshots
Zacqary d185d41
Fix registered task type test sorting
Zacqary 9f37561
Fix event validator
Zacqary f4b61ff
Fix alert summary test
Zacqary d56ab0c
Fix rule type registry jest
Zacqary dcb5a77
Merge remote-tracking branch 'upstream/main' into 164059-untracked-di…
Zacqary 99b644f
Clean up typedef and add jest test for untrack
Zacqary 72b9f60
Merge remote-tracking branch 'upstream/main' into 164059-untracked-di…
Zacqary 2db2f5f
Merge remote-tracking branch 'upstream/main' into 164059-untracked-di…
Zacqary 90acc70
Fix bad merge
Zacqary 79d6ac2
Merge remote-tracking branch 'upstream/main' into 164059-untracked-di…
Zacqary 1f243c6
Remove task spawner and use AAD methods to update alerts
Zacqary 84f707f
Remove comment
Zacqary 1de7e21
Type fix
Zacqary 2903a3b
Fix typecheck
Zacqary 87209f5
Fix Jest
Zacqary 870a131
Merge remote-tracking branch 'upstream/main' into 164059-untracked-di…
Zacqary ac26389
Iterate over indicesAlertIdMap
Zacqary ce89b91
Refactor untrack function to just use ruleId
Zacqary ddb2cd1
Restore alertUuid
Zacqary bac60b8
Fix typecheck
Zacqary a18cf49
Merge remote-tracking branch 'upstream/main' into 164059-untracked-di…
Zacqary 3ba23a2
Add logging for untrack failures
Zacqary 2fd6a11
Move alertsService to rulesClient
Zacqary a8b37f2
Fix typecheck
Zacqary 36283a5
Merge remote-tracking branch 'upstream/main' into 164059-untracked-di…
Zacqary dd412bd
Use autoRecoverAlerts as isLifecycleAlert
Zacqary dae99ee
Add test for untrackRuleIdsByIndices
Zacqary e7f3403
Typecheck fix
Zacqary 0624ea6
Handle un-flattened AAD fields
Zacqary 2d6ffd7
untrackRuleIdsByIndices -> setAlertStatusToUntracked
Zacqary 2867b41
Merge remote-tracking branch 'upstream/main' into 164059-untracked-di…
Zacqary 6259846
Fix lifecycle executor event log to support untracked alerts
Zacqary e1e74fa
Fix untracked alert table filter query
Zacqary 7ff8935
Fix typecheck
Zacqary 0b4aba7
Merge remote-tracking branch 'upstream/main' into 164059-untracked-di…
Zacqary cbb17c1
Fix typecheck
Zacqary 895e9ac
Move alert state clearing into bulkDisable function
Zacqary ef6457f
Merge remote-tracking branch 'upstream/main' into 164059-untracked-di…
Zacqary 5b384e6
Fix typecheck
Zacqary 30d4d88
Fix jest
Zacqary c2ec732
Merge remote-tracking branch 'upstream/main' into 164059-untracked-di…
Zacqary f512be7
Fix tests
Zacqary f3407f1
Merge remote-tracking branch 'upstream/main' into 164059-untracked-di…
Zacqary 645e1e6
Revert query test change
Zacqary e6ee727
Merge remote-tracking branch 'upstream/main' into 164059-untracked-di…
Zacqary 29d3192
Allow bulkDisable to take array of task ids to remove
Zacqary b94e238
Merge remote-tracking branch 'upstream/main' into 164059-untracked-di…
Zacqary 38e29a1
Revert "Allow bulkDisable to take array of task ids to remove"
Zacqary a669d03
Merge remote-tracking branch 'upstream/main' into 164059-untracked-di…
Zacqary f3b85df
Revert "Revert "Allow bulkDisable to take array of task ids to remove""
Zacqary cda79f1
Add isLifecycleAlert check to disable method
Zacqary 8df838e
Merge remote-tracking branch 'upstream/main' into 164059-untracked-di…
Zacqary c6c1ef1
Fix jest
Zacqary File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,13 @@ | |
| */ | ||
|
|
||
| import { ElasticsearchClient } from '@kbn/core/server'; | ||
| import { ALERT_RULE_UUID, ALERT_UUID } from '@kbn/rule-data-utils'; | ||
| import { | ||
| ALERT_RULE_UUID, | ||
| ALERT_STATUS, | ||
| ALERT_STATUS_UNTRACKED, | ||
| ALERT_STATUS_ACTIVE, | ||
| ALERT_UUID, | ||
| } from '@kbn/rule-data-utils'; | ||
| import { chunk, flatMap, isEmpty, keys } from 'lodash'; | ||
| import { SearchRequest } from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; | ||
| import type { Alert } from '@kbn/alerts-as-data-utils'; | ||
|
|
@@ -198,6 +204,51 @@ export class AlertsClient< | |
| return { hits, total }; | ||
| } | ||
|
|
||
| public async setAlertStatusToUntracked(indices: string[], ruleIds: string[]) { | ||
| const esClient = await this.options.elasticsearchClientPromise; | ||
| const terms: Array<{ term: Record<string, { value: string }> }> = ruleIds.map((ruleId) => ({ | ||
| term: { | ||
| [ALERT_RULE_UUID]: { value: ruleId }, | ||
| }, | ||
| })); | ||
| terms.push({ | ||
| term: { | ||
| [ALERT_STATUS]: { value: ALERT_STATUS_ACTIVE }, | ||
| }, | ||
| }); | ||
|
|
||
| try { | ||
| // Retry this updateByQuery up to 3 times to make sure the number of documents | ||
| // updated equals the number of documents matched | ||
| for (let retryCount = 0; retryCount < 3; retryCount++) { | ||
| const response = await esClient.updateByQuery({ | ||
| index: indices, | ||
| allow_no_indices: true, | ||
| body: { | ||
| conflicts: 'proceed', | ||
| script: { | ||
| source: UNTRACK_UPDATE_PAINLESS_SCRIPT, | ||
| lang: 'painless', | ||
| }, | ||
| query: { | ||
| bool: { | ||
| must: terms, | ||
| }, | ||
| }, | ||
| }, | ||
| }); | ||
| if (response.total === response.updated) break; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we log indices and ruleIds when we have to retry if we have SDH |
||
| this.options.logger.warn( | ||
| `Attempt ${retryCount + 1}: Failed to untrack ${ | ||
| (response.total ?? 0) - (response.updated ?? 0) | ||
| } of ${response.total}; indices ${indices}, ruleIds ${ruleIds}` | ||
| ); | ||
| } | ||
| } catch (err) { | ||
| this.options.logger.error(`Error marking ${ruleIds} as untracked - ${err.message}`); | ||
| } | ||
| } | ||
|
|
||
| public report( | ||
| alert: ReportedAlert< | ||
| AlertData, | ||
|
|
@@ -562,3 +613,11 @@ export class AlertsClient< | |
| return this._isUsingDataStreams; | ||
| } | ||
| } | ||
|
|
||
| const UNTRACK_UPDATE_PAINLESS_SCRIPT = ` | ||
| // Certain rule types don't flatten their AAD values, apply the ALERT_STATUS key to them directly | ||
| if (!ctx._source.containsKey('${ALERT_STATUS}') || ctx._source['${ALERT_STATUS}'].empty) { | ||
| ctx._source.${ALERT_STATUS} = '${ALERT_STATUS_UNTRACKED}'; | ||
| } else { | ||
| ctx._source['${ALERT_STATUS}'] = '${ALERT_STATUS_UNTRACKED}' | ||
| }`; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.