Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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