[Custom threshold] Add an adHoc data view API integration test (#171508)

Closes #170438

## Summary

This PR adds an ad hoc data view API integration test by changing one of
the existing custom threshold API integration tests.
This commit is contained in:
Maryam Saeidi 2023-11-20 20:21:35 +01:00 committed by GitHub
parent 936a1a40ac
commit 8fd18fbb05
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 15 deletions

View file

@ -16,7 +16,6 @@ import { FIRED_ACTIONS_ID } from '@kbn/observability-plugin/server/lib/rules/cus
import expect from '@kbn/expect'; import expect from '@kbn/expect';
import { OBSERVABILITY_THRESHOLD_RULE_TYPE_ID } from '@kbn/rule-data-utils'; import { OBSERVABILITY_THRESHOLD_RULE_TYPE_ID } from '@kbn/rule-data-utils';
import { createIndexConnector, createRule } from '../helpers/alerting_api_helper'; import { createIndexConnector, createRule } from '../helpers/alerting_api_helper';
import { createDataView, deleteDataView } from '../helpers/data_view';
import { import {
waitForAlertInIndex, waitForAlertInIndex,
waitForDocumentInIndex, waitForDocumentInIndex,
@ -38,8 +37,19 @@ export default function ({ getService }: FtrProviderContext) {
// DATE_VIEW should match the index template: // DATE_VIEW should match the index template:
// x-pack/packages/kbn-infra-forge/src/data_sources/composable/template.json // x-pack/packages/kbn-infra-forge/src/data_sources/composable/template.json
const DATE_VIEW = 'kbn-data-forge-fake_hosts'; const DATE_VIEW = 'kbn-data-forge-fake_hosts';
const DATE_VIEW_NAME = 'data-view-name'; const DATE_VIEW_NAME = 'ad-hoc-data-view-name';
const DATA_VIEW_ID = 'data-view-id'; const DATA_VIEW_ID = 'data-view-id';
const MOCKED_AD_HOC_DATA_VIEW = {
id: DATA_VIEW_ID,
title: DATE_VIEW,
timeFieldName: '@timestamp',
sourceFilters: [],
fieldFormats: {},
runtimeFieldMap: {},
allowNoIndex: false,
name: DATE_VIEW_NAME,
allowHidden: false,
};
let infraDataIndex: string; let infraDataIndex: string;
let actionId: string; let actionId: string;
let ruleId: string; let ruleId: string;
@ -48,12 +58,6 @@ export default function ({ getService }: FtrProviderContext) {
before(async () => { before(async () => {
infraDataIndex = await generate({ esClient, lookback: 'now-15m', logger }); infraDataIndex = await generate({ esClient, lookback: 'now-15m', logger });
await createDataView({
supertest,
name: DATE_VIEW_NAME,
id: DATA_VIEW_ID,
title: DATE_VIEW,
});
}); });
after(async () => { after(async () => {
@ -67,10 +71,6 @@ export default function ({ getService }: FtrProviderContext) {
index: '.kibana-event-log-*', index: '.kibana-event-log-*',
query: { term: { 'kibana.alert.rule.consumer': 'logs' } }, query: { term: { 'kibana.alert.rule.consumer': 'logs' } },
}); });
await deleteDataView({
supertest,
id: DATA_VIEW_ID,
});
await esDeleteAllIndices([ALERT_ACTION_INDEX, infraDataIndex]); await esDeleteAllIndices([ALERT_ACTION_INDEX, infraDataIndex]);
await cleanup({ esClient, logger }); await cleanup({ esClient, logger });
}); });
@ -109,7 +109,7 @@ export default function ({ getService }: FtrProviderContext) {
query: '', query: '',
language: 'kuery', language: 'kuery',
}, },
index: DATA_VIEW_ID, index: MOCKED_AD_HOC_DATA_VIEW,
}, },
}, },
actions: [ actions: [
@ -199,7 +199,10 @@ export default function ({ getService }: FtrProviderContext) {
], ],
alertOnNoData: true, alertOnNoData: true,
alertOnGroupDisappear: true, alertOnGroupDisappear: true,
searchConfiguration: { index: 'data-view-id', query: { query: '', language: 'kuery' } }, searchConfiguration: {
index: MOCKED_AD_HOC_DATA_VIEW,
query: { query: '', language: 'kuery' },
},
}); });
}); });

View file

@ -5,8 +5,9 @@
* 2.0. * 2.0.
*/ */
import { ThresholdParams } from '@kbn/observability-plugin/common/custom_threshold_rule/types';
import type { SuperTest, Test } from 'supertest'; import type { SuperTest, Test } from 'supertest';
import expect from '@kbn/expect';
import { ThresholdParams } from '@kbn/observability-plugin/common/custom_threshold_rule/types';
export async function createIndexConnector({ export async function createIndexConnector({
supertest, supertest,
@ -64,5 +65,8 @@ export async function createRule<Params = ThresholdParams>({
rule_type_id: ruleTypeId, rule_type_id: ruleTypeId,
actions, actions,
}); });
if (body.statusCode) {
expect(body.statusCode).eql(200, body.message);
}
return body; return body;
} }