Skip to content

Commit

Permalink
Fixes Failing test: Chrome X-Pack UI Functional Tests.x-pack/test/fun…
Browse files Browse the repository at this point in the history
…ctional_with_es_ssl/apps/triggers_actions_ui/details·ts - Actions and Triggers app Alert Details Alert Instances renders the active alert instances (#83478)

* Unskipping test

* Unskipping test

* Making action group name lookup dynamic

* Removing comment

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
ymao1 and kibanamachine authored Nov 20, 2020
1 parent f64f16b commit a2598ea
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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()}`)
Expand All @@ -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'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<void, void, AlertingExampleDeps> {
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',
Expand Down Expand Up @@ -56,64 +107,3 @@ export class AlertingFixturePlugin implements Plugin<void, void, AlertingExample
public start() {}
public stop() {}
}

function createNoopAlertType(alerts: AlertingSetup) {
const noopAlertType: AlertType = {
id: 'test.noop',
name: 'Test: Noop',
actionGroups: [{ id: 'default', name: 'Default' }],
defaultActionGroupId: 'default',
async executor() {},
producer: 'alerts',
};
alerts.registerType(noopAlertType);
}

function createAlwaysFiringAlertType(alerts: AlertingSetup) {
// Alert types
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,
};
},
};
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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface AlertInstanceSummary {
export interface AlertInstanceStatus {
status: string;
muted: boolean;
actionGroupId: string;
activeStartDate?: string;
}

Expand Down

0 comments on commit a2598ea

Please sign in to comment.