Skip to content

Commit

Permalink
[ML] Display warning if clone job fails due to missing data view
Browse files Browse the repository at this point in the history
  • Loading branch information
peteharverson committed Nov 11, 2021
1 parent 0b5a434 commit ae935aa
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,22 @@ export async function cloneJob(jobId) {
]);

const dataViewNames = await getDataViewNames();
const jobIndicesAvailable = dataViewNames.includes(datafeed.indices.join(','));
const dataViewTitle = datafeed.indices.join(',');
const jobIndicesAvailable = dataViewNames.includes(dataViewTitle);

if (jobIndicesAvailable === false) {
const warningText = i18n.translate(
'xpack.ml.jobsList.managementActions.noSourceDataViewForClone',
{
defaultMessage:
'Unable to clone the anomaly detection job {jobId}. No data view exists for index {dataViewTitle}.',
values: { jobId, dataViewTitle },
}
);
getToastNotifications().addDanger({
title: warningText,
'data-test-subj': 'mlCloneJobNoDataViewExistsWarningToast',
});
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { FtrProviderContext } from '../../../ftr_provider_context';
export default function ({ getService }: FtrProviderContext) {
const esArchiver = getService('esArchiver');
const ml = getService('ml');
const browser = getService('browser');

const jobId = `fq_single_1_${Date.now()}`;
const jobIdClone = `${jobId}_clone`;
Expand Down Expand Up @@ -201,7 +202,26 @@ export default function ({ getService }: FtrProviderContext) {
await ml.api.assertDetectorResultsExist(jobId, 0);
});

it('job cloning fails in the single metric wizard if a matching data view does not exist', async () => {
await ml.testExecution.logTestStep('delete data view used by job');
await ml.testResources.deleteIndexPatternByTitle('ft_farequote');

// Refresh page to ensure page has correct cache of data views
await browser.refresh();

await ml.testExecution.logTestStep(
'job cloning clicks the clone action and loads the single metric wizard'
);
await ml.jobTable.clickCloneJobActionWhenNoDataViewExists(jobId);
});

it('job cloning opens the existing job in the single metric wizard', async () => {
await ml.testExecution.logTestStep('recreate data view used by job');
await ml.testResources.createIndexPatternIfNeeded('ft_farequote', '@timestamp');

// Refresh page to ensure page has correct cache of data views
await browser.refresh();

await ml.testExecution.logTestStep(
'job cloning clicks the clone action and loads the single metric wizard'
);
Expand Down
13 changes: 13 additions & 0 deletions x-pack/test/functional/services/ml/job_table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,19 @@ export function MachineLearningJobTableProvider(
await testSubjects.existOrFail('~mlPageJobWizard');
}

public async clickCloneJobActionWhenNoDataViewExists(jobId: string) {
await this.ensureJobActionsMenuOpen(jobId);
await testSubjects.click('mlActionButtonCloneJob');
await this.assertNoDataViewForCloneJobWarningToastExist();
}

public async assertNoDataViewForCloneJobWarningToastExist() {
await retry.tryForTime(5000, async () => {
const toast = await testSubjects.find('mlCloneJobNoDataViewExistsWarningToast');
expect(toast).not.to.be(undefined);
});
}

public async clickEditJobAction(jobId: string) {
await this.ensureJobActionsMenuOpen(jobId);
await testSubjects.click('mlActionButtonEditJob');
Expand Down

0 comments on commit ae935aa

Please sign in to comment.