mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
[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:
parent
936a1a40ac
commit
8fd18fbb05
2 changed files with 22 additions and 15 deletions
|
@ -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' },
|
||||||
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue