-
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.
[ResponseOps][flapping] change action behavior when flapping (#147810)
Resolves #143445 ## Summary This pr changes the behavior of alerting actions respecting flapping. To recover a flapping alert the alert must be reported as recovered for 4 (this will be configurable eventually) consecutive runs before the framework makes the alert as recovered. Link to a spreadsheet that helps vizualize the changes: https://docs.google.com/spreadsheets/d/1amoUDFx-Sdxirnabd_E4OSnyur57sLhY6Ce79oDYgJA/edit#gid=0 Also Resolves #147205 to recover those alerts ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios ### To verify - Create an alert and let it run until it gets into a flapping state (changes from active/recovered at least 4 times) - Once flapping, verify the following cases: - Verify that a recovered alert will be returned as an active notification 3 times before finally recovering - Verify that an alert that does not recover 3 times before an active alert is reported never reports as a recovered alert Co-authored-by: kibanamachine <[email protected]> Co-authored-by: Ying Mao <[email protected]>
- Loading branch information
1 parent
a78fece
commit 000ba78
Showing
21 changed files
with
688 additions
and
30 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
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
146 changes: 146 additions & 0 deletions
146
x-pack/plugins/alerting/server/lib/get_alerts_for_notification.test.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,146 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
import { getAlertsForNotification } from '.'; | ||
import { Alert } from '../alert'; | ||
|
||
describe('getAlertsForNotification', () => { | ||
test('should set pendingRecoveredCount to zero for all active alerts', () => { | ||
const alert1 = new Alert('1', { meta: { flapping: true, pendingRecoveredCount: 3 } }); | ||
const alert2 = new Alert('2', { meta: { flapping: false } }); | ||
|
||
const { newAlerts, activeAlerts } = getAlertsForNotification( | ||
'default', | ||
{ | ||
'1': alert1, | ||
}, | ||
{ | ||
'1': alert1, | ||
'2': alert2, | ||
}, | ||
{}, | ||
{} | ||
); | ||
expect(newAlerts).toMatchInlineSnapshot(` | ||
Object { | ||
"1": Object { | ||
"meta": Object { | ||
"flapping": true, | ||
"flappingHistory": Array [], | ||
"pendingRecoveredCount": 0, | ||
}, | ||
"state": Object {}, | ||
}, | ||
} | ||
`); | ||
expect(activeAlerts).toMatchInlineSnapshot(` | ||
Object { | ||
"1": Object { | ||
"meta": Object { | ||
"flapping": true, | ||
"flappingHistory": Array [], | ||
"pendingRecoveredCount": 0, | ||
}, | ||
"state": Object {}, | ||
}, | ||
"2": Object { | ||
"meta": Object { | ||
"flapping": false, | ||
"flappingHistory": Array [], | ||
"pendingRecoveredCount": 0, | ||
}, | ||
"state": Object {}, | ||
}, | ||
} | ||
`); | ||
}); | ||
|
||
test('should return flapping pending recovered alerts as active alerts', () => { | ||
const alert1 = new Alert('1', { meta: { flapping: true, pendingRecoveredCount: 3 } }); | ||
const alert2 = new Alert('2', { meta: { flapping: false } }); | ||
const alert3 = new Alert('3', { meta: { flapping: true } }); | ||
|
||
const { newAlerts, activeAlerts, recoveredAlerts, currentRecoveredAlerts } = | ||
getAlertsForNotification( | ||
'default', | ||
{}, | ||
{}, | ||
{ | ||
'1': alert1, | ||
'2': alert2, | ||
'3': alert3, | ||
}, | ||
{ | ||
'1': alert1, | ||
'2': alert2, | ||
'3': alert3, | ||
} | ||
); | ||
|
||
expect(newAlerts).toMatchInlineSnapshot(`Object {}`); | ||
expect(activeAlerts).toMatchInlineSnapshot(` | ||
Object { | ||
"3": Object { | ||
"meta": Object { | ||
"flapping": true, | ||
"flappingHistory": Array [], | ||
"pendingRecoveredCount": 1, | ||
}, | ||
"state": Object {}, | ||
}, | ||
} | ||
`); | ||
expect(Object.values(activeAlerts).map((a) => a.getScheduledActionOptions())) | ||
.toMatchInlineSnapshot(` | ||
Array [ | ||
Object { | ||
"actionGroup": "default", | ||
"context": Object {}, | ||
"state": Object {}, | ||
}, | ||
] | ||
`); | ||
expect(recoveredAlerts).toMatchInlineSnapshot(` | ||
Object { | ||
"1": Object { | ||
"meta": Object { | ||
"flapping": true, | ||
"flappingHistory": Array [], | ||
"pendingRecoveredCount": 0, | ||
}, | ||
"state": Object {}, | ||
}, | ||
"2": Object { | ||
"meta": Object { | ||
"flapping": false, | ||
"flappingHistory": Array [], | ||
}, | ||
"state": Object {}, | ||
}, | ||
} | ||
`); | ||
expect(currentRecoveredAlerts).toMatchInlineSnapshot(` | ||
Object { | ||
"1": Object { | ||
"meta": Object { | ||
"flapping": true, | ||
"flappingHistory": Array [], | ||
"pendingRecoveredCount": 0, | ||
}, | ||
"state": Object {}, | ||
}, | ||
"2": Object { | ||
"meta": Object { | ||
"flapping": false, | ||
"flappingHistory": Array [], | ||
}, | ||
"state": Object {}, | ||
}, | ||
} | ||
`); | ||
}); | ||
}); |
Oops, something went wrong.