Skip to content

Commit

Permalink
[ML] Display warning if clone job fails due to missing data view (ela…
Browse files Browse the repository at this point in the history
…stic#117993)

* [ML] Display warning if clone job fails due to missing data view

* [ML] Edits following review

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
2 people authored and fkanout committed Nov 17, 2021
1 parent 374ac68 commit 7d49c73
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,21 @@ 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 },
}
);
getToastNotificationService().displayDangerToast(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 displays an error toast'
);
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
10 changes: 10 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,16 @@ 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 testSubjects.existOrFail('mlCloneJobNoDataViewExistsWarningToast', { timeout: 5000 });
}

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

0 comments on commit 7d49c73

Please sign in to comment.