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] Adds created_by job property for the advanced wizard #167021

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
1 change: 1 addition & 0 deletions x-pack/plugins/ml/common/constants/new_job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export enum CREATED_BY_LABEL {
SINGLE_METRIC = 'single-metric-wizard',
MULTI_METRIC = 'multi-metric-wizard',
POPULATION = 'population-wizard',
ADVANCED = 'advanced-wizard',
CATEGORIZATION = 'categorization-wizard',
RARE = 'rare-wizard',
GEO = 'geo-wizard',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { mlCalendarService } from '../../../services/calendar_service';
import { isPopulatedObject } from '@kbn/ml-is-populated-object';
import { ML_PAGES } from '../../../../../common/constants/locator';
import { PLUGIN_ID } from '../../../../../common/constants/app';
import { CREATED_BY_LABEL } from '../../../../../common/constants/new_job';

export function loadFullJob(jobId) {
return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -240,7 +241,12 @@ export async function cloneJob(jobId) {
return;
}

if (cloneableJob !== undefined && originalJob?.custom_settings?.created_by !== undefined) {
const createdBy = originalJob?.custom_settings?.created_by;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I export jobs, looks like created_by is removed (tried an advanced job and a multi-metric one). I can't remember - was this intentional?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're using the flag exclude_generated: true when retrieving the jobs from es. This removes the created_by prop.
If we think it would be better to not strip this out, I can change it in a separate PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds a good idea to retain created_by on export, and to do it in a separate PR.

if (
cloneableJob !== undefined &&
createdBy !== undefined &&
createdBy !== CREATED_BY_LABEL.ADVANCED
) {
// if the job is from a wizards, i.e. contains a created_by property
// use tempJobCloningObjects to temporarily store the job
mlJobService.tempJobCloningObjects.createdBy = originalJob?.custom_settings?.created_by;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import type { Field, Aggregation, SplitField } from '@kbn/ml-anomaly-utils';
import type { SavedSearch } from '@kbn/saved-search-plugin/public';

import { JobCreator } from './job_creator';
import {
import type {
Job,
Datafeed,
Detector,
CustomRule,
} from '../../../../../../common/types/anomaly_detection_jobs';
import { createBasicDetector } from './util/default_configs';
import { JOB_TYPE } from '../../../../../../common/constants/new_job';
import { CREATED_BY_LABEL, JOB_TYPE } from '../../../../../../common/constants/new_job';
import { getRichDetectors } from './util/general';
import { isValidJson } from '../../../../../../common/util/validation_utils';

Expand All @@ -41,6 +41,7 @@ export class AdvancedJobCreator extends JobCreator {

constructor(indexPattern: DataView, savedSearch: SavedSearch | null, query: object) {
super(indexPattern, savedSearch, query);
this.createdBy = CREATED_BY_LABEL.ADVANCED;

this._queryString = JSON.stringify(this._datafeed_config.query);

Expand Down Expand Up @@ -182,6 +183,7 @@ export class AdvancedJobCreator extends JobCreator {

public cloneFromExistingJob(job: Job, datafeed: Datafeed) {
this._overrideConfigs(job, datafeed);
this.createdBy = CREATED_BY_LABEL.ADVANCED;
const detectors = getRichDetectors(job, datafeed, this.additionalFields, true);

// keep track of the custom rules for each detector
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import type { DataView } from '@kbn/data-views-plugin/public';
import type { Field, Aggregation, SplitField, AggFieldPair } from '@kbn/ml-anomaly-utils';
import type { SavedSearch } from '@kbn/saved-search-plugin/public';
import { JobCreator } from './job_creator';
import { Job, Datafeed, Detector } from '../../../../../../common/types/anomaly_detection_jobs';
import type {
Job,
Datafeed,
Detector,
} from '../../../../../../common/types/anomaly_detection_jobs';
import { createBasicDetector } from './util/default_configs';
import { JOB_TYPE, CREATED_BY_LABEL } from '../../../../../../common/constants/new_job';
import { getRichDetectors } from './util/general';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import type { DataView } from '@kbn/data-views-plugin/public';
import type { Field, Aggregation, SplitField, AggFieldPair } from '@kbn/ml-anomaly-utils';
import type { SavedSearch } from '@kbn/saved-search-plugin/public';
import { JobCreator } from './job_creator';
import { Job, Datafeed, Detector } from '../../../../../../common/types/anomaly_detection_jobs';
import type {
Job,
Datafeed,
Detector,
} from '../../../../../../common/types/anomaly_detection_jobs';
import { createBasicDetector } from './util/default_configs';
import { JOB_TYPE, CREATED_BY_LABEL } from '../../../../../../common/constants/new_job';
import { getRichDetectors } from './util/general';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import type { DataView } from '@kbn/data-views-plugin/public';
import type { Field, Aggregation, SplitField, AggFieldPair } from '@kbn/ml-anomaly-utils';
import type { SavedSearch } from '@kbn/saved-search-plugin/public';
import { JobCreator } from './job_creator';
import { Job, Datafeed, Detector } from '../../../../../../common/types/anomaly_detection_jobs';
import type {
Job,
Datafeed,
Detector,
} from '../../../../../../common/types/anomaly_detection_jobs';
import { createBasicDetector } from './util/default_configs';
import { JOB_TYPE, CREATED_BY_LABEL } from '../../../../../../common/constants/new_job';
import { getRichDetectors } from './util/general';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ import {
} from '@kbn/ml-anomaly-utils';
import type { SavedSearch } from '@kbn/saved-search-plugin/public';
import { JobCreator } from './job_creator';
import { Job, Datafeed, Detector } from '../../../../../../common/types/anomaly_detection_jobs';
import type {
Job,
Datafeed,
Detector,
} from '../../../../../../common/types/anomaly_detection_jobs';
import { JOB_TYPE, CREATED_BY_LABEL } from '../../../../../../common/constants/new_job';
import { getRichDetectors, isSparseDataJob } from './util/general';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
import type { SavedSearch } from '@kbn/saved-search-plugin/public';
import { parseInterval } from '../../../../../../common/util/parse_interval';
import { JobCreator } from './job_creator';
import {
import type {
Job,
Datafeed,
Detector,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ async function getWizardUrlFromCloningJob(createdBy: string | undefined, dataVie
case CREATED_BY_LABEL.GEO:
page = JOB_TYPE.GEO;
break;
case CREATED_BY_LABEL.ADVANCED:
default:
page = JOB_TYPE.ADVANCED;
break;
Expand Down
Loading