Skip to content

Commit

Permalink
[ML] Fixing various issues when cloning a job using a wizard (#23368) (
Browse files Browse the repository at this point in the history
  • Loading branch information
jgowdyelastic authored Sep 22, 2018
1 parent e4553de commit 848de4d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function populateSingleMetricSettings(jobSettings, scope) {
if (f.agg !== undefined) {
// find the aggregation object in the aggTypeOptions list which has the same name
// as the agg setting in the url
const agg = scope.ui.aggTypeOptions.find(o => (o.name === f.agg));
const agg = scope.ui.aggTypeOptions.find(o => (o.mlName === f.agg));
if (agg !== undefined) {
scope.formConfig.agg.type = agg;
scope.aggChange();
Expand Down Expand Up @@ -83,7 +83,7 @@ function populateMultiMetricSettings(jobSettings, scope) {
}

if (f.agg !== undefined) {
const agg = scope.ui.aggTypeOptions.find(o => (o.name === f.agg));
const agg = scope.ui.aggTypeOptions.find(o => (o.mlName === f.agg));
if (agg !== undefined) {
scope.formConfig.fields[field.id].agg.type = agg;
}
Expand Down Expand Up @@ -124,7 +124,7 @@ function populatePopulationSettings(jobSettings, scope) {
if (field !== undefined) {

if (f.agg !== undefined) {
const agg = scope.ui.aggTypeOptions.find(o => (o.name === f.agg));
const agg = scope.ui.aggTypeOptions.find(o => (o.mlName === f.agg));
if (agg !== undefined) {
field.agg = { type: agg };
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function jobSettingsFromJob(job, aggTypeOptions) {

function getKibanaAggName(mlAggName) {
const agg = aggTypeOptions.find(a => a.mlName === mlAggName);
return (agg) ? agg.name : undefined;
return (agg) ? agg.mlName : undefined;
}

const jobSettings = {};
Expand All @@ -43,7 +43,19 @@ export function jobSettingsFromJob(job, aggTypeOptions) {
if (job.custom_settings.created_by === WIZARD_TYPE.SINGLE_METRIC) {
// single metric
const d = dtrs[0];
const field = { agg: getKibanaAggName(d.function, aggTypeOptions) };
let func = d.function;

// distinct_count jobs in single metric wizard use a particular aggregation where
// the detector function is replaced as non_zero_count.
// here we look for this exact situation and switch the function back to distinct_count
if (
func === 'non_zero_count' &&
job.analysis_config.summary_count_field_name !== undefined &&
job.analysis_config.summary_count_field_name.match(/^dc_.+/)) {
func = 'distinct_count';
}

const field = { agg: getKibanaAggName(func) };
if (d.field_name) {
field.fieldName = d.field_name;
}
Expand All @@ -58,7 +70,7 @@ export function jobSettingsFromJob(job, aggTypeOptions) {
splitField = d.partition_field_name;
}

const field = { agg: getKibanaAggName(d.function, aggTypeOptions) };
const field = { agg: getKibanaAggName(d.function) };
if (d.field_name) {
field.fieldName = d.field_name;
}
Expand All @@ -79,7 +91,7 @@ export function jobSettingsFromJob(job, aggTypeOptions) {
overField = d.over_field_name;
}

const field = { agg: getKibanaAggName(d.function, aggTypeOptions) };
const field = { agg: getKibanaAggName(d.function) };
if (d.field_name) {
field.fieldName = d.field_name;
}
Expand Down
6 changes: 6 additions & 0 deletions x-pack/plugins/ml/public/services/job_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,12 @@ class JobService {
}
}

// when jumping from a wizard to the advanced job creation,
// the wizard's created_by information should be stripped.
if (tempJob.custom_settings && tempJob.custom_settings.created_by) {
delete tempJob.custom_settings.created_by;
}

return tempJob;
}

Expand Down

0 comments on commit 848de4d

Please sign in to comment.