forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ML] Anomaly Detection: Functional tests for anomaly detection foreca…
…sts. (elastic#116140) Functional tests for anomaly detection forecasts.
- Loading branch information
1 parent
68be5c2
commit b10375b
Showing
10 changed files
with
282 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
x-pack/test/functional/apps/ml/anomaly_detection/forecasts.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/* | ||
* 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 { Job, Datafeed } from '../../../../../plugins/ml/common/types/anomaly_detection_jobs'; | ||
|
||
// @ts-expect-error not full interface | ||
const JOB_CONFIG: Job = { | ||
job_id: `fq_single_1_smv`, | ||
description: 'count() on farequote dataset with 15m bucket span', | ||
groups: ['farequote', 'automated', 'single-metric'], | ||
analysis_config: { | ||
bucket_span: '15m', | ||
influencers: [], | ||
detectors: [ | ||
{ | ||
function: 'count', | ||
}, | ||
], | ||
}, | ||
data_description: { time_field: '@timestamp' }, | ||
analysis_limits: { model_memory_limit: '10mb' }, | ||
model_plot_config: { enabled: true }, | ||
}; | ||
|
||
// @ts-expect-error not full interface | ||
const DATAFEED_CONFIG: Datafeed = { | ||
datafeed_id: 'datafeed-fq_single_1_smv', | ||
indices: ['ft_farequote'], | ||
job_id: 'fq_single_1_smv', | ||
query: { bool: { must: [{ match_all: {} }] } }, | ||
}; | ||
|
||
export default function ({ getService }: FtrProviderContext) { | ||
const esArchiver = getService('esArchiver'); | ||
const ml = getService('ml'); | ||
|
||
describe('forecasts', function () { | ||
this.tags(['mlqa']); | ||
|
||
describe('with single metric job', function () { | ||
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.api.createAndRunAnomalyDetectionLookbackJob(JOB_CONFIG, DATAFEED_CONFIG); | ||
await ml.securityUI.loginAsMlPowerUser(); | ||
}); | ||
|
||
after(async () => { | ||
await ml.api.cleanMlIndices(); | ||
}); | ||
|
||
it('opens a job from job list link', async () => { | ||
await ml.testExecution.logTestStep('navigate to job list'); | ||
await ml.navigation.navigateToMl(); | ||
await ml.navigation.navigateToJobManagement(); | ||
|
||
await ml.testExecution.logTestStep('open job in single metric viewer'); | ||
await ml.jobTable.waitForJobsToLoad(); | ||
await ml.jobTable.filterWithSearchString(JOB_CONFIG.job_id, 1); | ||
|
||
await ml.jobTable.clickOpenJobInSingleMetricViewerButton(JOB_CONFIG.job_id); | ||
await ml.commonUI.waitForMlLoadingIndicatorToDisappear(); | ||
}); | ||
|
||
it('displays job results', async () => { | ||
await ml.testExecution.logTestStep('pre-fills the job selection'); | ||
await ml.jobSelection.assertJobSelection([JOB_CONFIG.job_id]); | ||
|
||
await ml.testExecution.logTestStep('pre-fills the detector input'); | ||
await ml.singleMetricViewer.assertDetectorInputExist(); | ||
await ml.singleMetricViewer.assertDetectorInputValue('0'); | ||
|
||
await ml.testExecution.logTestStep('displays the chart'); | ||
await ml.singleMetricViewer.assertChartExist(); | ||
|
||
await ml.testExecution.logTestStep('should not display the forecasts toggle checkbox'); | ||
await ml.forecast.assertForecastCheckboxMissing(); | ||
|
||
await ml.testExecution.logTestStep('should open the forecasts modal'); | ||
await ml.forecast.assertForecastButtonExists(); | ||
await ml.forecast.assertForecastButtonEnabled(true); | ||
await ml.forecast.openForecastModal(); | ||
await ml.forecast.assertForecastModalRunButtonEnabled(true); | ||
|
||
await ml.testExecution.logTestStep('should run the forecast and close the modal'); | ||
await ml.forecast.clickForecastModalRunButton(); | ||
|
||
await ml.testExecution.logTestStep('should display the forecasts toggle checkbox'); | ||
await ml.forecast.assertForecastCheckboxExists(); | ||
|
||
await ml.testExecution.logTestStep( | ||
'should display the forecast in the single metric chart' | ||
); | ||
await ml.forecast.assertForecastChartElementsExists(); | ||
|
||
await ml.testExecution.logTestStep('should hide the forecast in the single metric chart'); | ||
await ml.forecast.clickForecastCheckbox(); | ||
await ml.forecast.assertForecastChartElementsHidden(); | ||
|
||
await ml.testExecution.logTestStep('should open the forecasts modal and list the forecast'); | ||
await ml.forecast.assertForecastButtonExists(); | ||
await ml.forecast.assertForecastButtonEnabled(true); | ||
await ml.forecast.openForecastModal(); | ||
await ml.forecast.assertForecastTableExists(); | ||
await ml.forecast.assertForecastTableNotEmpty(); | ||
}); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/* | ||
* 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 MachineLearningForecastProvider({ getService }: FtrProviderContext) { | ||
const testSubjects = getService('testSubjects'); | ||
|
||
return { | ||
async assertForecastButtonExists() { | ||
await testSubjects.existOrFail( | ||
'mlSingleMetricViewerSeriesControls > mlSingleMetricViewerButtonForecast' | ||
); | ||
}, | ||
|
||
async assertForecastButtonEnabled(expectedValue: boolean) { | ||
const isEnabled = await testSubjects.isEnabled( | ||
'mlSingleMetricViewerSeriesControls > mlSingleMetricViewerButtonForecast' | ||
); | ||
expect(isEnabled).to.eql( | ||
expectedValue, | ||
`Expected "forecast" button to be '${expectedValue ? 'enabled' : 'disabled'}' (got '${ | ||
isEnabled ? 'enabled' : 'disabled' | ||
}')` | ||
); | ||
}, | ||
|
||
async assertForecastChartElementsExists() { | ||
await testSubjects.existOrFail(`mlForecastArea`, { | ||
timeout: 30 * 1000, | ||
}); | ||
await testSubjects.existOrFail(`mlForecastValuesline`, { | ||
timeout: 30 * 1000, | ||
}); | ||
await testSubjects.existOrFail(`mlForecastMarkers`, { | ||
timeout: 30 * 1000, | ||
}); | ||
}, | ||
|
||
async assertForecastChartElementsHidden() { | ||
await testSubjects.missingOrFail(`mlForecastArea`, { | ||
allowHidden: true, | ||
timeout: 30 * 1000, | ||
}); | ||
await testSubjects.missingOrFail(`mlForecastValuesline`, { | ||
allowHidden: true, | ||
timeout: 30 * 1000, | ||
}); | ||
await testSubjects.missingOrFail(`mlForecastMarkers`, { | ||
allowHidden: true, | ||
timeout: 30 * 1000, | ||
}); | ||
}, | ||
|
||
async assertForecastCheckboxExists() { | ||
await testSubjects.existOrFail(`mlForecastCheckbox`, { | ||
timeout: 30 * 1000, | ||
}); | ||
}, | ||
|
||
async assertForecastCheckboxMissing() { | ||
await testSubjects.missingOrFail(`mlForecastCheckbox`, { | ||
timeout: 30 * 1000, | ||
}); | ||
}, | ||
|
||
async clickForecastCheckbox() { | ||
await testSubjects.click('mlForecastCheckbox'); | ||
}, | ||
|
||
async openForecastModal() { | ||
await testSubjects.click( | ||
'mlSingleMetricViewerSeriesControls > mlSingleMetricViewerButtonForecast' | ||
); | ||
await testSubjects.existOrFail('mlModalForecast'); | ||
}, | ||
|
||
async closeForecastModal() { | ||
await testSubjects.click('mlModalForecast > mlModalForecastButtonClose'); | ||
await this.assertForecastModalMissing(); | ||
}, | ||
|
||
async assertForecastModalMissing() { | ||
await testSubjects.missingOrFail(`mlModalForecast`, { | ||
timeout: 30 * 1000, | ||
}); | ||
}, | ||
|
||
async assertForecastModalRunButtonEnabled(expectedValue: boolean) { | ||
const isEnabled = await testSubjects.isEnabled('mlModalForecast > mlModalForecastButtonRun'); | ||
expect(isEnabled).to.eql( | ||
expectedValue, | ||
`Expected forecast "run" button to be '${expectedValue ? 'enabled' : 'disabled'}' (got '${ | ||
isEnabled ? 'enabled' : 'disabled' | ||
}')` | ||
); | ||
}, | ||
|
||
async assertForecastTableExists() { | ||
await testSubjects.existOrFail('mlModalForecast > mlModalForecastTable'); | ||
}, | ||
|
||
async clickForecastModalRunButton() { | ||
await testSubjects.click('mlModalForecast > mlModalForecastButtonRun'); | ||
await this.assertForecastModalMissing(); | ||
}, | ||
|
||
async getForecastTableRows() { | ||
return await testSubjects.findAll('mlModalForecastTable > ~mlForecastsListRow'); | ||
}, | ||
|
||
async assertForecastTableNotEmpty() { | ||
const tableRows = await this.getForecastTableRows(); | ||
expect(tableRows.length).to.be.greaterThan( | ||
0, | ||
`Forecast table should have at least one row (got '${tableRows.length}')` | ||
); | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.