Skip to content

Commit bcc0d0b

Browse files
[ML] Adding option to create AD jobs without starting the datafeed (#77484)
* [ML] Adding option to create AD jobs without starting the datafeed * changing translation id * i just need some space * adding missed spelling change * disabling switch when running * improving logic * further test improvements Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
1 parent 9355f5d commit bcc0d0b

12 files changed

Lines changed: 273 additions & 18 deletions

File tree

x-pack/plugins/ml/public/application/jobs/new_job/common/job_creator/util/general.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,13 @@ export function resetJob(jobCreator: JobCreatorType, navigateToPath: NavigateToP
268268
navigateToPath('/jobs/new_job');
269269
}
270270

271-
export function advancedStartDatafeed(jobCreator: JobCreatorType, navigateToPath: NavigateToPath) {
272-
stashCombinedJob(jobCreator, false, false);
271+
export function advancedStartDatafeed(
272+
jobCreator: JobCreatorType | null,
273+
navigateToPath: NavigateToPath
274+
) {
275+
if (jobCreator !== null) {
276+
stashCombinedJob(jobCreator, false, false);
277+
}
273278
navigateToPath('/jobs');
274279
}
275280

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
export { StartDatafeedSwitch } from './start_datafeed_switch';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import React, { FC } from 'react';
8+
import { i18n } from '@kbn/i18n';
9+
import { EuiSwitch, EuiFormRow, EuiSpacer } from '@elastic/eui';
10+
interface Props {
11+
startDatafeed: boolean;
12+
setStartDatafeed(start: boolean): void;
13+
disabled?: boolean;
14+
}
15+
16+
export const StartDatafeedSwitch: FC<Props> = ({
17+
startDatafeed,
18+
setStartDatafeed,
19+
disabled = false,
20+
}) => {
21+
return (
22+
<>
23+
<EuiSpacer />
24+
<EuiFormRow
25+
helpText={i18n.translate(
26+
'xpack.ml.newJob.wizard.summaryStep.startDatafeedCheckboxHelpText',
27+
{
28+
defaultMessage: 'If unselected, job can be started later from the jobs list.',
29+
}
30+
)}
31+
>
32+
<EuiSwitch
33+
data-test-subj="mlJobWizardStartDatafeedCheckbox"
34+
label={i18n.translate('xpack.ml.newJob.wizard.summaryStep.startDatafeedCheckbox', {
35+
defaultMessage: 'Start immediately',
36+
})}
37+
checked={startDatafeed}
38+
onChange={(e) => setStartDatafeed(e.target.checked)}
39+
disabled={disabled}
40+
/>
41+
</EuiFormRow>
42+
</>
43+
);
44+
};

x-pack/plugins/ml/public/application/jobs/new_job/pages/components/summary_step/summary.tsx

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { DatafeedDetails } from './components/datafeed_details';
2828
import { DetectorChart } from './components/detector_chart';
2929
import { JobProgress } from './components/job_progress';
3030
import { PostSaveOptions } from './components/post_save_options';
31+
import { StartDatafeedSwitch } from './components/start_datafeed_switch';
3132
import { toastNotificationServiceProvider } from '../../../../../services/toast_notification_service';
3233
import {
3334
convertToAdvancedJob,
@@ -50,6 +51,7 @@ export const SummaryStep: FC<StepProps> = ({ setCurrentStep, isCurrentStep }) =>
5051
const [creatingJob, setCreatingJob] = useState(false);
5152
const [isValid, setIsValid] = useState(jobValidator.validationSummary.basic);
5253
const [jobRunner, setJobRunner] = useState<JobRunner | null>(null);
54+
const [startDatafeed, setStartDatafeed] = useState(true);
5355

5456
const isAdvanced = isAdvancedJobCreator(jobCreator);
5557
const jsonEditorMode = isAdvanced ? EDITOR_MODE.EDITABLE : EDITOR_MODE.READONLY;
@@ -59,15 +61,17 @@ export const SummaryStep: FC<StepProps> = ({ setCurrentStep, isCurrentStep }) =>
5961
}, []);
6062

6163
async function start() {
64+
setCreatingJob(true);
6265
if (isAdvanced) {
63-
await startAdvanced();
66+
await createAdvancedJob();
67+
} else if (startDatafeed === true) {
68+
await createAndStartJob();
6469
} else {
65-
await startInline();
70+
await createAdvancedJob(false);
6671
}
6772
}
6873

69-
async function startInline() {
70-
setCreatingJob(true);
74+
async function createAndStartJob() {
7175
try {
7276
const jr = await jobCreator.createAndStartJob();
7377
setJobRunner(jr);
@@ -76,12 +80,11 @@ export const SummaryStep: FC<StepProps> = ({ setCurrentStep, isCurrentStep }) =>
7680
}
7781
}
7882

79-
async function startAdvanced() {
80-
setCreatingJob(true);
83+
async function createAdvancedJob(showStartModal: boolean = true) {
8184
try {
8285
await jobCreator.createJob();
8386
await jobCreator.createDatafeed();
84-
advancedStartDatafeed(jobCreator, navigateToPath);
87+
advancedStartDatafeed(showStartModal ? jobCreator : null, navigateToPath);
8588
} catch (error) {
8689
handleJobCreationError(error);
8790
}
@@ -131,6 +134,14 @@ export const SummaryStep: FC<StepProps> = ({ setCurrentStep, isCurrentStep }) =>
131134
<EuiSpacer size="m" />
132135
<JobDetails />
133136

137+
{isAdvanced === false && (
138+
<StartDatafeedSwitch
139+
startDatafeed={startDatafeed}
140+
setStartDatafeed={setStartDatafeed}
141+
disabled={creatingJob}
142+
/>
143+
)}
144+
134145
{isAdvanced && (
135146
<Fragment>
136147
<EuiHorizontalRule />

x-pack/test/functional/apps/ml/anomaly_detection/categorization_job.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export default function ({ getService }: FtrProviderContext) {
108108
await ml.testExecution.logTestStep('job creation displays the time range step');
109109
await ml.jobWizardCommon.assertTimeRangeSectionExists();
110110

111-
await ml.testExecution.logTestStep('job creation sets the timerange');
111+
await ml.testExecution.logTestStep('job creation sets the time range');
112112
await ml.jobWizardCommon.clickUseFullDataButton(
113113
'Apr 5, 2019 @ 11:25:35.770',
114114
'Nov 21, 2019 @ 06:01:13.914'
@@ -230,7 +230,7 @@ export default function ({ getService }: FtrProviderContext) {
230230
await ml.testExecution.logTestStep('job cloning displays the time range step');
231231
await ml.jobWizardCommon.assertTimeRangeSectionExists();
232232

233-
await ml.testExecution.logTestStep('job cloning sets the timerange');
233+
await ml.testExecution.logTestStep('job cloning sets the time range');
234234
await ml.jobWizardCommon.clickUseFullDataButton(
235235
'Apr 5, 2019 @ 11:25:35.770',
236236
'Nov 21, 2019 @ 06:01:13.914'

x-pack/test/functional/apps/ml/anomaly_detection/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export default function ({ loadTestFile }: FtrProviderContext) {
1010
this.tags(['skipFirefox']);
1111

1212
loadTestFile(require.resolve('./single_metric_job'));
13+
loadTestFile(require.resolve('./single_metric_job_without_datafeed_start'));
1314
loadTestFile(require.resolve('./multi_metric_job'));
1415
loadTestFile(require.resolve('./population_job'));
1516
loadTestFile(require.resolve('./saved_search_job'));

x-pack/test/functional/apps/ml/anomaly_detection/multi_metric_job.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export default function ({ getService }: FtrProviderContext) {
104104
await ml.testExecution.logTestStep('job creation displays the time range step');
105105
await ml.jobWizardCommon.assertTimeRangeSectionExists();
106106

107-
await ml.testExecution.logTestStep('job creation sets the timerange');
107+
await ml.testExecution.logTestStep('job creation sets the time range');
108108
await ml.jobWizardCommon.clickUseFullDataButton(
109109
'Feb 7, 2016 @ 00:00:00.000',
110110
'Feb 11, 2016 @ 23:59:54.000'
@@ -235,7 +235,7 @@ export default function ({ getService }: FtrProviderContext) {
235235
await ml.testExecution.logTestStep('job cloning displays the time range step');
236236
await ml.jobWizardCommon.assertTimeRangeSectionExists();
237237

238-
await ml.testExecution.logTestStep('job cloning sets the timerange');
238+
await ml.testExecution.logTestStep('job cloning sets the time range');
239239
await ml.jobWizardCommon.clickUseFullDataButton(
240240
'Feb 7, 2016 @ 00:00:00.000',
241241
'Feb 11, 2016 @ 23:59:54.000'

x-pack/test/functional/apps/ml/anomaly_detection/population_job.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export default function ({ getService }: FtrProviderContext) {
118118
await ml.testExecution.logTestStep('job creation displays the time range step');
119119
await ml.jobWizardCommon.assertTimeRangeSectionExists();
120120

121-
await ml.testExecution.logTestStep('job creation sets the timerange');
121+
await ml.testExecution.logTestStep('job creation sets the time range');
122122
await ml.jobWizardCommon.clickUseFullDataButton(
123123
'Jun 12, 2019 @ 00:04:19.000',
124124
'Jul 12, 2019 @ 23:45:36.000'
@@ -261,7 +261,7 @@ export default function ({ getService }: FtrProviderContext) {
261261
await ml.testExecution.logTestStep('job cloning displays the time range step');
262262
await ml.jobWizardCommon.assertTimeRangeSectionExists();
263263

264-
await ml.testExecution.logTestStep('job cloning sets the timerange');
264+
await ml.testExecution.logTestStep('job cloning sets the time range');
265265
await ml.jobWizardCommon.clickUseFullDataButton(
266266
'Jun 12, 2019 @ 00:04:19.000',
267267
'Jul 12, 2019 @ 23:45:36.000'

x-pack/test/functional/apps/ml/anomaly_detection/saved_search_job.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ export default function ({ getService }: FtrProviderContext) {
306306
await ml.testExecution.logTestStep('job creation displays the time range step');
307307
await ml.jobWizardCommon.assertTimeRangeSectionExists();
308308

309-
await ml.testExecution.logTestStep('job creation sets the timerange');
309+
await ml.testExecution.logTestStep('job creation sets the time range');
310310
await ml.jobWizardCommon.clickUseFullDataButton(
311311
'Feb 7, 2016 @ 00:00:00.000',
312312
'Feb 11, 2016 @ 23:59:54.000'

x-pack/test/functional/apps/ml/anomaly_detection/single_metric_job.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export default function ({ getService }: FtrProviderContext) {
103103
await ml.testExecution.logTestStep('job creation displays the time range step');
104104
await ml.jobWizardCommon.assertTimeRangeSectionExists();
105105

106-
await ml.testExecution.logTestStep('job creation sets the timerange');
106+
await ml.testExecution.logTestStep('job creation sets the time range');
107107
await ml.jobWizardCommon.clickUseFullDataButton(
108108
'Feb 7, 2016 @ 00:00:00.000',
109109
'Feb 11, 2016 @ 23:59:54.000'
@@ -212,7 +212,7 @@ export default function ({ getService }: FtrProviderContext) {
212212
await ml.testExecution.logTestStep('job cloning displays the time range step');
213213
await ml.jobWizardCommon.assertTimeRangeSectionExists();
214214

215-
await ml.testExecution.logTestStep('job cloning sets the timerange');
215+
await ml.testExecution.logTestStep('job cloning sets the time range');
216216
await ml.jobWizardCommon.clickUseFullDataButton(
217217
'Feb 7, 2016 @ 00:00:00.000',
218218
'Feb 11, 2016 @ 23:59:54.000'

0 commit comments

Comments
 (0)