forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add muting support for alerts (elastic#43712) (elastic#46951)
* Create supporting API * Rename mute terminology to mute instance to allow alert level muting * Add alert mute and unmute APIs * Add logic to handle alert muting * Add integration tests + fix AAD breaking the object * Fix failing jest tests * Fix test failures * Clear out mutedInstanceIds when muting / unmuting an alert * Skip muting / unmuting instances when alert is muted * Rename interface for alert instance * Rename functional tests to alert instance terminology * Add API integration tests for alert muting / unmuting * Apply PR feedback pt1 * Create single index record action * Function to create always firing alerts and function to generate reference * Make tests use alert utils * Rename mute / unmute alert routes * Make alerts.ts integration test use alertUtils for both spaces_only and security_and_spaces * Re-use alert utils where possible * Change muted in mapping to muteAll * Rename alert client methods to muteAll and unmuteAll * Rename files * Rename alert utils function muteAll and unmuteAll * Rename variable in task runner * Cleanup * Destructure instead of using existingObject variable
- Loading branch information
Showing
45 changed files
with
1,880 additions
and
616 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
750 changes: 486 additions & 264 deletions
750
x-pack/legacy/plugins/alerting/server/alerts_client.test.ts
Large diffs are not rendered by default.
Oops, something went wrong.
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
22 changes: 22 additions & 0 deletions
22
x-pack/legacy/plugins/alerting/server/routes/mute_all.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,22 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { createMockServer } from './_mock_server'; | ||
import { muteAllAlertRoute } from './mute_all'; | ||
|
||
const { server, alertsClient } = createMockServer(); | ||
muteAllAlertRoute(server); | ||
|
||
test('mutes an alert', async () => { | ||
const request = { | ||
method: 'POST', | ||
url: '/api/alert/1/_mute_all', | ||
}; | ||
|
||
const { statusCode } = await server.inject(request); | ||
expect(statusCode).toBe(204); | ||
expect(alertsClient.muteAll).toHaveBeenCalledWith({ id: '1' }); | ||
}); |
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,31 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import Hapi from 'hapi'; | ||
|
||
interface MuteAllRequest extends Hapi.Request { | ||
params: { | ||
id: string; | ||
}; | ||
} | ||
|
||
export function muteAllAlertRoute(server: Hapi.Server) { | ||
server.route({ | ||
method: 'POST', | ||
path: '/api/alert/{id}/_mute_all', | ||
options: { | ||
tags: ['access:alerting-all'], | ||
response: { | ||
emptyStatusCode: 204, | ||
}, | ||
}, | ||
async handler(request: MuteAllRequest, h: Hapi.ResponseToolkit) { | ||
const alertsClient = request.getAlertsClient!(); | ||
await alertsClient.muteAll(request.params); | ||
return h.response(); | ||
}, | ||
}); | ||
} |
Oops, something went wrong.