Skip to content

Commit d76d44c

Browse files
committed
Making action group name lookup dynamic
1 parent 8040dae commit d76d44c

3 files changed

Lines changed: 75 additions & 68 deletions

File tree

x-pack/test/functional_with_es_ssl/apps/triggers_actions_ui/details.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import uuid from 'uuid';
99
import { omit, mapValues, range, flatten } from 'lodash';
1010
import moment from 'moment';
1111
import { FtrProviderContext } from '../../ftr_provider_context';
12+
import { alwaysFiringAlertType } from '../../fixtures/plugins/alerts/server/plugin';
1213

1314
export default ({ getPageObjects, getService }: FtrProviderContext) => {
1415
const testSubjects = getService('testSubjects');
@@ -373,16 +374,31 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
373374
// refresh to ensure Api call and UI are looking at freshest output
374375
await browser.refresh();
375376

377+
// Get action groups
378+
const { actionGroups } = alwaysFiringAlertType;
379+
376380
// Verify content
377381
await testSubjects.existOrFail('alertInstancesList');
378382

379-
const summary = await alerting.alerts.getAlertInstanceSummary(alert.id);
383+
const actionGroupNameFromId = (actionGroupId: string) =>
384+
actionGroups.find(
385+
(actionGroup: { id: string; name: string }) => actionGroup.id === actionGroupId
386+
)?.name;
380387

388+
const summary = await alerting.alerts.getAlertInstanceSummary(alert.id);
381389
const dateOnAllInstancesFromApiResponse = mapValues(
382390
summary.instances,
383391
(instance) => instance.activeStartDate
384392
);
385393

394+
const actionGroupNameOnAllInstancesFromApiResponse = mapValues(
395+
summary.instances,
396+
(instance) => {
397+
const name = actionGroupNameFromId(instance.actionGroupId);
398+
return name ? ` (${name})` : '';
399+
}
400+
);
401+
386402
log.debug(
387403
`API RESULT: ${Object.entries(dateOnAllInstancesFromApiResponse)
388404
.map(([id, date]) => `${id}: ${moment(date).utc()}`)
@@ -393,21 +409,21 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
393409
expect(instancesList.map((instance) => omit(instance, 'duration'))).to.eql([
394410
{
395411
instance: 'us-central',
396-
status: 'Active (Default)',
412+
status: `Active${actionGroupNameOnAllInstancesFromApiResponse['us-central']}`,
397413
start: moment(dateOnAllInstancesFromApiResponse['us-central'])
398414
.utc()
399415
.format('D MMM YYYY @ HH:mm:ss'),
400416
},
401417
{
402418
instance: 'us-east',
403-
status: 'Active (Default)',
419+
status: `Active${actionGroupNameOnAllInstancesFromApiResponse['us-east']}`,
404420
start: moment(dateOnAllInstancesFromApiResponse['us-east'])
405421
.utc()
406422
.format('D MMM YYYY @ HH:mm:ss'),
407423
},
408424
{
409425
instance: 'us-west',
410-
status: 'Active (Default)',
426+
status: `Active${actionGroupNameOnAllInstancesFromApiResponse['us-west']}`,
411427
start: moment(dateOnAllInstancesFromApiResponse['us-west'])
412428
.utc()
413429
.format('D MMM YYYY @ HH:mm:ss'),

x-pack/test/functional_with_es_ssl/fixtures/plugins/alerts/server/plugin.ts

Lines changed: 54 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,62 @@ export interface AlertingExampleDeps {
1717
features: FeaturesPluginSetup;
1818
}
1919

20+
export const noopAlertType: AlertType = {
21+
id: 'test.noop',
22+
name: 'Test: Noop',
23+
actionGroups: [{ id: 'default', name: 'Default' }],
24+
defaultActionGroupId: 'default',
25+
async executor() {},
26+
producer: 'alerts',
27+
};
28+
29+
export const alwaysFiringAlertType: any = {
30+
id: 'test.always-firing',
31+
name: 'Always Firing',
32+
actionGroups: [
33+
{ id: 'default', name: 'Default' },
34+
{ id: 'other', name: 'Other' },
35+
],
36+
defaultActionGroupId: 'default',
37+
producer: 'alerts',
38+
async executor(alertExecutorOptions: any) {
39+
const { services, state, params } = alertExecutorOptions;
40+
41+
(params.instances || []).forEach((instance: { id: string; state: any }) => {
42+
services
43+
.alertInstanceFactory(instance.id)
44+
.replaceState({ instanceStateValue: true, ...(instance.state || {}) })
45+
.scheduleActions('default');
46+
});
47+
48+
return {
49+
globalStateValue: true,
50+
groupInSeriesIndex: (state.groupInSeriesIndex || 0) + 1,
51+
};
52+
},
53+
};
54+
55+
export const failingAlertType: any = {
56+
id: 'test.failing',
57+
name: 'Test: Failing',
58+
actionGroups: [
59+
{
60+
id: 'default',
61+
name: 'Default',
62+
},
63+
],
64+
producer: 'alerts',
65+
defaultActionGroupId: 'default',
66+
async executor() {
67+
throw new Error('Failed to execute alert type');
68+
},
69+
};
70+
2071
export class AlertingFixturePlugin implements Plugin<void, void, AlertingExampleDeps> {
2172
public setup(core: CoreSetup, { alerts, features }: AlertingExampleDeps) {
22-
createNoopAlertType(alerts);
23-
createAlwaysFiringAlertType(alerts);
24-
createFailingAlertType(alerts);
73+
alerts.registerType(noopAlertType);
74+
alerts.registerType(alwaysFiringAlertType);
75+
alerts.registerType(failingAlertType);
2576
features.registerKibanaFeature({
2677
id: 'alerting_fixture',
2778
name: 'alerting_fixture',
@@ -56,64 +107,3 @@ export class AlertingFixturePlugin implements Plugin<void, void, AlertingExample
56107
public start() {}
57108
public stop() {}
58109
}
59-
60-
function createNoopAlertType(alerts: AlertingSetup) {
61-
const noopAlertType: AlertType = {
62-
id: 'test.noop',
63-
name: 'Test: Noop',
64-
actionGroups: [{ id: 'default', name: 'Default' }],
65-
defaultActionGroupId: 'default',
66-
async executor() {},
67-
producer: 'alerts',
68-
};
69-
alerts.registerType(noopAlertType);
70-
}
71-
72-
function createAlwaysFiringAlertType(alerts: AlertingSetup) {
73-
// Alert types
74-
const alwaysFiringAlertType: any = {
75-
id: 'test.always-firing',
76-
name: 'Always Firing',
77-
actionGroups: [
78-
{ id: 'default', name: 'Default' },
79-
{ id: 'other', name: 'Other' },
80-
],
81-
defaultActionGroupId: 'default',
82-
producer: 'alerts',
83-
async executor(alertExecutorOptions: any) {
84-
const { services, state, params } = alertExecutorOptions;
85-
86-
(params.instances || []).forEach((instance: { id: string; state: any }) => {
87-
services
88-
.alertInstanceFactory(instance.id)
89-
.replaceState({ instanceStateValue: true, ...(instance.state || {}) })
90-
.scheduleActions('default');
91-
});
92-
93-
return {
94-
globalStateValue: true,
95-
groupInSeriesIndex: (state.groupInSeriesIndex || 0) + 1,
96-
};
97-
},
98-
};
99-
alerts.registerType(alwaysFiringAlertType);
100-
}
101-
102-
function createFailingAlertType(alerts: AlertingSetup) {
103-
const failingAlertType: any = {
104-
id: 'test.failing',
105-
name: 'Test: Failing',
106-
actionGroups: [
107-
{
108-
id: 'default',
109-
name: 'Default',
110-
},
111-
],
112-
producer: 'alerts',
113-
defaultActionGroupId: 'default',
114-
async executor() {
115-
throw new Error('Failed to execute alert type');
116-
},
117-
};
118-
alerts.registerType(failingAlertType);
119-
}

x-pack/test/functional_with_es_ssl/services/alerting/alerts.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export interface AlertInstanceSummary {
2020
export interface AlertInstanceStatus {
2121
status: string;
2222
muted: boolean;
23+
actionGroupId: string;
2324
activeStartDate?: string;
2425
}
2526

0 commit comments

Comments
 (0)