Skip to content

Commit

Permalink
[ML] Automates geographic anomaly screenshots (#146502)
Browse files Browse the repository at this point in the history
Co-authored-by: Robert Oskamp <robert.oskamp@elastic.co>
  • Loading branch information
lcawl and pheyos authored Dec 2, 2022
1 parent c38315f commit e20ab58
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default ({ getService }: FtrProviderContext) => {
await ml.api.createAndRunAnomalyDetectionLookbackJob(
ml.commonConfig.getADFqSingleMetricJobConfig(adJobId),
ml.commonConfig.getADFqDatafeedConfig(adJobId),
idSpace1
{ space: idSpace1 }
);
await ml.api.assertJobSpaces(adJobId, 'anomaly-detector', [idSpace1]);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export default ({ getService }: FtrProviderContext) => {
// @ts-expect-error not full interface
testJobConfig,
testDatafeedConfig,
idSpace1
{ space: idSpace1 }
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export default ({ getService }: FtrProviderContext) => {
// @ts-expect-error not full interface
testJobConfig,
testDatafeedConfig,
idSpace1
{ space: idSpace1 }
);
});

Expand Down
5 changes: 3 additions & 2 deletions x-pack/test/functional/services/ml/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -860,12 +860,13 @@ export function MachineLearningAPIProvider({ getService }: FtrProviderContext) {
async createAndRunAnomalyDetectionLookbackJob(
jobConfig: Job,
datafeedConfig: Datafeed,
space?: string
options: { space?: string; end?: string } = {}
) {
const { space = undefined, end = `${Date.now()}` } = options;
await this.createAnomalyDetectionJob(jobConfig, space);
await this.createDatafeed(datafeedConfig, space);
await this.openAnomalyDetectionJob(jobConfig.job_id);
await this.startDatafeed(datafeedConfig.datafeed_id, { start: '0', end: `${Date.now()}` });
await this.startDatafeed(datafeedConfig.datafeed_id, { start: '0', end });
await this.waitForDatafeedState(datafeedConfig.datafeed_id, DATAFEED_STATE.STOPPED);
await this.waitForJobState(jobConfig.job_id, JOB_STATE.CLOSED);
},
Expand Down
18 changes: 18 additions & 0 deletions x-pack/test/functional/services/sample_data/test_resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
* 2.0.
*/

import { UI_SETTINGS } from '@kbn/data-plugin/common';
import { FtrProviderContext } from '../../ftr_provider_context';

export function SampleDataTestResourcesServiceProvider({ getService }: FtrProviderContext) {
const supertest = getService('supertest');
const kibanaServer = getService('kibanaServer');

return {
async installKibanaSampleData(sampleDataId: 'ecommerce' | 'flights' | 'logs') {
Expand All @@ -26,6 +28,22 @@ export function SampleDataTestResourcesServiceProvider({ getService }: FtrProvid
await this.installKibanaSampleData('ecommerce');
await this.installKibanaSampleData('flights');
await this.installKibanaSampleData('logs');

// Sample data is shifted to be relative to current time
// This means that a static timerange will return different documents
// Setting the time range to a window larger than the sample data set
// ensures all documents are coverered by time query so the ES results will always be the same
const SAMPLE_DATA_RANGE = `[
{
"from": "now-180d",
"to": "now+180d",
"display": "sample data range"
}
]`;

await kibanaServer.uiSettings.update({
[UI_SETTINGS.TIMEPICKER_QUICK_RANGES]: SAMPLE_DATA_RANGE,
});
},

async removeAllKibanaSampleData() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ import { ECOMMERCE_INDEX_PATTERN, LOGS_INDEX_PATTERN } from '..';

export default function ({ getPageObject, getService }: FtrProviderContext) {
const elasticChart = getService('elasticChart');
const maps = getPageObject('maps');
const ml = getService('ml');
const commonScreenshots = getService('commonScreenshots');
const renderable = getService('renderable');
const maps = getPageObject('maps');
const timePicker = getPageObject('timePicker');

const screenshotDirectories = ['ml_docs', 'anomaly_detection'];

Expand Down Expand Up @@ -76,9 +77,12 @@ export default function ({ getPageObject, getService }: FtrProviderContext) {

describe('geographic data', function () {
before(async () => {
// Stop the sample data feed about three months after the current date to capture anomaly
const dateStopString = new Date(Date.now() + 131400 * 60 * 1000).toISOString();
await ml.api.createAndRunAnomalyDetectionLookbackJob(
ecommerceGeoJobConfig as Job,
ecommerceGeoDatafeedConfig as Datafeed
ecommerceGeoDatafeedConfig as Datafeed,
{ end: dateStopString }
);
await ml.api.createAndRunAnomalyDetectionLookbackJob(
weblogGeoJobConfig as Job,
Expand Down Expand Up @@ -222,8 +226,7 @@ export default function ({ getPageObject, getService }: FtrProviderContext) {
);
});

// the job stopped to produce an anomaly, needs investigation
it.skip('ecommerce anomaly explorer screenshots', async () => {
it('ecommerce anomaly explorer screenshots', async () => {
await ml.testExecution.logTestStep('navigate to job list');
await ml.navigation.navigateToMl();
await ml.navigation.navigateToJobManagement();
Expand All @@ -233,6 +236,13 @@ export default function ({ getPageObject, getService }: FtrProviderContext) {
await ml.jobTable.filterWithSearchString(ecommerceGeoJobConfig.job_id, 1);
await ml.jobTable.clickOpenJobInAnomalyExplorerButton(ecommerceGeoJobConfig.job_id);
await ml.commonUI.waitForMlLoadingIndicatorToDisappear();
await ml.testExecution.logTestStep('Choose time range...');
await timePicker.setCommonlyUsedTime('sample_data range');

await ml.testExecution.logTestStep('open anomaly list actions and take screenshot');
await ml.anomaliesTable.scrollTableIntoView();
await ml.anomaliesTable.ensureAnomalyActionsMenuOpen(0);
await commonScreenshots.takeScreenshot('view-in-maps', screenshotDirectories);

await ml.testExecution.logTestStep('select swim lane tile');
const cells = await ml.swimLane.getCells(overallSwimLaneTestSubj);
Expand All @@ -242,11 +252,9 @@ export default function ({ getPageObject, getService }: FtrProviderContext) {
y: sampleCell.y + cellSize,
});
await ml.swimLane.waitForSwimLanesToLoad();

await ml.testExecution.logTestStep('take screenshot');
await ml.testExecution.logTestStep('open anomaly list details and take screenshot');
await ml.anomaliesTable.ensureDetailsOpen(0);
await ml.anomalyExplorer.scrollChartsContainerIntoView();

await commonScreenshots.takeScreenshot(
'ecommerce-anomaly-explorer-geopoint',
screenshotDirectories
Expand Down

0 comments on commit e20ab58

Please sign in to comment.