Skip to content

Commit

Permalink
[RAC] Fixes terminology and splits tests to new case (elastic#120335)
Browse files Browse the repository at this point in the history
* Includes errors in the total number of rules

* Fixes terminology and splits tests to new case

* Removes unused vars

* Review feedback
  • Loading branch information
claudiopro authored Dec 3, 2021
1 parent bfa8b3c commit 5bfaf51
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,10 @@ function AlertsPage() {
// Note that the API uses the semantics of 'alerts' instead of 'rules'
const { alertExecutionStatus, ruleMutedStatus, ruleEnabledStatus } = response;
if (alertExecutionStatus && ruleMutedStatus && ruleEnabledStatus) {
const total = Object.entries(alertExecutionStatus).reduce((acc, [key, value]) => {
if (key !== 'error') {
acc = acc + value;
}
return acc;
}, 0);
const { error } = alertExecutionStatus;
const { muted } = ruleMutedStatus;
const total = Object.values(alertExecutionStatus).reduce((acc, value) => acc + value, 0);
const { disabled } = ruleEnabledStatus;
const { muted } = ruleMutedStatus;
const { error } = alertExecutionStatus;
setRuleStats({
...ruleStats,
total,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ export function ObservabilityAlertsCommonProvider({
return actionsOverflowButtons[index] || null;
};

const getAlertStatValue = async (testSubj: string) => {
const getRuleStatValue = async (testSubj: string) => {
const stat = await testSubjects.find(testSubj);
const title = await stat.findByCssSelector('.euiStat__title');
const count = await title.getVisibleText();
Expand Down Expand Up @@ -317,6 +317,6 @@ export function ObservabilityAlertsCommonProvider({
viewRuleDetailsButtonClick,
viewRuleDetailsLinkClick,
getAlertsFlyoutViewRuleDetailsLinkOrFail,
getAlertStatValue,
getRuleStatValue,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,7 @@

import expect from '@kbn/expect';
import { FtrProviderContext } from '../../../ftr_provider_context';
import { ObjectRemover } from '../../../../functional_with_es_ssl/lib/object_remover';
import {
createAlert,
disableAlert,
muteAlert,
} from '../../../../functional_with_es_ssl/lib/alert_api_actions';
import { generateUniqueKey } from '../../../../functional_with_es_ssl/lib/get_test_data';

async function asyncForEach<T>(array: T[], callback: (item: T, index: number) => void) {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index);
}
}
import { asyncForEach } from '../helpers';

const ACTIVE_ALERTS_CELL_COUNT = 78;
const RECOVERED_ALERTS_CELL_COUNT = 120;
Expand All @@ -28,8 +16,6 @@ const TOTAL_ALERTS_CELL_COUNT = 165;
export default ({ getService }: FtrProviderContext) => {
const esArchiver = getService('esArchiver');
const find = getService('find');
const supertest = getService('supertest');
const objectRemover = new ObjectRemover(supertest);

describe('Observability alerts', function () {
this.tags('includeFirefox');
Expand Down Expand Up @@ -245,65 +231,6 @@ export default ({ getService }: FtrProviderContext) => {
expect(await find.existsByCssSelector('[title="Rules and Connectors"]')).to.eql(true);
});
});

describe('Stat counters', () => {
beforeEach(async () => {
const uniqueKey = generateUniqueKey();

const alertToDisable = await createAlert({
supertest,
objectRemover,
overwrites: { name: 'b', tags: [uniqueKey] },
});
await createAlert({
supertest,
objectRemover,
overwrites: { name: 'c', tags: [uniqueKey] },
});
await createAlert({
supertest,
objectRemover,
overwrites: { name: 'a', tags: [uniqueKey] },
});
await createAlert({
supertest,
objectRemover,
overwrites: { name: 'd', tags: [uniqueKey] },
});
await createAlert({
supertest,
objectRemover,
overwrites: { name: 'e', tags: [uniqueKey] },
});
const alertToMute = await createAlert({
supertest,
objectRemover,
overwrites: { name: 'f', tags: [uniqueKey] },
});

await disableAlert({ supertest, alertId: alertToDisable.id });
await muteAlert({ supertest, alertId: alertToMute.id });

await observability.alerts.common.navigateToTimeWithData();
});

afterEach(async () => {
await objectRemover.removeAll();
});

it('Exist and display expected values', async () => {
const subjToValueMap: { [key: string]: number } = {
statRuleCount: 6,
statDisabled: 1,
statMuted: 1,
statErrors: 0,
};
await asyncForEach(Object.keys(subjToValueMap), async (subject: string) => {
const value = await observability.alerts.common.getAlertStatValue(subject);
expect(value).to.be(subjToValueMap[subject]);
});
});
});
});
});
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import expect from '@kbn/expect';
import { FtrProviderContext } from '../../../ftr_provider_context';
import { ObjectRemover } from '../../../../functional_with_es_ssl/lib/object_remover';
import {
createAlert as createRule,
disableAlert as disableRule,
muteAlert as muteRule,
} from '../../../../functional_with_es_ssl/lib/alert_api_actions';
import { generateUniqueKey } from '../../../../functional_with_es_ssl/lib/get_test_data';
import { asyncForEach } from '../helpers';

export default ({ getService }: FtrProviderContext) => {
const esArchiver = getService('esArchiver');
const supertest = getService('supertest');
const objectRemover = new ObjectRemover(supertest);

describe('Observability rules', function () {
this.tags('includeFirefox');

const observability = getService('observability');

before(async () => {
await esArchiver.load('x-pack/test/functional/es_archives/observability/alerts');
const setup = async () => {
await observability.alerts.common.setKibanaTimeZoneToUTC();
await observability.alerts.common.navigateToTimeWithData();
};
await setup();
});

after(async () => {
await esArchiver.unload('x-pack/test/functional/es_archives/observability/alerts');
});

describe('With no data', () => {
it('Shows the no data screen', async () => {
await observability.alerts.common.getNoDataPageOrFail();
});
});

describe('Stat counters', () => {
beforeEach(async () => {
const uniqueKey = generateUniqueKey();

const ruleToDisable = await createRule({
supertest,
objectRemover,
overwrites: { name: 'b', tags: [uniqueKey] },
});
await createRule({
supertest,
objectRemover,
overwrites: { name: 'c', tags: [uniqueKey] },
});
await createRule({
supertest,
objectRemover,
overwrites: { name: 'a', tags: [uniqueKey] },
});
await createRule({
supertest,
objectRemover,
overwrites: { name: 'd', tags: [uniqueKey] },
});
await createRule({
supertest,
objectRemover,
overwrites: { name: 'e', tags: [uniqueKey] },
});
const ruleToMute = await createRule({
supertest,
objectRemover,
overwrites: { name: 'f', tags: [uniqueKey] },
});

await disableRule({ supertest, alertId: ruleToDisable.id });
await muteRule({ supertest, alertId: ruleToMute.id });

await observability.alerts.common.navigateToTimeWithData();
});

afterEach(async () => {
await objectRemover.removeAll();
});

it('Exist and display expected values', async () => {
const subjToValueMap: { [key: string]: number } = {
statRuleCount: 6,
statDisabled: 1,
statMuted: 1,
statErrors: 0,
};
await asyncForEach(Object.keys(subjToValueMap), async (subject: string) => {
const value = await observability.alerts.common.getRuleStatValue(subject);
expect(value).to.be(subjToValueMap[subject]);
});
});
});
});
};
12 changes: 12 additions & 0 deletions x-pack/test/observability_functional/apps/observability/helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export async function asyncForEach<T>(array: T[], callback: (item: T, index: number) => void) {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index);
}
}
13 changes: 8 additions & 5 deletions x-pack/test/observability_functional/apps/observability/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@ import { FtrProviderContext } from '../../ftr_provider_context';
export default function ({ loadTestFile }: FtrProviderContext) {
describe('ObservabilityApp', function () {
this.tags('ciGroup6');
loadTestFile(require.resolve('./feature_controls'));
loadTestFile(require.resolve('./exploratory_view'));

loadTestFile(require.resolve('./alerts'));
loadTestFile(require.resolve('./alerts/add_to_case'));
loadTestFile(require.resolve('./alerts/alert_disclaimer'));
loadTestFile(require.resolve('./alerts/workflow_status'));
loadTestFile(require.resolve('./alerts/bulk_actions'));
loadTestFile(require.resolve('./alerts/pagination'));
loadTestFile(require.resolve('./alerts/add_to_case'));
loadTestFile(require.resolve('./alerts/rule_stats'));
loadTestFile(require.resolve('./alerts/state_synchronization'));
loadTestFile(require.resolve('./alerts/bulk_actions'));
loadTestFile(require.resolve('./alerts/table_storage'));
loadTestFile(require.resolve('./alerts/workflow_status'));

loadTestFile(require.resolve('./exploratory_view'));
loadTestFile(require.resolve('./feature_controls'));
});
}

0 comments on commit 5bfaf51

Please sign in to comment.