Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { FIRED_ACTIONS_ID } from '@kbn/observability-plugin/server/lib/rules/cus
import expect from '@kbn/expect';
import { OBSERVABILITY_THRESHOLD_RULE_TYPE_ID } from '@kbn/rule-data-utils';
import { createIndexConnector, createRule } from '../helpers/alerting_api_helper';
import { createDataView, deleteDataView } from '../helpers/data_view';
import {
waitForAlertInIndex,
waitForDocumentInIndex,
Expand All @@ -38,8 +37,19 @@ export default function ({ getService }: FtrProviderContext) {
// DATE_VIEW should match the index template:
// x-pack/packages/kbn-infra-forge/src/data_sources/composable/template.json
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 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,
};
Comment on lines +42 to +52
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be worth using this util from data plugin createStubDataView

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update

I tried it but got this error:

image

let infraDataIndex: string;
let actionId: string;
let ruleId: string;
Expand All @@ -48,12 +58,6 @@ export default function ({ getService }: FtrProviderContext) {

before(async () => {
infraDataIndex = await generate({ esClient, lookback: 'now-15m', logger });
await createDataView({
supertest,
name: DATE_VIEW_NAME,
id: DATA_VIEW_ID,
title: DATE_VIEW,
});
});

after(async () => {
Expand All @@ -67,10 +71,6 @@ export default function ({ getService }: FtrProviderContext) {
index: '.kibana-event-log-*',
query: { term: { 'kibana.alert.rule.consumer': 'logs' } },
});
await deleteDataView({
supertest,
id: DATA_VIEW_ID,
});
await esDeleteAllIndices([ALERT_ACTION_INDEX, infraDataIndex]);
await cleanup({ esClient, logger });
});
Expand Down Expand Up @@ -109,7 +109,7 @@ export default function ({ getService }: FtrProviderContext) {
query: '',
language: 'kuery',
},
index: DATA_VIEW_ID,
index: MOCKED_AD_HOC_DATA_VIEW,
},
},
actions: [
Expand Down Expand Up @@ -199,7 +199,10 @@ export default function ({ getService }: FtrProviderContext) {
],
alertOnNoData: true,
alertOnGroupDisappear: true,
searchConfiguration: { index: 'data-view-id', query: { query: '', language: 'kuery' } },
searchConfiguration: {
index: MOCKED_AD_HOC_DATA_VIEW,
query: { query: '', language: 'kuery' },
},
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
* 2.0.
*/

import { ThresholdParams } from '@kbn/observability-plugin/common/custom_threshold_rule/types';
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({
supertest,
Expand Down Expand Up @@ -64,5 +65,8 @@ export async function createRule<Params = ThresholdParams>({
rule_type_id: ruleTypeId,
actions,
});
if (body.statusCode) {
expect(body.statusCode).eql(200, body.message);
}
return body;
}
Loading