mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
[Synthetics] Fix and updated alert flaky tests (#160870)
This commit is contained in:
parent
91fbd8e9e0
commit
e5cb4f3e68
3 changed files with 102 additions and 57 deletions
|
@ -90,7 +90,10 @@ const STANDARD_LIST_TYPES = [
|
|||
'lens',
|
||||
'map',
|
||||
'cases',
|
||||
// synthetics based objects
|
||||
'synthetics-monitor',
|
||||
'uptime-dynamic-settings',
|
||||
|
||||
'osquery-saved-query',
|
||||
'osquery-pack',
|
||||
'infrastructure-ui-source',
|
||||
|
|
|
@ -5,7 +5,10 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { SYNTHETICS_STATUS_RULE } from '../../../common/constants/synthetics_alerts';
|
||||
import {
|
||||
SYNTHETICS_STATUS_RULE,
|
||||
SYNTHETICS_TLS_RULE,
|
||||
} from '../../../common/constants/synthetics_alerts';
|
||||
import { DefaultAlertService } from './default_alert_service';
|
||||
import { SyntheticsRestApiRouteFactory } from '../types';
|
||||
import { SYNTHETICS_API_URLS } from '../../../common/constants';
|
||||
|
@ -16,6 +19,12 @@ export const getDefaultAlertingRoute: SyntheticsRestApiRouteFactory = () => ({
|
|||
validate: {},
|
||||
handler: async ({ context, server, savedObjectsClient }): Promise<any> => {
|
||||
const defaultAlertService = new DefaultAlertService(context, server, savedObjectsClient);
|
||||
return await defaultAlertService.getExistingAlert(SYNTHETICS_STATUS_RULE);
|
||||
const statusRule = defaultAlertService.getExistingAlert(SYNTHETICS_STATUS_RULE);
|
||||
const tlsRule = defaultAlertService.getExistingAlert(SYNTHETICS_TLS_RULE);
|
||||
const [status, tls] = await Promise.all([statusRule, tlsRule]);
|
||||
return {
|
||||
statusRule: status,
|
||||
tlsRule: tls,
|
||||
};
|
||||
},
|
||||
});
|
||||
|
|
|
@ -10,15 +10,11 @@ import { ConfigKey, HTTPFields } from '@kbn/synthetics-plugin/common/runtime_typ
|
|||
import { SYNTHETICS_API_URLS } from '@kbn/synthetics-plugin/common/constants';
|
||||
|
||||
import { secretKeys } from '@kbn/synthetics-plugin/common/constants/monitor_management';
|
||||
import { syntheticsMonitorType } from '@kbn/synthetics-plugin/common/types/saved_objects';
|
||||
import { FtrProviderContext } from '../../ftr_provider_context';
|
||||
import { getFixtureJson } from './helper/get_fixture_json';
|
||||
import { Spaces } from '../../../alerting_api_integration/spaces_only/scenarios';
|
||||
import { ObjectRemover } from '../../../alerting_api_integration/common/lib';
|
||||
|
||||
export default function ({ getService }: FtrProviderContext) {
|
||||
// FLAKY: https://github.com/elastic/kibana/issues/158408
|
||||
describe.skip('EnableDefaultAlerting', function () {
|
||||
describe('EnableDefaultAlerting', function () {
|
||||
this.tags('skipCloud');
|
||||
|
||||
const supertest = getService('supertest');
|
||||
|
@ -28,24 +24,19 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
let _httpMonitorJson: HTTPFields;
|
||||
let httpMonitorJson: HTTPFields;
|
||||
|
||||
const objectRemover = new ObjectRemover(supertest);
|
||||
|
||||
after(async () => {
|
||||
await objectRemover.removeAll();
|
||||
await kibanaServer.savedObjects.clean({ types: [syntheticsMonitorType] });
|
||||
await kibanaServer.savedObjects.cleanStandardList();
|
||||
});
|
||||
|
||||
before(() => {
|
||||
before(async () => {
|
||||
await kibanaServer.savedObjects.cleanStandardList();
|
||||
|
||||
_httpMonitorJson = getFixtureJson('http_monitor');
|
||||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
httpMonitorJson = _httpMonitorJson;
|
||||
await kibanaServer.savedObjects.clean({ types: [syntheticsMonitorType] });
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await objectRemover.removeAll();
|
||||
await kibanaServer.savedObjects.cleanStandardList();
|
||||
});
|
||||
|
||||
it('returns the created alerted when called', async () => {
|
||||
|
@ -54,41 +45,23 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
.set('kbn-xsrf', 'true')
|
||||
.send({});
|
||||
|
||||
const omitFields = ['id', 'updatedAt', 'createdAt', 'scheduledTaskId', 'executionStatus'];
|
||||
const omitFields = [
|
||||
'id',
|
||||
'updatedAt',
|
||||
'createdAt',
|
||||
'scheduledTaskId',
|
||||
'executionStatus',
|
||||
'monitoring',
|
||||
'nextRun',
|
||||
'lastRun',
|
||||
'snoozeSchedule',
|
||||
];
|
||||
|
||||
objectRemover.add(Spaces.default.id, apiResponse.body.id, 'rule', 'alerting');
|
||||
const statusRule = apiResponse.body.statusRule;
|
||||
const tlsRule = apiResponse.body.tlsRule;
|
||||
|
||||
expect(omit(apiResponse.body, omitFields)).eql(
|
||||
omit(
|
||||
{
|
||||
id: '1d72eb10-8046-11ed-9c27-7d79cab2e477',
|
||||
notifyWhen: 'onActionGroupChange',
|
||||
consumer: 'uptime',
|
||||
alertTypeId: 'xpack.synthetics.alerts.monitorStatus',
|
||||
apiKeyCreatedByUser: false,
|
||||
tags: ['SYNTHETICS_DEFAULT_ALERT'],
|
||||
name: 'Synthetics internal alert',
|
||||
enabled: true,
|
||||
throttle: null,
|
||||
apiKeyOwner: 'elastic',
|
||||
createdBy: 'elastic',
|
||||
updatedBy: 'elastic',
|
||||
muteAll: false,
|
||||
mutedInstanceIds: [],
|
||||
schedule: { interval: '1m' },
|
||||
actions: [],
|
||||
params: {},
|
||||
updatedAt: '2022-12-20T09:10:15.500Z',
|
||||
createdAt: '2022-12-20T09:10:15.500Z',
|
||||
scheduledTaskId: '1d72eb10-8046-11ed-9c27-7d79cab2e477',
|
||||
executionStatus: { status: 'pending', lastExecutionDate: '2022-12-20T09:10:15.500Z' },
|
||||
ruleTypeId: 'xpack.synthetics.alerts.monitorStatus',
|
||||
running: false,
|
||||
revision: 0,
|
||||
},
|
||||
omitFields
|
||||
)
|
||||
);
|
||||
expect(omit(statusRule, omitFields)).eql(omit(defaultAlertRules.statusRule, omitFields));
|
||||
expect(omit(tlsRule, omitFields)).eql(omit(defaultAlertRules.tlsRule, omitFields));
|
||||
});
|
||||
|
||||
it('enables alert when new monitor is added', async () => {
|
||||
|
@ -110,19 +83,79 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
)
|
||||
);
|
||||
|
||||
let foundAlert: any;
|
||||
|
||||
await retry.tryForTime(30 * 1000, async () => {
|
||||
const res = await supertest
|
||||
.get(SYNTHETICS_API_URLS.ENABLE_DEFAULT_ALERTING)
|
||||
.set('kbn-xsrf', 'true');
|
||||
|
||||
expect(res.body.ruleTypeId).eql('xpack.synthetics.alerts.monitorStatus');
|
||||
foundAlert = res.body;
|
||||
expect(res.body.statusRule.ruleTypeId).eql('xpack.synthetics.alerts.monitorStatus');
|
||||
expect(res.body.tlsRule.ruleTypeId).eql('xpack.synthetics.alerts.tls');
|
||||
});
|
||||
if (foundAlert) {
|
||||
objectRemover.add(Spaces.default.id, foundAlert.id, 'rule', 'alerting');
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
const defaultAlertRules = {
|
||||
statusRule: {
|
||||
id: '574e82f0-1672-11ee-8e7d-c985c0ef6c2e',
|
||||
notifyWhen: null,
|
||||
consumer: 'uptime',
|
||||
alertTypeId: 'xpack.synthetics.alerts.monitorStatus',
|
||||
tags: ['SYNTHETICS_DEFAULT_ALERT'],
|
||||
name: 'Synthetics status internal alert',
|
||||
enabled: true,
|
||||
throttle: null,
|
||||
apiKeyOwner: 'elastic',
|
||||
apiKeyCreatedByUser: false,
|
||||
createdBy: 'elastic',
|
||||
updatedBy: 'elastic',
|
||||
muteAll: false,
|
||||
mutedInstanceIds: [],
|
||||
revision: 0,
|
||||
running: false,
|
||||
schedule: { interval: '1m' },
|
||||
actions: [],
|
||||
params: {},
|
||||
snoozeSchedule: [],
|
||||
updatedAt: '2023-06-29T11:44:44.488Z',
|
||||
createdAt: '2023-06-29T11:44:44.488Z',
|
||||
scheduledTaskId: '574e82f0-1672-11ee-8e7d-c985c0ef6c2e',
|
||||
executionStatus: {
|
||||
status: 'ok',
|
||||
lastExecutionDate: '2023-06-29T11:47:55.331Z',
|
||||
lastDuration: 64,
|
||||
},
|
||||
ruleTypeId: 'xpack.synthetics.alerts.monitorStatus',
|
||||
},
|
||||
tlsRule: {
|
||||
id: '574eaa00-1672-11ee-8e7d-c985c0ef6c2e',
|
||||
notifyWhen: null,
|
||||
consumer: 'uptime',
|
||||
alertTypeId: 'xpack.synthetics.alerts.tls',
|
||||
tags: ['SYNTHETICS_DEFAULT_ALERT'],
|
||||
name: 'Synthetics internal TLS alert',
|
||||
enabled: true,
|
||||
throttle: null,
|
||||
apiKeyOwner: 'elastic',
|
||||
apiKeyCreatedByUser: false,
|
||||
createdBy: 'elastic',
|
||||
updatedBy: 'elastic',
|
||||
muteAll: false,
|
||||
mutedInstanceIds: [],
|
||||
revision: 0,
|
||||
running: false,
|
||||
schedule: { interval: '10m' },
|
||||
actions: [],
|
||||
params: {},
|
||||
snoozeSchedule: [],
|
||||
updatedAt: '2023-06-29T11:44:44.489Z',
|
||||
createdAt: '2023-06-29T11:44:44.489Z',
|
||||
scheduledTaskId: '574eaa00-1672-11ee-8e7d-c985c0ef6c2e',
|
||||
executionStatus: {
|
||||
status: 'ok',
|
||||
lastExecutionDate: '2023-06-29T11:44:46.214Z',
|
||||
lastDuration: 193,
|
||||
},
|
||||
ruleTypeId: 'xpack.synthetics.alerts.tls',
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue