[Custom threshold] Use data view name instead of indexPattern in reason message (#170453)

## Summary

This PR uses data view `name` instead of `indexPattern` in the reason
message for the custom threshold rule.
This commit is contained in:
Maryam Saeidi 2023-11-03 15:29:17 +01:00 committed by GitHub
parent 8a1ad098c8
commit cd490eeabe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 17 additions and 11 deletions

View file

@ -235,7 +235,7 @@ describe('The metric threshold alert type', () => {
const { action } = mostRecentAction(instanceID);
expect(action.group).toBeUndefined();
expect(action.reason).toBe(
'test.metric.1 is 1, above the threshold of 0.75. (duration: 1 min, data view: mockedIndexPattern)'
'test.metric.1 is 1, above the threshold of 0.75. (duration: 1 min, data view: mockedDataViewName)'
);
});
});
@ -995,7 +995,7 @@ describe('The metric threshold alert type', () => {
const { action } = mostRecentAction(instanceID);
const reasons = action.reason;
expect(reasons).toBe(
'test.metric.1 is 1, above the threshold of 1; test.metric.2 is 3, above the threshold of 3. (duration: 1 min, data view: mockedIndexPattern)'
'test.metric.1 is 1, above the threshold of 1; test.metric.2 is 3, above the threshold of 3. (duration: 1 min, data view: mockedDataViewName)'
);
});
});
@ -1746,6 +1746,7 @@ const alertsServices = alertsMock.createRuleExecutorServices();
const mockedIndex = {
id: 'c34a7c79-a88b-4b4a-ad19-72f6d24104e4',
title: 'metrics-fake_hosts',
name: 'mockedDataViewName',
fieldFormatMap: {},
typeMeta: {},
timeFieldName: '@timestamp',

View file

@ -134,6 +134,7 @@ export const createCustomThresholdExecutor = ({
const initialSearchSource = await searchSourceClient.create(params.searchConfiguration!);
const dataView = initialSearchSource.getField('index')!.getIndexPattern();
const dataViewName = initialSearchSource.getField('index')!.name;
const timeFieldName = initialSearchSource.getField('index')?.timeFieldName;
if (!dataView) {
throw new Error('No matched data view');
@ -189,7 +190,7 @@ export const createCustomThresholdExecutor = ({
let reason;
if (nextState === AlertStates.ALERT) {
reason = buildFiredAlertReason(alertResults, group, dataView);
reason = buildFiredAlertReason(alertResults, group, dataViewName);
}
/* NO DATA STATE HANDLING

View file

@ -37,6 +37,7 @@ 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 DATA_VIEW_ID = 'data-view-id';
let infraDataIndex: string;
let actionId: string;
@ -48,7 +49,7 @@ export default function ({ getService }: FtrProviderContext) {
infraDataIndex = await generate({ esClient, lookback: 'now-15m', logger });
await createDataView({
supertest,
name: DATE_VIEW,
name: DATE_VIEW_NAME,
id: DATA_VIEW_ID,
title: DATE_VIEW,
});
@ -213,7 +214,7 @@ export default function ({ getService }: FtrProviderContext) {
`https://localhost:5601/app/observability/alerts?_a=(kuery:%27kibana.alert.uuid:%20%22${alertId}%22%27%2CrangeFrom:%27${rangeFrom}%27%2CrangeTo:now%2Cstatus:all)`
);
expect(resp.hits.hits[0]._source?.reason).eql(
`Average system.cpu.user.pct is 250%, above the threshold of 50%. (duration: 5 mins, data view: ${DATE_VIEW})`
`Average system.cpu.user.pct is 250%, above the threshold of 50%. (duration: 5 mins, data view: ${DATE_VIEW_NAME})`
);
expect(resp.hits.hits[0]._source?.value).eql('250%');
});

View file

@ -33,6 +33,7 @@ export default function ({ getService }: FtrProviderContext) {
describe('Custom Threshold rule - AVG - PCT - NoData', () => {
const CUSTOM_THRESHOLD_RULE_ALERT_INDEX = '.alerts-observability.threshold.alerts-default';
const ALERT_ACTION_INDEX = 'alert-action-threshold';
const DATA_VIEW = 'no-data-pattern';
const DATA_VIEW_ID = 'data-view-id-no-data';
let actionId: string;
let ruleId: string;
@ -42,9 +43,9 @@ export default function ({ getService }: FtrProviderContext) {
before(async () => {
await createDataView({
supertest,
name: 'no-data-pattern',
name: DATA_VIEW,
id: DATA_VIEW_ID,
title: 'no-data-pattern',
title: DATA_VIEW,
});
});

View file

@ -42,6 +42,7 @@ export default function ({ getService }: FtrProviderContext) {
const ALERT_ACTION_INDEX = 'alert-action-threshold';
const DATE_VIEW = 'traces-apm*,metrics-apm*,logs-apm*';
const DATA_VIEW_ID = 'data-view-id';
const DATA_VIEW_NAME = 'test-data-view-name';
let synthtraceEsClient: ApmSynthtraceEsClient;
let actionId: string;
@ -54,7 +55,7 @@ export default function ({ getService }: FtrProviderContext) {
await generateData({ synthtraceEsClient, start, end });
await createDataView({
supertest,
name: 'test-data-view',
name: DATA_VIEW_NAME,
id: DATA_VIEW_ID,
title: DATE_VIEW,
});
@ -218,7 +219,7 @@ export default function ({ getService }: FtrProviderContext) {
`https://localhost:5601/app/observability/alerts?_a=(kuery:%27kibana.alert.uuid:%20%22${alertId}%22%27%2CrangeFrom:%27${rangeFrom}%27%2CrangeTo:now%2Cstatus:all)`
);
expect(resp.hits.hits[0]._source?.reason).eql(
`Average span.self_time.sum.us is 10,000,000, above the threshold of 7,500,000. (duration: 5 mins, data view: ${DATE_VIEW})`
`Average span.self_time.sum.us is 10,000,000, above the threshold of 7,500,000. (duration: 5 mins, data view: ${DATA_VIEW_NAME})`
);
expect(resp.hits.hits[0]._source?.value).eql('10,000,000');
});

View file

@ -38,6 +38,7 @@ export default function ({ getService }: FtrProviderContext) {
// x-pack/packages/kbn-infra-forge/src/data_sources/composable/template.json
const DATE_VIEW = 'kbn-data-forge-fake_hosts';
const DATA_VIEW_ID = 'data-view-id';
const DATE_VIEW_NAME = 'data-view-name';
let infraDataIndex: string;
let actionId: string;
let ruleId: string;
@ -48,7 +49,7 @@ export default function ({ getService }: FtrProviderContext) {
infraDataIndex = await generate({ esClient, lookback: 'now-15m', logger });
await createDataView({
supertest,
name: DATE_VIEW,
name: DATE_VIEW_NAME,
id: DATA_VIEW_ID,
title: DATE_VIEW,
});
@ -212,7 +213,7 @@ export default function ({ getService }: FtrProviderContext) {
`https://localhost:5601/app/observability/alerts?_a=(kuery:%27kibana.alert.uuid:%20%22${alertId}%22%27%2CrangeFrom:%27${rangeFrom}%27%2CrangeTo:now%2Cstatus:all)`
);
expect(resp.hits.hits[0]._source?.reason).eql(
`Document count is 3, above the threshold of 2. (duration: 1 min, data view: ${DATE_VIEW})`
`Document count is 3, above the threshold of 2. (duration: 1 min, data view: ${DATE_VIEW_NAME})`
);
expect(resp.hits.hits[0]._source?.value).eql('3');
});