-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Response Ops][Alerting] Initial implementation of FAAD `AlertsClient…
…` for writing generic AAD documents (#156946) Resolves #156442 ## Summary 1. Adds `shouldWriteAlerts` flag to rule type registration which defaults to `false` if not set. This prevents duplicate AAD documents from being written for the rule registry rule types that had to register with the framework in order to get their resources installed on startup. 2. Initial implementation of `AlertsClient` which primarily functions as a proxy to the `LegacyAlertsClient`. It does 2 additional thing: a. When initialized with the active & recovered alerts from the previous execution (de-serialized from the task manager state), it queries the AAD index for the corresponding alert document. b. When returning the alerts to serialize into the task manager state, it builds the alert document and bulk upserts into the AAD index. This PR does not opt any rule types into writing these generic docs but adds an example functional test that does. To test it out with the ES query rule type, add the following ``` diff --git a/x-pack/plugins/stack_alerts/server/rule_types/es_query/rule_type.ts b/x-pack/plugins/stack_alerts/server/rule_types/es_query/rule_type.ts index 214d2ee4b76..0439a576b03 100644 --- a/x-pack/plugins/stack_alerts/server/rule_types/es_query/rule_type.ts +++ b/x-pack/plugins/stack_alerts/server/rule_types/es_query/rule_type.ts @@ -187,5 +187,12 @@ export function getRuleType( }, producer: STACK_ALERTS_FEATURE_ID, doesSetRecoveryContext: true, + alerts: { + context: 'stack', + shouldWrite: true, + mappings: { + fieldMap: {}, + }, + }, }; } ``` ## To Verify - Verify that rule registry rule types still work as expected - Verify that non rule-registry rule types still work as expected - Modify a rule type to register with FAAD and write alerts and verify that the alert documents look as expected. --------- Co-authored-by: Kibana Machine <[email protected]>
- Loading branch information
1 parent
e77b45f
commit 282305f
Showing
43 changed files
with
3,932 additions
and
320 deletions.
There are no files selected for viewing
This file contains 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 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 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
23 changes: 23 additions & 0 deletions
23
x-pack/plugins/alerting/server/alerts_client/alerts_client.mock.ts
This file contains 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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
const createAlertsClientMock = () => { | ||
return jest.fn().mockImplementation(() => { | ||
return { | ||
processAndLogAlerts: jest.fn(), | ||
getTrackedAlerts: jest.fn(), | ||
getProcessedAlerts: jest.fn(), | ||
getAlertsToSerialize: jest.fn(), | ||
hasReachedAlertLimit: jest.fn(), | ||
checkLimitUsage: jest.fn(), | ||
getExecutorServices: jest.fn(), | ||
}; | ||
}); | ||
}; | ||
|
||
export const alertsClientMock = { | ||
create: createAlertsClientMock(), | ||
}; |
Oops, something went wrong.