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

[ML] Explain Log Rate Spikes: Basic functional tests. #138387

Merged
merged 7 commits into from
Aug 11, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions .buildkite/ftr_configs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ enabled:
- x-pack/test/functional/apps/maps/group2/config.ts
- x-pack/test/functional/apps/maps/group3/config.ts
- x-pack/test/functional/apps/maps/group4/config.ts
- x-pack/test/functional/apps/ml/aiops/config.ts
- x-pack/test/functional/apps/ml/anomaly_detection/config.ts
- x-pack/test/functional/apps/ml/data_frame_analytics/config.ts
- x-pack/test/functional/apps/ml/data_visualizer/config.ts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export const ExplainLogRateSpikesPage: FC<ExplainLogRateSpikesPageProps> = ({
}

return (
<EuiPageBody data-test-subj="aiopsIndexPage" paddingSize="none" panelled={false}>
<EuiPageBody data-test-subj="aiopsExplainLogRateSpikesPage" paddingSize="none" panelled={false}>
<EuiFlexGroup gutterSize="none">
<EuiFlexItem>
<EuiPageContentHeader className="aiopsPageHeader">
Expand Down Expand Up @@ -268,6 +268,7 @@ export const ExplainLogRateSpikesPage: FC<ExplainLogRateSpikesPageProps> = ({
/>
</p>
}
data-test-subj="aiopsNoWindowParametersEmptyPrompt"
/>
)}
</EuiPanel>
Expand Down
20 changes: 20 additions & 0 deletions x-pack/test/functional/apps/ml/aiops/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* 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 { FtrConfigProviderContext } from '@kbn/test';

export default async function ({ readConfigFile }: FtrConfigProviderContext) {
const functionalConfig = await readConfigFile(require.resolve('../../../config.base.js'));

return {
...functionalConfig.getAll(),
testFiles: [require.resolve('.')],
junit: {
reportName: 'Chrome X-Pack UI Functional Tests - ML aiops',
},
};
}
82 changes: 82 additions & 0 deletions x-pack/test/functional/apps/ml/aiops/explain_log_rate_spikes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* 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 { FtrProviderContext } from '../../../ftr_provider_context';
import { TestData } from './types';
import { farequoteDataViewTestData } from '../data_visualizer/index_test_data';

export default function ({ getPageObject, getService }: FtrProviderContext) {
const headerPage = getPageObject('header');
const esArchiver = getService('esArchiver');
const ml = getService('ml');

function runTests(testData: TestData) {
it(`${testData.suiteTitle} loads the source data in explain log rate spikes`, async () => {
await ml.testExecution.logTestStep(
`${testData.suiteTitle} loads the saved search selection page`
);
await ml.aiops.navigateToIndexPatternSelection();

await ml.testExecution.logTestStep(
`${testData.suiteTitle} loads the explain log rate spikes page`
);
await ml.jobSourceSelection.selectSourceForExplainLogRateSpikes(
testData.sourceIndexOrSavedSearch
);
});

it(`${testData.suiteTitle} displays index details`, async () => {
await ml.testExecution.logTestStep(`${testData.suiteTitle} displays the time range step`);
await ml.aiops.assertTimeRangeSelectorSectionExists();

await ml.testExecution.logTestStep(`${testData.suiteTitle} loads data for full time range`);
await ml.aiops.clickUseFullDataButton(testData.expected.totalDocCountFormatted);
await headerPage.waitUntilLoadingHasFinished();

await ml.testExecution.logTestStep(
`${testData.suiteTitle} displays elements in the doc count panel correctly`
);
await ml.aiops.assertTotalDocCountHeaderExist();
await ml.aiops.assertTotalDocCountChartExist();

await ml.testExecution.logTestStep(
`${testData.suiteTitle} displays elements in the page correctly`
);

await ml.aiops.assertSearchPanelExist();

await ml.testExecution.logTestStep('displays empty prompt');
await ml.aiops.assertNoWindowParametersEmptyPromptExist();
});
}

describe('index based', function () {
qn895 marked this conversation as resolved.
Show resolved Hide resolved
this.tags(['ml']);
before(async () => {
await esArchiver.loadIfNeeded('x-pack/test/functional/es_archives/ml/farequote');

await ml.testResources.createIndexPatternIfNeeded('ft_farequote', '@timestamp');
await ml.testResources.setKibanaTimeZoneToUTC();

await ml.securityUI.loginAsMlPowerUser();
});

after(async () => {
await ml.testResources.deleteIndexPatternByTitle('ft_farequote');
});

describe('with farequote', function () {
// Run tests on full farequote index.
it(`${farequoteDataViewTestData.suiteTitle} loads the explain log rate spikes page`, async () => {
// Start navigation from the base of the ML app.
await ml.navigation.navigateToMl();
});

runTests(farequoteDataViewTestData);
});
});
}
36 changes: 36 additions & 0 deletions x-pack/test/functional/apps/ml/aiops/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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 { FtrProviderContext } from '../../../ftr_provider_context';

export default function ({ getService, loadTestFile }: FtrProviderContext) {
const esArchiver = getService('esArchiver');
const ml = getService('ml');

describe('machine learning - aiops', function () {
this.tags(['skipFirefox', 'ml', 'walterra']);
qn895 marked this conversation as resolved.
Show resolved Hide resolved

before(async () => {
await ml.securityCommon.createMlRoles();
await ml.securityCommon.createMlUsers();
});

after(async () => {
// NOTE: Logout needs to happen before anything else to avoid flaky behavior
await ml.securityUI.logout();

await ml.securityCommon.cleanMlUsers();
await ml.securityCommon.cleanMlRoles();

await esArchiver.unload('x-pack/test/functional/es_archives/ml/farequote');

await ml.testResources.resetKibanaTimeZone();
});

loadTestFile(require.resolve('./explain_log_rate_spikes'));
});
}
17 changes: 17 additions & 0 deletions x-pack/test/functional/apps/ml/aiops/test_data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* 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 { TestData } from './types';

export const farequoteDataViewTestData: TestData = {
suiteTitle: 'farequote index pattern',
isSavedSearch: false,
sourceIndexOrSavedSearch: 'ft_farequote',
expected: {
totalDocCountFormatted: '86,274',
},
};
16 changes: 16 additions & 0 deletions x-pack/test/functional/apps/ml/aiops/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* 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 interface TestData {
suiteTitle: string;
isSavedSearch?: boolean;
sourceIndexOrSavedSearch: string;
rowsPerPage?: 10 | 25 | 50;
expected: {
totalDocCountFormatted: string;
};
}
64 changes: 64 additions & 0 deletions x-pack/test/functional/services/ml/aiops.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* 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';

export function MachineLearningAiopsProvider({ getService }: FtrProviderContext) {
const testSubjects = getService('testSubjects');
const retry = getService('retry');

return {
async assertTimeRangeSelectorSectionExists() {
await testSubjects.existOrFail('aiopsTimeRangeSelectorSection');
},

async assertTotalDocumentCount(expectedFormattedTotalDocCount: string) {
await retry.tryForTime(5000, async () => {
const docCount = await testSubjects.getVisibleText('aiopsTotalDocCount');
expect(docCount).to.eql(
expectedFormattedTotalDocCount,
`Expected total document count to be '${expectedFormattedTotalDocCount}' (got '${docCount}')`
);
});
},

async clickUseFullDataButton(expectedFormattedTotalDocCount: string) {
await retry.tryForTime(30 * 1000, async () => {
await testSubjects.clickWhenNotDisabled('aiopsExplainLogRatesSpikeButtonUseFullData');
await testSubjects.clickWhenNotDisabled('superDatePickerApplyTimeButton');
await this.assertTotalDocumentCount(expectedFormattedTotalDocCount);
});
},

async assertTotalDocCountHeaderExist() {
await retry.tryForTime(5000, async () => {
await testSubjects.existOrFail(`aiopsTotalDocCountHeader`);
});
},

async assertTotalDocCountChartExist() {
await retry.tryForTime(5000, async () => {
await testSubjects.existOrFail(`aiopsDocumentCountChart`);
});
},

async assertSearchPanelExist() {
await testSubjects.existOrFail(`aiopsSearchPanel`);
},

async assertNoWindowParametersEmptyPromptExist() {
await testSubjects.existOrFail(`aiopsNoWindowParametersEmptyPrompt`);
},

async navigateToIndexPatternSelection() {
await testSubjects.click('mlMainTab explainLogRateSpikes');
await testSubjects.existOrFail('mlPageSourceSelection');
},
};
}
3 changes: 3 additions & 0 deletions x-pack/test/functional/services/ml/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import { FtrProviderContext } from '../../ftr_provider_context';

import { MachineLearningAiopsProvider } from './aiops';
import { MachineLearningAnomaliesTableProvider } from './anomalies_table';
import { MachineLearningAnomalyExplorerProvider } from './anomaly_explorer';
import { MachineLearningAPIProvider } from './api';
Expand Down Expand Up @@ -127,8 +128,10 @@ export function MachineLearningProvider(context: FtrProviderContext) {
const trainedModels = TrainedModelsProvider(context, commonUI);
const trainedModelsTable = TrainedModelsTableProvider(context, commonUI);
const mlNodesPanel = MlNodesPanelProvider(context);
const aiops = MachineLearningAiopsProvider(context);

return {
aiops,
anomaliesTable,
anomalyExplorer,
alerting,
Expand Down
4 changes: 4 additions & 0 deletions x-pack/test/functional/services/ml/job_source_selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,9 @@ export function MachineLearningJobSourceSelectionProvider({ getService }: FtrPro
async selectSourceForIndexBasedDataVisualizer(sourceName: string) {
await this.selectSource(sourceName, 'dataVisualizerIndexPage');
},

async selectSourceForExplainLogRateSpikes(sourceName: string) {
await this.selectSource(sourceName, 'aiopsExplainLogRateSpikesPage');
},
};
}