diff --git a/x-pack/test/functional_with_es_ssl/apps/triggers_actions_ui/details.ts b/x-pack/test/functional_with_es_ssl/apps/triggers_actions_ui/details.ts index 1d86d95b7a796..fdcb456493dab 100644 --- a/x-pack/test/functional_with_es_ssl/apps/triggers_actions_ui/details.ts +++ b/x-pack/test/functional_with_es_ssl/apps/triggers_actions_ui/details.ts @@ -9,6 +9,7 @@ import uuid from 'uuid'; import { omit, mapValues, range, flatten } from 'lodash'; import moment from 'moment'; import { FtrProviderContext } from '../../ftr_provider_context'; +import { alwaysFiringAlertType } from '../../fixtures/plugins/alerts/server/plugin'; export default ({ getPageObjects, getService }: FtrProviderContext) => { const testSubjects = getService('testSubjects'); @@ -306,8 +307,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { }); }); - // FLAKY: https://github.com/elastic/kibana/issues/57426 - describe.skip('Alert Instances', function () { + describe('Alert Instances', function () { const testRunUuid = uuid.v4(); let alert: any; @@ -373,16 +373,31 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { // refresh to ensure Api call and UI are looking at freshest output await browser.refresh(); + // Get action groups + const { actionGroups } = alwaysFiringAlertType; + // Verify content await testSubjects.existOrFail('alertInstancesList'); - const summary = await alerting.alerts.getAlertInstanceSummary(alert.id); + const actionGroupNameFromId = (actionGroupId: string) => + actionGroups.find( + (actionGroup: { id: string; name: string }) => actionGroup.id === actionGroupId + )?.name; + const summary = await alerting.alerts.getAlertInstanceSummary(alert.id); const dateOnAllInstancesFromApiResponse = mapValues( summary.instances, (instance) => instance.activeStartDate ); + const actionGroupNameOnAllInstancesFromApiResponse = mapValues( + summary.instances, + (instance) => { + const name = actionGroupNameFromId(instance.actionGroupId); + return name ? ` (${name})` : ''; + } + ); + log.debug( `API RESULT: ${Object.entries(dateOnAllInstancesFromApiResponse) .map(([id, date]) => `${id}: ${moment(date).utc()}`) @@ -393,21 +408,21 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { expect(instancesList.map((instance) => omit(instance, 'duration'))).to.eql([ { instance: 'us-central', - status: 'Active (Default)', + status: `Active${actionGroupNameOnAllInstancesFromApiResponse['us-central']}`, start: moment(dateOnAllInstancesFromApiResponse['us-central']) .utc() .format('D MMM YYYY @ HH:mm:ss'), }, { instance: 'us-east', - status: 'Active (Default)', + status: `Active${actionGroupNameOnAllInstancesFromApiResponse['us-east']}`, start: moment(dateOnAllInstancesFromApiResponse['us-east']) .utc() .format('D MMM YYYY @ HH:mm:ss'), }, { instance: 'us-west', - status: 'Active (Default)', + status: `Active${actionGroupNameOnAllInstancesFromApiResponse['us-west']}`, start: moment(dateOnAllInstancesFromApiResponse['us-west']) .utc() .format('D MMM YYYY @ HH:mm:ss'), diff --git a/x-pack/test/functional_with_es_ssl/fixtures/plugins/alerts/server/plugin.ts b/x-pack/test/functional_with_es_ssl/fixtures/plugins/alerts/server/plugin.ts index 6f9d010378624..6584c5891a8b9 100644 --- a/x-pack/test/functional_with_es_ssl/fixtures/plugins/alerts/server/plugin.ts +++ b/x-pack/test/functional_with_es_ssl/fixtures/plugins/alerts/server/plugin.ts @@ -17,11 +17,62 @@ export interface AlertingExampleDeps { features: FeaturesPluginSetup; } +export const noopAlertType: AlertType = { + id: 'test.noop', + name: 'Test: Noop', + actionGroups: [{ id: 'default', name: 'Default' }], + defaultActionGroupId: 'default', + async executor() {}, + producer: 'alerts', +}; + +export const alwaysFiringAlertType: any = { + id: 'test.always-firing', + name: 'Always Firing', + actionGroups: [ + { id: 'default', name: 'Default' }, + { id: 'other', name: 'Other' }, + ], + defaultActionGroupId: 'default', + producer: 'alerts', + async executor(alertExecutorOptions: any) { + const { services, state, params } = alertExecutorOptions; + + (params.instances || []).forEach((instance: { id: string; state: any }) => { + services + .alertInstanceFactory(instance.id) + .replaceState({ instanceStateValue: true, ...(instance.state || {}) }) + .scheduleActions('default'); + }); + + return { + globalStateValue: true, + groupInSeriesIndex: (state.groupInSeriesIndex || 0) + 1, + }; + }, +}; + +export const failingAlertType: any = { + id: 'test.failing', + name: 'Test: Failing', + actionGroups: [ + { + id: 'default', + name: 'Default', + }, + ], + producer: 'alerts', + defaultActionGroupId: 'default', + async executor() { + throw new Error('Failed to execute alert type'); + }, +}; + export class AlertingFixturePlugin implements Plugin { public setup(core: CoreSetup, { alerts, features }: AlertingExampleDeps) { - createNoopAlertType(alerts); - createAlwaysFiringAlertType(alerts); - createFailingAlertType(alerts); + alerts.registerType(noopAlertType); + alerts.registerType(alwaysFiringAlertType); + alerts.registerType(failingAlertType); features.registerKibanaFeature({ id: 'alerting_fixture', name: 'alerting_fixture', @@ -56,64 +107,3 @@ export class AlertingFixturePlugin implements Plugin { - services - .alertInstanceFactory(instance.id) - .replaceState({ instanceStateValue: true, ...(instance.state || {}) }) - .scheduleActions('default'); - }); - - return { - globalStateValue: true, - groupInSeriesIndex: (state.groupInSeriesIndex || 0) + 1, - }; - }, - }; - alerts.registerType(alwaysFiringAlertType); -} - -function createFailingAlertType(alerts: AlertingSetup) { - const failingAlertType: any = { - id: 'test.failing', - name: 'Test: Failing', - actionGroups: [ - { - id: 'default', - name: 'Default', - }, - ], - producer: 'alerts', - defaultActionGroupId: 'default', - async executor() { - throw new Error('Failed to execute alert type'); - }, - }; - alerts.registerType(failingAlertType); -} diff --git a/x-pack/test/functional_with_es_ssl/services/alerting/alerts.ts b/x-pack/test/functional_with_es_ssl/services/alerting/alerts.ts index 942b352b4afd3..5ab07aa00412b 100644 --- a/x-pack/test/functional_with_es_ssl/services/alerting/alerts.ts +++ b/x-pack/test/functional_with_es_ssl/services/alerting/alerts.ts @@ -20,6 +20,7 @@ export interface AlertInstanceSummary { export interface AlertInstanceStatus { status: string; muted: boolean; + actionGroupId: string; activeStartDate?: string; }