From 2b3d6afc73bd12134f726fcc1a12eee405c2d0b4 Mon Sep 17 00:00:00 2001 From: James Gowdy Date: Fri, 12 Jun 2020 13:32:52 +0100 Subject: [PATCH 1/5] [ML] Allow editing of model_snapshot_retention_days --- .../edit_job_flyout/edit_job_flyout.js | 9 +++++ .../components/edit_job_flyout/edit_utils.js | 9 +++++ .../edit_job_flyout/tabs/job_details.js | 40 ++++++++++++++++++- .../schemas/anomaly_detectors_schema.ts | 1 + 4 files changed, 58 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/ml/public/application/jobs/jobs_list/components/edit_job_flyout/edit_job_flyout.js b/x-pack/plugins/ml/public/application/jobs/jobs_list/components/edit_job_flyout/edit_job_flyout.js index b463322ea55db..210af3b03e5f0 100644 --- a/x-pack/plugins/ml/public/application/jobs/jobs_list/components/edit_job_flyout/edit_job_flyout.js +++ b/x-pack/plugins/ml/public/application/jobs/jobs_list/components/edit_job_flyout/edit_job_flyout.js @@ -48,6 +48,7 @@ export class EditJobFlyoutUI extends Component { jobDescription: '', jobGroups: [], jobModelMemoryLimit: '', + jobModelSnapshotRetentionDays: 1, jobDetectors: [], jobDetectorDescriptions: [], jobCustomUrls: [], @@ -96,6 +97,7 @@ export class EditJobFlyoutUI extends Component { 'jobDescription', 'jobGroups', 'jobModelMemoryLimit', + 'jobModelSnapshotRetentionDays', 'jobCustomUrls', 'jobDetectors', 'jobDetectorDescriptions', @@ -128,6 +130,9 @@ export class EditJobFlyoutUI extends Component { job.analysis_limits && job.analysis_limits.model_memory_limit ? job.analysis_limits.model_memory_limit : ''; + + const modelSnapshotRetentionDays = + job.model_snapshot_retention_days !== undefined ? job.model_snapshot_retention_days : 1; const detectors = job.analysis_config && job.analysis_config.detectors ? [...job.analysis_config.detectors] @@ -146,6 +151,7 @@ export class EditJobFlyoutUI extends Component { jobDescription: job.description, jobGroups: job.groups !== undefined ? job.groups : [], jobModelMemoryLimit: mml, + jobModelSnapshotRetentionDays: modelSnapshotRetentionDays, jobDetectors: detectors, jobDetectorDescriptions: detectors.map((d) => d.detector_description), jobBucketSpan: bucketSpan, @@ -229,6 +235,7 @@ export class EditJobFlyoutUI extends Component { description: this.state.jobDescription, groups: this.state.jobGroups, mml: this.state.jobModelMemoryLimit, + modelSnapshotRetentionDays: this.state.jobModelSnapshotRetentionDays, detectorDescriptions: this.state.jobDetectorDescriptions, datafeedQuery: collapseLiteralStrings(this.state.datafeedQuery), datafeedQueryDelay: this.state.datafeedQueryDelay, @@ -275,6 +282,7 @@ export class EditJobFlyoutUI extends Component { jobDescription, jobGroups, jobModelMemoryLimit, + jobModelSnapshotRetentionDays, jobDetectors, jobDetectorDescriptions, jobBucketSpan, @@ -302,6 +310,7 @@ export class EditJobFlyoutUI extends Component { jobDescription={jobDescription} jobGroups={jobGroups} jobModelMemoryLimit={jobModelMemoryLimit} + jobModelSnapshotRetentionDays={jobModelSnapshotRetentionDays} setJobDetails={this.setJobDetails} jobGroupsValidationError={jobGroupsValidationError} jobModelMemoryLimitValidationError={jobModelMemoryLimitValidationError} diff --git a/x-pack/plugins/ml/public/application/jobs/jobs_list/components/edit_job_flyout/edit_utils.js b/x-pack/plugins/ml/public/application/jobs/jobs_list/components/edit_job_flyout/edit_utils.js index fcd2c09f72767..5d57e1b879766 100644 --- a/x-pack/plugins/ml/public/application/jobs/jobs_list/components/edit_job_flyout/edit_utils.js +++ b/x-pack/plugins/ml/public/application/jobs/jobs_list/components/edit_job_flyout/edit_utils.js @@ -16,6 +16,7 @@ export function saveJob(job, newJobData, finish) { ...extractDescription(job, newJobData), ...extractGroups(job, newJobData), ...extractMML(job, newJobData), + ...extractModelSnapshotRetentionDays(job, newJobData), ...extractDetectorDescriptions(job, newJobData), ...extractCustomSettings(job, newJobData), }; @@ -175,6 +176,14 @@ function extractMML(job, newJobData) { return mmlData; } +function extractModelSnapshotRetentionDays(job, newJobData) { + const modelSnapshotRetentionDays = newJobData.modelSnapshotRetentionDays; + if (modelSnapshotRetentionDays !== job.model_snapshot_retention_days) { + return { model_snapshot_retention_days: modelSnapshotRetentionDays }; + } + return {}; +} + function extractDetectorDescriptions(job, newJobData) { const detectors = []; const descriptions = newJobData.detectorDescriptions.map((d, i) => ({ diff --git a/x-pack/plugins/ml/public/application/jobs/jobs_list/components/edit_job_flyout/tabs/job_details.js b/x-pack/plugins/ml/public/application/jobs/jobs_list/components/edit_job_flyout/tabs/job_details.js index 974afafc08b6b..77bbfbc100791 100644 --- a/x-pack/plugins/ml/public/application/jobs/jobs_list/components/edit_job_flyout/tabs/job_details.js +++ b/x-pack/plugins/ml/public/application/jobs/jobs_list/components/edit_job_flyout/tabs/job_details.js @@ -7,7 +7,14 @@ import PropTypes from 'prop-types'; import React, { Component } from 'react'; -import { EuiFieldText, EuiForm, EuiFormRow, EuiSpacer, EuiComboBox } from '@elastic/eui'; +import { + EuiFieldText, + EuiForm, + EuiFormRow, + EuiSpacer, + EuiComboBox, + EuiFieldNumber, +} from '@elastic/eui'; import { ml } from '../../../../../services/ml_api_service'; import { i18n } from '@kbn/i18n'; @@ -24,6 +31,7 @@ export class JobDetails extends Component { mml: '', mmlValidationError: '', groupsValidationError: '', + modelSnapshotRetentionDays: 1, }; this.setJobDetails = props.setJobDetails; @@ -52,6 +60,7 @@ export class JobDetails extends Component { mml: props.jobModelMemoryLimit, mmlValidationError: props.jobModelMemoryLimitValidationError, groupsValidationError: props.jobGroupsValidationError, + modelSnapshotRetentionDays: props.jobModelSnapshotRetentionDays, }; } @@ -63,6 +72,10 @@ export class JobDetails extends Component { this.setJobDetails({ jobModelMemoryLimit: e.target.value }); }; + onModelSnapshotRetentionDaysChange = (e) => { + this.setJobDetails({ jobModelSnapshotRetentionDays: +e.target.value }); + }; + onGroupsChange = (selectedGroups) => { this.setJobDetails({ jobGroups: selectedGroups.map((g) => g.label) }); }; @@ -104,6 +117,7 @@ export class JobDetails extends Component { groups, mmlValidationError, groupsValidationError, + modelSnapshotRetentionDays, } = this.state; const { datafeedRunning } = this.props; return ( @@ -172,6 +186,30 @@ export class JobDetails extends Component { disabled={datafeedRunning} /> + + } + // helpText={ + // datafeedRunning ? ( + // + // ) : null + // } + // isInvalid={mmlValidationError !== ''} + // error={mmlValidationError} + > + + ); diff --git a/x-pack/plugins/ml/server/routes/schemas/anomaly_detectors_schema.ts b/x-pack/plugins/ml/server/routes/schemas/anomaly_detectors_schema.ts index de393e002c55b..3a01a616a4f7c 100644 --- a/x-pack/plugins/ml/server/routes/schemas/anomaly_detectors_schema.ts +++ b/x-pack/plugins/ml/server/routes/schemas/anomaly_detectors_schema.ts @@ -69,6 +69,7 @@ export const anomalyDetectionUpdateJobSchema = schema.object({ }) ), groups: schema.maybe(schema.arrayOf(schema.maybe(schema.string()))), + model_snapshot_retention_days: schema.maybe(schema.number()), }); export const analysisConfigSchema = schema.object({ From e6c5a931b1e7a392246be4a58abefa95866ef915 Mon Sep 17 00:00:00 2001 From: James Gowdy Date: Fri, 12 Jun 2020 13:37:40 +0100 Subject: [PATCH 2/5] removing commented code --- .../components/edit_job_flyout/tabs/job_details.js | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/x-pack/plugins/ml/public/application/jobs/jobs_list/components/edit_job_flyout/tabs/job_details.js b/x-pack/plugins/ml/public/application/jobs/jobs_list/components/edit_job_flyout/tabs/job_details.js index 77bbfbc100791..17a0e18dcea16 100644 --- a/x-pack/plugins/ml/public/application/jobs/jobs_list/components/edit_job_flyout/tabs/job_details.js +++ b/x-pack/plugins/ml/public/application/jobs/jobs_list/components/edit_job_flyout/tabs/job_details.js @@ -193,16 +193,6 @@ export class JobDetails extends Component { defaultMessage="Model snapshot retention days" /> } - // helpText={ - // datafeedRunning ? ( - // - // ) : null - // } - // isInvalid={mmlValidationError !== ''} - // error={mmlValidationError} > Date: Fri, 12 Jun 2020 14:52:53 +0100 Subject: [PATCH 3/5] flooring number input --- .../jobs_list/components/edit_job_flyout/tabs/job_details.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/ml/public/application/jobs/jobs_list/components/edit_job_flyout/tabs/job_details.js b/x-pack/plugins/ml/public/application/jobs/jobs_list/components/edit_job_flyout/tabs/job_details.js index 17a0e18dcea16..01243f980fa3c 100644 --- a/x-pack/plugins/ml/public/application/jobs/jobs_list/components/edit_job_flyout/tabs/job_details.js +++ b/x-pack/plugins/ml/public/application/jobs/jobs_list/components/edit_job_flyout/tabs/job_details.js @@ -73,7 +73,7 @@ export class JobDetails extends Component { }; onModelSnapshotRetentionDaysChange = (e) => { - this.setJobDetails({ jobModelSnapshotRetentionDays: +e.target.value }); + this.setJobDetails({ jobModelSnapshotRetentionDays: Math.floor(+e.target.value) }); }; onGroupsChange = (selectedGroups) => { From cc5f6f1539a8eabe6f2423ff864a686e5d1800a6 Mon Sep 17 00:00:00 2001 From: James Gowdy Date: Fri, 12 Jun 2020 15:52:28 +0100 Subject: [PATCH 4/5] adding daily_model_snapshot_retention_after_days --- .../edit_job_flyout/edit_job_flyout.js | 12 +++++++ .../components/edit_job_flyout/edit_utils.js | 9 +++++ .../edit_job_flyout/tabs/job_details.js | 34 ++++++++++++++++++- 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/ml/public/application/jobs/jobs_list/components/edit_job_flyout/edit_job_flyout.js b/x-pack/plugins/ml/public/application/jobs/jobs_list/components/edit_job_flyout/edit_job_flyout.js index 210af3b03e5f0..574a7efe7792a 100644 --- a/x-pack/plugins/ml/public/application/jobs/jobs_list/components/edit_job_flyout/edit_job_flyout.js +++ b/x-pack/plugins/ml/public/application/jobs/jobs_list/components/edit_job_flyout/edit_job_flyout.js @@ -49,6 +49,7 @@ export class EditJobFlyoutUI extends Component { jobGroups: [], jobModelMemoryLimit: '', jobModelSnapshotRetentionDays: 1, + jobDailyModelSnapshotRetentionAfterDays: 1, jobDetectors: [], jobDetectorDescriptions: [], jobCustomUrls: [], @@ -98,6 +99,7 @@ export class EditJobFlyoutUI extends Component { 'jobGroups', 'jobModelMemoryLimit', 'jobModelSnapshotRetentionDays', + 'jobDailyModelSnapshotRetentionAfterDays', 'jobCustomUrls', 'jobDetectors', 'jobDetectorDescriptions', @@ -133,6 +135,12 @@ export class EditJobFlyoutUI extends Component { const modelSnapshotRetentionDays = job.model_snapshot_retention_days !== undefined ? job.model_snapshot_retention_days : 1; + + const dailyModelSnapshotRetentionAfterDays = + job.daily_model_snapshot_retention_after_days !== undefined + ? job.daily_model_snapshot_retention_after_days + : modelSnapshotRetentionDays; + const detectors = job.analysis_config && job.analysis_config.detectors ? [...job.analysis_config.detectors] @@ -152,6 +160,7 @@ export class EditJobFlyoutUI extends Component { jobGroups: job.groups !== undefined ? job.groups : [], jobModelMemoryLimit: mml, jobModelSnapshotRetentionDays: modelSnapshotRetentionDays, + jobDailyModelSnapshotRetentionAfterDays: dailyModelSnapshotRetentionAfterDays, jobDetectors: detectors, jobDetectorDescriptions: detectors.map((d) => d.detector_description), jobBucketSpan: bucketSpan, @@ -236,6 +245,7 @@ export class EditJobFlyoutUI extends Component { groups: this.state.jobGroups, mml: this.state.jobModelMemoryLimit, modelSnapshotRetentionDays: this.state.jobModelSnapshotRetentionDays, + dailyModelSnapshotRetentionAfterDays: this.state.jobDailyModelSnapshotRetentionAfterDays, detectorDescriptions: this.state.jobDetectorDescriptions, datafeedQuery: collapseLiteralStrings(this.state.datafeedQuery), datafeedQueryDelay: this.state.datafeedQueryDelay, @@ -283,6 +293,7 @@ export class EditJobFlyoutUI extends Component { jobGroups, jobModelMemoryLimit, jobModelSnapshotRetentionDays, + jobDailyModelSnapshotRetentionAfterDays, jobDetectors, jobDetectorDescriptions, jobBucketSpan, @@ -311,6 +322,7 @@ export class EditJobFlyoutUI extends Component { jobGroups={jobGroups} jobModelMemoryLimit={jobModelMemoryLimit} jobModelSnapshotRetentionDays={jobModelSnapshotRetentionDays} + jobDailyModelSnapshotRetentionAfterDays={jobDailyModelSnapshotRetentionAfterDays} setJobDetails={this.setJobDetails} jobGroupsValidationError={jobGroupsValidationError} jobModelMemoryLimitValidationError={jobModelMemoryLimitValidationError} diff --git a/x-pack/plugins/ml/public/application/jobs/jobs_list/components/edit_job_flyout/edit_utils.js b/x-pack/plugins/ml/public/application/jobs/jobs_list/components/edit_job_flyout/edit_utils.js index 5d57e1b879766..5030c48a4e367 100644 --- a/x-pack/plugins/ml/public/application/jobs/jobs_list/components/edit_job_flyout/edit_utils.js +++ b/x-pack/plugins/ml/public/application/jobs/jobs_list/components/edit_job_flyout/edit_utils.js @@ -17,6 +17,7 @@ export function saveJob(job, newJobData, finish) { ...extractGroups(job, newJobData), ...extractMML(job, newJobData), ...extractModelSnapshotRetentionDays(job, newJobData), + ...extractDailyModelSnapshotRetentionAfterDays(job, newJobData), ...extractDetectorDescriptions(job, newJobData), ...extractCustomSettings(job, newJobData), }; @@ -184,6 +185,14 @@ function extractModelSnapshotRetentionDays(job, newJobData) { return {}; } +function extractDailyModelSnapshotRetentionAfterDays(job, newJobData) { + const dailyModelSnapshotRetentionAfterDays = newJobData.dailyModelSnapshotRetentionAfterDays; + if (dailyModelSnapshotRetentionAfterDays !== job.daily_model_snapshot_retention_after_days) { + return { daily_model_snapshot_retention_after_days: dailyModelSnapshotRetentionAfterDays }; + } + return {}; +} + function extractDetectorDescriptions(job, newJobData) { const detectors = []; const descriptions = newJobData.detectorDescriptions.map((d, i) => ({ diff --git a/x-pack/plugins/ml/public/application/jobs/jobs_list/components/edit_job_flyout/tabs/job_details.js b/x-pack/plugins/ml/public/application/jobs/jobs_list/components/edit_job_flyout/tabs/job_details.js index 01243f980fa3c..ec5ef6fce26b5 100644 --- a/x-pack/plugins/ml/public/application/jobs/jobs_list/components/edit_job_flyout/tabs/job_details.js +++ b/x-pack/plugins/ml/public/application/jobs/jobs_list/components/edit_job_flyout/tabs/job_details.js @@ -32,6 +32,7 @@ export class JobDetails extends Component { mmlValidationError: '', groupsValidationError: '', modelSnapshotRetentionDays: 1, + dailyModelSnapshotRetentionAfterDays: 1, }; this.setJobDetails = props.setJobDetails; @@ -61,6 +62,7 @@ export class JobDetails extends Component { mmlValidationError: props.jobModelMemoryLimitValidationError, groupsValidationError: props.jobGroupsValidationError, modelSnapshotRetentionDays: props.jobModelSnapshotRetentionDays, + dailyModelSnapshotRetentionAfterDays: props.jobDailyModelSnapshotRetentionAfterDays, }; } @@ -73,7 +75,21 @@ export class JobDetails extends Component { }; onModelSnapshotRetentionDaysChange = (e) => { - this.setJobDetails({ jobModelSnapshotRetentionDays: Math.floor(+e.target.value) }); + const jobModelSnapshotRetentionDays = Math.floor(+e.target.value); + + this.setJobDetails({ + jobModelSnapshotRetentionDays, + ...(this.state.dailyModelSnapshotRetentionAfterDays > jobModelSnapshotRetentionDays + ? { jobDailyModelSnapshotRetentionAfterDays: jobModelSnapshotRetentionDays } + : {}), + }); + }; + + onDailyModelSnapshotRetentionAfterDaysChange = (e) => { + const jobDailyModelSnapshotRetentionAfterDays = Math.floor(+e.target.value); + if (jobDailyModelSnapshotRetentionAfterDays <= this.state.modelSnapshotRetentionDays) { + this.setJobDetails({ jobDailyModelSnapshotRetentionAfterDays }); + } }; onGroupsChange = (selectedGroups) => { @@ -118,6 +134,7 @@ export class JobDetails extends Component { mmlValidationError, groupsValidationError, modelSnapshotRetentionDays, + dailyModelSnapshotRetentionAfterDays, } = this.state; const { datafeedRunning } = this.props; return ( @@ -200,6 +217,21 @@ export class JobDetails extends Component { onChange={this.onModelSnapshotRetentionDaysChange} /> + + } + > + + ); From b2e0bcb76cd21cf77c8fe51e71b058b689c456a1 Mon Sep 17 00:00:00 2001 From: James Gowdy Date: Fri, 12 Jun 2020 16:10:23 +0100 Subject: [PATCH 5/5] updating default values --- .../jobs_list/components/edit_job_flyout/edit_job_flyout.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/ml/public/application/jobs/jobs_list/components/edit_job_flyout/edit_job_flyout.js b/x-pack/plugins/ml/public/application/jobs/jobs_list/components/edit_job_flyout/edit_job_flyout.js index 574a7efe7792a..3508d69ee2212 100644 --- a/x-pack/plugins/ml/public/application/jobs/jobs_list/components/edit_job_flyout/edit_job_flyout.js +++ b/x-pack/plugins/ml/public/application/jobs/jobs_list/components/edit_job_flyout/edit_job_flyout.js @@ -48,8 +48,8 @@ export class EditJobFlyoutUI extends Component { jobDescription: '', jobGroups: [], jobModelMemoryLimit: '', - jobModelSnapshotRetentionDays: 1, - jobDailyModelSnapshotRetentionAfterDays: 1, + jobModelSnapshotRetentionDays: 10, + jobDailyModelSnapshotRetentionAfterDays: 10, jobDetectors: [], jobDetectorDescriptions: [], jobCustomUrls: [], @@ -134,7 +134,7 @@ export class EditJobFlyoutUI extends Component { : ''; const modelSnapshotRetentionDays = - job.model_snapshot_retention_days !== undefined ? job.model_snapshot_retention_days : 1; + job.model_snapshot_retention_days !== undefined ? job.model_snapshot_retention_days : 10; const dailyModelSnapshotRetentionAfterDays = job.daily_model_snapshot_retention_after_days !== undefined