Skip to content

Commit

Permalink
[ML] Fixing empty time range when cloning jobs (#45286)
Browse files Browse the repository at this point in the history
* [ML] Fixing empty time range when cloning jobs

* removing if statement
  • Loading branch information
jgowdyelastic authored Sep 11, 2019
1 parent 4f7ce19 commit d916e92
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,13 @@ export function cloneJob(jobId) {
// if the job is from a wizards, i.e. contains a created_by property
// use tempJobCloningObjects to temporarily store the job
mlJobService.tempJobCloningObjects.job = job;

if (job.data_counts.earliest_record_timestamp !== undefined && job.data_counts.latest_record_timestamp !== undefined) {
// if the job has run before, use the earliest and latest record timestamp
// as the cloned job's time range
mlJobService.tempJobCloningObjects.start = job.data_counts.earliest_record_timestamp;
mlJobService.tempJobCloningObjects.end = job.data_counts.latest_record_timestamp;
}
} else {
// otherwise use the currentJob
mlJobService.currentJob = job;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ export function isSparseDataJob(job: Job, datafeed: Datafeed): boolean {
function stashCombinedJob(
jobCreator: JobCreatorType,
skipTimeRangeStep: boolean = false,
advanced: boolean = false
advanced: boolean = false,
includeTimeRange: boolean = false
) {
const combinedJob = {
...jobCreator.jobConfig,
Expand All @@ -138,16 +139,22 @@ function stashCombinedJob(
mlJobService.currentJob = combinedJob;
} else {
mlJobService.tempJobCloningObjects.job = combinedJob;
}

if (skipTimeRangeStep === true) {
mlJobService.tempJobCloningObjects.skipTimeRangeStep = true;
// skip over the time picker step of the wizard
mlJobService.tempJobCloningObjects.skipTimeRangeStep = skipTimeRangeStep;

if (includeTimeRange === true) {
// auto select the start and end dates of the time picker
mlJobService.tempJobCloningObjects.start = jobCreator.start;
mlJobService.tempJobCloningObjects.end = jobCreator.end;
}
}
}

export function convertToMultiMetricJob(jobCreator: JobCreatorType) {
jobCreator.createdBy = CREATED_BY_LABEL.MULTI_METRIC;
stashCombinedJob(jobCreator, true, false);
jobCreator.modelPlot = false;
stashCombinedJob(jobCreator, true, false, true);

window.location.href = window.location.href.replace(
JOB_TYPE.SINGLE_METRIC,
Expand All @@ -157,7 +164,7 @@ export function convertToMultiMetricJob(jobCreator: JobCreatorType) {

export function convertToAdvancedJob(jobCreator: JobCreatorType) {
jobCreator.createdBy = null;
stashCombinedJob(jobCreator, false, true);
stashCombinedJob(jobCreator, false, true, false);

let jobType = JOB_TYPE.SINGLE_METRIC;
if (isMultiMetricJobCreator(jobCreator)) {
Expand All @@ -171,7 +178,7 @@ export function convertToAdvancedJob(jobCreator: JobCreatorType) {

export function resetJob(jobCreator: JobCreatorType) {
jobCreator.jobId = '';
stashCombinedJob(jobCreator, true, false);
stashCombinedJob(jobCreator, true, false, true);

window.location.href = '#/jobs/new_job';
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,22 @@ export const Page: FC<PageProps> = ({ existingJobsAndGroups, jobType }) => {
if (skipTimeRangeStep === false) {
jobCreator.jobId = '';
}

mlJobService.tempJobCloningObjects.skipTimeRangeStep = false;
mlJobService.tempJobCloningObjects.job = undefined;

if (
mlJobService.tempJobCloningObjects.start !== undefined &&
mlJobService.tempJobCloningObjects.end !== undefined
) {
// auto select the start and end dates for the time range picker
jobCreator.setTimeRange(
mlJobService.tempJobCloningObjects.start,
mlJobService.tempJobCloningObjects.end
);
mlJobService.tempJobCloningObjects.start = undefined;
mlJobService.tempJobCloningObjects.end = undefined;
}
} else {
jobCreator.bucketSpan = DEFAULT_BUCKET_SPAN;

Expand All @@ -80,7 +94,7 @@ export const Page: FC<PageProps> = ({ existingJobsAndGroups, jobType }) => {
jobCreator.modelPlot = true;
}

if (kibanaContext.currentSavedSearch.id === undefined) {
if (kibanaContext.currentSavedSearch.id !== undefined) {
// Jobs created from saved searches cannot be cloned in the wizard as the
// ML job config holds no reference to the saved search ID.
jobCreator.createdBy = null;
Expand Down
2 changes: 2 additions & 0 deletions x-pack/legacy/plugins/ml/public/services/job_service.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ declare interface JobService {
tempJobCloningObjects: {
job: any;
skipTimeRangeStep: boolean;
start?: number;
end?: number;
};
skipTimeRangeStep: boolean;
saveNewJob(job: any): Promise<any>;
Expand Down
2 changes: 2 additions & 0 deletions x-pack/legacy/plugins/ml/public/services/job_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class JobService {
this.tempJobCloningObjects = {
job: undefined,
skipTimeRangeStep: false,
start: undefined,
end: undefined,
};

this.jobs = [];
Expand Down

0 comments on commit d916e92

Please sign in to comment.