[8.5] [ML] Automates geographic anomaly screenshots (#146502) (#146905)

# Backport

This will backport the following commits from `main` to `8.5`:
- [[ML] Automates geographic anomaly screenshots
(#146502)](https://github.com/elastic/kibana/pull/146502)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Lisa
Cawley","email":"lcawley@elastic.co"},"sourceCommit":{"committedDate":"2022-12-02T17:20:09Z","message":"[ML]
Automates geographic anomaly screenshots
(#146502)\n\n\r\nCo-authored-by: Robert Oskamp
<robert.oskamp@elastic.co>","sha":"e20ab5883b951ca621ebe04ff5fcb332d4a3e7c5","branchLabelMapping":{"^v8.7.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":[":ml","release_note:skip","v8.7.0","v8.5.3","v8.6.1"],"number":146502,"url":"https://github.com/elastic/kibana/pull/146502","mergeCommit":{"message":"[ML]
Automates geographic anomaly screenshots
(#146502)\n\n\r\nCo-authored-by: Robert Oskamp
<robert.oskamp@elastic.co>","sha":"e20ab5883b951ca621ebe04ff5fcb332d4a3e7c5"}},"sourceBranch":"main","suggestedTargetBranches":["8.5","8.6"],"targetPullRequestStates":[{"branch":"main","label":"v8.7.0","labelRegex":"^v8.7.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/146502","number":146502,"mergeCommit":{"message":"[ML]
Automates geographic anomaly screenshots
(#146502)\n\n\r\nCo-authored-by: Robert Oskamp
<robert.oskamp@elastic.co>","sha":"e20ab5883b951ca621ebe04ff5fcb332d4a3e7c5"}},{"branch":"8.5","label":"v8.5.3","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.6","label":"v8.6.1","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Lisa Cawley <lcawley@elastic.co>
This commit is contained in:
Kibana Machine 2022-12-02 13:15:26 -05:00 committed by GitHub
parent 18e3e57066
commit b3d667df3b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 39 additions and 12 deletions

View file

@ -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]);
});

View file

@ -87,7 +87,7 @@ export default ({ getService }: FtrProviderContext) => {
// @ts-expect-error not full interface
testJobConfig,
testDatafeedConfig,
idSpace1
{ space: idSpace1 }
);
});

View file

@ -88,7 +88,7 @@ export default ({ getService }: FtrProviderContext) => {
// @ts-expect-error not full interface
testJobConfig,
testDatafeedConfig,
idSpace1
{ space: idSpace1 }
);
});

View file

@ -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);
},

View file

@ -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') {
@ -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() {

View file

@ -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'];
@ -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,
@ -227,8 +231,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();
@ -238,6 +241,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);
@ -247,11 +257,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