mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
[Synthetics] Refactor e2e tests for silent failures (#161638)
This commit is contained in:
parent
47d099e22f
commit
5fca22a79d
1 changed files with 14 additions and 55 deletions
|
@ -200,70 +200,29 @@ export class SyntheticsServices {
|
|||
});
|
||||
}
|
||||
|
||||
async cleaUp(things: Array<'monitors' | 'alerts' | 'rules'> = ['monitors', 'alerts', 'rules']) {
|
||||
const promises = [];
|
||||
if (things.includes('monitors')) {
|
||||
promises.push(this.cleanTestMonitors());
|
||||
}
|
||||
if (things.includes('alerts')) {
|
||||
promises.push(this.cleaUpAlerts());
|
||||
}
|
||||
|
||||
if (things.includes('rules')) {
|
||||
promises.push(this.cleaUpRules());
|
||||
}
|
||||
|
||||
await Promise.all(promises);
|
||||
}
|
||||
|
||||
async cleaUpAlerts() {
|
||||
const getService = this.params.getService;
|
||||
const es: Client = getService('es');
|
||||
const listOfIndices = await es.cat.indices({ format: 'json' });
|
||||
for (const index of listOfIndices) {
|
||||
if (index.index?.startsWith('.internal.alerts-observability.uptime.alerts')) {
|
||||
await es.deleteByQuery({ index: index.index, query: { match_all: {} } });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async cleaUpRules() {
|
||||
async cleaUp() {
|
||||
try {
|
||||
const { data: response } = await this.requester.request({
|
||||
description: 'get monitors by name',
|
||||
path: `/internal/alerting/rules/_find`,
|
||||
query: {
|
||||
per_page: 10,
|
||||
page: 1,
|
||||
},
|
||||
method: 'GET',
|
||||
});
|
||||
const { data = [] } = response as any;
|
||||
const getService = this.params.getService;
|
||||
const server = getService('kibanaServer');
|
||||
|
||||
if (data.length > 0) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`Deleting ${data.length} rules`);
|
||||
|
||||
await axios.patch(
|
||||
this.kibanaUrl + '/internal/alerting/rules/_bulk_delete',
|
||||
{
|
||||
ids: data.map((rule: any) => rule.id),
|
||||
},
|
||||
{ auth: { username: 'elastic', password: 'changeme' }, headers: { 'kbn-xsrf': 'true' } }
|
||||
);
|
||||
}
|
||||
await server.savedObjects.clean({ types: ['synthetics-monitor', 'alert'] });
|
||||
await this.cleaUpAlerts();
|
||||
} catch (e) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
async cleanTestMonitors() {
|
||||
const getService = this.params.getService;
|
||||
const server = getService('kibanaServer');
|
||||
|
||||
async cleaUpAlerts() {
|
||||
try {
|
||||
await server.savedObjects.clean({ types: ['synthetics-monitor'] });
|
||||
const getService = this.params.getService;
|
||||
const es: Client = getService('es');
|
||||
const listOfIndices = await es.cat.indices({ format: 'json' });
|
||||
for (const index of listOfIndices) {
|
||||
if (index.index?.startsWith('.internal.alerts-observability.uptime.alerts')) {
|
||||
await es.deleteByQuery({ index: index.index, query: { match_all: {} } });
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(e);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue