-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented Alerting health status pusher by using task manager and s…
…tatus pooler for Kibana status plugins 'kibanahost/api/status' (#79056) (#82907) * Implemented Alerting health status pusher by using task manager and status pooler for Kibana status plugins 'kibanahost/api/status' * Exposed health task registration to alerts plugin * Fixed type error * Extended health API endpoint with info about decryption failures, added correct health task implementation * adjusted query * Tested locally and got it working as expected, fixed tests and type check * Added unit tests * Changed AlertExecutionStatusErrorReasons to be enum * Uppercase the enum * Replaced string values to enum * Fixed types * Extended AlertsClient with getHealth method * added return type to healthStatus$ * Added configurable health check interval and timestamps * Extended update core status interval to 5mins * Fixed failing tests * Registered alerts config * Fixed date for ok health state * fixed jest test * fixed task state * Fixed due to comments, moved getHealth to a plugin level * fixed type checks * Added sorting to the latest Ok state last update * adjusted error queries * Fixed jest tests * removed unused * fixed type check
- Loading branch information
1 parent
88f7ca0
commit c2d04d3
Showing
28 changed files
with
917 additions
and
81 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* 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 { configSchema } from './config'; | ||
|
||
describe('config validation', () => { | ||
test('alerts defaults', () => { | ||
const config: Record<string, unknown> = {}; | ||
expect(configSchema.validate(config)).toMatchInlineSnapshot(` | ||
Object { | ||
"healthCheck": Object { | ||
"interval": "60m", | ||
}, | ||
} | ||
`); | ||
}); | ||
}); |
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,16 @@ | ||
/* | ||
* 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 { schema, TypeOf } from '@kbn/config-schema'; | ||
import { validateDurationSchema } from './lib'; | ||
|
||
export const configSchema = schema.object({ | ||
healthCheck: schema.object({ | ||
interval: schema.string({ validate: validateDurationSchema, defaultValue: '60m' }), | ||
}), | ||
}); | ||
|
||
export type AlertsConfig = TypeOf<typeof configSchema>; |
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,221 @@ | ||
/* | ||
* 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 { savedObjectsRepositoryMock } from '../../../../../src/core/server/mocks'; | ||
import { AlertExecutionStatusErrorReasons, HealthStatus } from '../types'; | ||
import { getHealth } from './get_health'; | ||
|
||
const savedObjectsRepository = savedObjectsRepositoryMock.create(); | ||
|
||
describe('getHealth()', () => { | ||
test('return true if some of alerts has a decryption error', async () => { | ||
const lastExecutionDateError = new Date().toISOString(); | ||
const lastExecutionDate = new Date().toISOString(); | ||
savedObjectsRepository.find.mockResolvedValueOnce({ | ||
total: 1, | ||
per_page: 1, | ||
page: 1, | ||
saved_objects: [ | ||
{ | ||
id: '1', | ||
type: 'alert', | ||
attributes: { | ||
alertTypeId: 'myType', | ||
schedule: { interval: '10s' }, | ||
params: { | ||
bar: true, | ||
}, | ||
createdAt: new Date().toISOString(), | ||
actions: [ | ||
{ | ||
group: 'default', | ||
actionRef: 'action_0', | ||
params: { | ||
foo: true, | ||
}, | ||
}, | ||
], | ||
executionStatus: { | ||
status: 'error', | ||
lastExecutionDate: lastExecutionDateError, | ||
error: { | ||
reason: AlertExecutionStatusErrorReasons.Decrypt, | ||
message: 'Failed decrypt', | ||
}, | ||
}, | ||
}, | ||
score: 1, | ||
references: [ | ||
{ | ||
name: 'action_0', | ||
type: 'action', | ||
id: '1', | ||
}, | ||
], | ||
}, | ||
], | ||
}); | ||
savedObjectsRepository.find.mockResolvedValueOnce({ | ||
total: 0, | ||
per_page: 10, | ||
page: 1, | ||
saved_objects: [], | ||
}); | ||
|
||
savedObjectsRepository.find.mockResolvedValueOnce({ | ||
total: 0, | ||
per_page: 10, | ||
page: 1, | ||
saved_objects: [], | ||
}); | ||
|
||
savedObjectsRepository.find.mockResolvedValueOnce({ | ||
total: 1, | ||
per_page: 1, | ||
page: 1, | ||
saved_objects: [ | ||
{ | ||
id: '2', | ||
type: 'alert', | ||
attributes: { | ||
alertTypeId: 'myType', | ||
schedule: { interval: '1s' }, | ||
params: { | ||
bar: true, | ||
}, | ||
createdAt: new Date().toISOString(), | ||
actions: [], | ||
executionStatus: { | ||
status: 'ok', | ||
lastExecutionDate, | ||
}, | ||
}, | ||
score: 1, | ||
references: [], | ||
}, | ||
], | ||
}); | ||
const result = await getHealth(savedObjectsRepository); | ||
expect(result).toStrictEqual({ | ||
executionHealth: { | ||
status: HealthStatus.OK, | ||
timestamp: lastExecutionDate, | ||
}, | ||
readHealth: { | ||
status: HealthStatus.OK, | ||
timestamp: lastExecutionDate, | ||
}, | ||
decryptionHealth: { | ||
status: HealthStatus.Warning, | ||
timestamp: lastExecutionDateError, | ||
}, | ||
}); | ||
expect(savedObjectsRepository.find).toHaveBeenCalledTimes(4); | ||
}); | ||
|
||
test('return false if no alerts with a decryption error', async () => { | ||
const lastExecutionDateError = new Date().toISOString(); | ||
const lastExecutionDate = new Date().toISOString(); | ||
savedObjectsRepository.find.mockResolvedValueOnce({ | ||
total: 0, | ||
per_page: 10, | ||
page: 1, | ||
saved_objects: [], | ||
}); | ||
|
||
savedObjectsRepository.find.mockResolvedValueOnce({ | ||
total: 1, | ||
per_page: 1, | ||
page: 1, | ||
saved_objects: [ | ||
{ | ||
id: '1', | ||
type: 'alert', | ||
attributes: { | ||
alertTypeId: 'myType', | ||
schedule: { interval: '10s' }, | ||
params: { | ||
bar: true, | ||
}, | ||
createdAt: new Date().toISOString(), | ||
actions: [ | ||
{ | ||
group: 'default', | ||
actionRef: 'action_0', | ||
params: { | ||
foo: true, | ||
}, | ||
}, | ||
], | ||
executionStatus: { | ||
status: 'error', | ||
lastExecutionDate: lastExecutionDateError, | ||
error: { | ||
reason: AlertExecutionStatusErrorReasons.Execute, | ||
message: 'Failed', | ||
}, | ||
}, | ||
}, | ||
score: 1, | ||
references: [ | ||
{ | ||
name: 'action_0', | ||
type: 'action', | ||
id: '1', | ||
}, | ||
], | ||
}, | ||
], | ||
}); | ||
savedObjectsRepository.find.mockResolvedValueOnce({ | ||
total: 0, | ||
per_page: 10, | ||
page: 1, | ||
saved_objects: [], | ||
}); | ||
|
||
savedObjectsRepository.find.mockResolvedValueOnce({ | ||
total: 1, | ||
per_page: 1, | ||
page: 1, | ||
saved_objects: [ | ||
{ | ||
id: '2', | ||
type: 'alert', | ||
attributes: { | ||
alertTypeId: 'myType', | ||
schedule: { interval: '1s' }, | ||
params: { | ||
bar: true, | ||
}, | ||
createdAt: new Date().toISOString(), | ||
actions: [], | ||
executionStatus: { | ||
status: 'ok', | ||
lastExecutionDate, | ||
}, | ||
}, | ||
score: 1, | ||
references: [], | ||
}, | ||
], | ||
}); | ||
const result = await getHealth(savedObjectsRepository); | ||
expect(result).toStrictEqual({ | ||
executionHealth: { | ||
status: HealthStatus.Warning, | ||
timestamp: lastExecutionDateError, | ||
}, | ||
readHealth: { | ||
status: HealthStatus.OK, | ||
timestamp: lastExecutionDate, | ||
}, | ||
decryptionHealth: { | ||
status: HealthStatus.OK, | ||
timestamp: lastExecutionDate, | ||
}, | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.