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

[7.x] Fixes Failing test: Chrome X-Pack UI Functional Tests.x-pack/test/functional_with_es_ssl/apps/triggers_actions_ui/details·ts - Actions and Triggers app Alert Details Alert Instances renders the active alert instances (#83478) #83912

Merged
merged 1 commit into from
Nov 20, 2020
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 @@ -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