* 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
76 lines
2.4 KiB
TypeScript
76 lines
2.4 KiB
TypeScript
/*
|
|
* 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 { alertsClientMock } from './alerts_client.mock';
|
|
import { PluginSetupContract, PluginStartContract } from './plugin';
|
|
import { AlertInstance } from './alert_instance';
|
|
import {
|
|
elasticsearchServiceMock,
|
|
savedObjectsClientMock,
|
|
} from '../../../../src/core/server/mocks';
|
|
|
|
export { alertsClientMock };
|
|
|
|
const createSetupMock = () => {
|
|
const mock: jest.Mocked<PluginSetupContract> = {
|
|
registerType: jest.fn(),
|
|
};
|
|
return mock;
|
|
};
|
|
|
|
const createStartMock = () => {
|
|
const mock: jest.Mocked<PluginStartContract> = {
|
|
listTypes: jest.fn(),
|
|
getAlertsClientWithRequest: jest.fn().mockResolvedValue(alertsClientMock.create()),
|
|
getFrameworkHealth: jest.fn(),
|
|
};
|
|
return mock;
|
|
};
|
|
|
|
export type AlertInstanceMock = jest.Mocked<AlertInstance>;
|
|
const createAlertInstanceFactoryMock = () => {
|
|
const mock = {
|
|
hasScheduledActions: jest.fn(),
|
|
isThrottled: jest.fn(),
|
|
getScheduledActionOptions: jest.fn(),
|
|
unscheduleActions: jest.fn(),
|
|
getState: jest.fn(),
|
|
scheduleActions: jest.fn(),
|
|
replaceState: jest.fn(),
|
|
updateLastScheduledActions: jest.fn(),
|
|
toJSON: jest.fn(),
|
|
toRaw: jest.fn(),
|
|
};
|
|
|
|
// support chaining
|
|
mock.replaceState.mockReturnValue(mock);
|
|
mock.unscheduleActions.mockReturnValue(mock);
|
|
mock.scheduleActions.mockReturnValue(mock);
|
|
|
|
return (mock as unknown) as AlertInstanceMock;
|
|
};
|
|
|
|
const createAlertServicesMock = () => {
|
|
const alertInstanceFactoryMock = createAlertInstanceFactoryMock();
|
|
return {
|
|
alertInstanceFactory: jest
|
|
.fn<jest.Mocked<AlertInstance>, [string]>()
|
|
.mockReturnValue(alertInstanceFactoryMock),
|
|
callCluster: elasticsearchServiceMock.createLegacyScopedClusterClient().callAsCurrentUser,
|
|
getLegacyScopedClusterClient: jest.fn(),
|
|
savedObjectsClient: savedObjectsClientMock.create(),
|
|
scopedClusterClient: elasticsearchServiceMock.createScopedClusterClient().asCurrentUser,
|
|
};
|
|
};
|
|
export type AlertServicesMock = ReturnType<typeof createAlertServicesMock>;
|
|
|
|
export const alertsMock = {
|
|
createAlertInstanceFactory: createAlertInstanceFactoryMock,
|
|
createSetup: createSetupMock,
|
|
createStart: createStartMock,
|
|
createAlertServices: createAlertServicesMock,
|
|
};
|