Skip to content

Commit

Permalink
[ML] Allow editing of model_snapshot_retention_days (#69003) (#69206)
Browse files Browse the repository at this point in the history
* [ML] Allow editing of model_snapshot_retention_days

* removing commented code

* flooring number input

* adding daily_model_snapshot_retention_after_days

* updating default values

Co-authored-by: Elastic Machine <[email protected]>

Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
jgowdyelastic and elasticmachine authored Jun 16, 2020
1 parent da33681 commit 9ee5938
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ export class EditJobFlyoutUI extends Component {
jobDescription: '',
jobGroups: [],
jobModelMemoryLimit: '',
jobModelSnapshotRetentionDays: 10,
jobDailyModelSnapshotRetentionAfterDays: 10,
jobDetectors: [],
jobDetectorDescriptions: [],
jobCustomUrls: [],
Expand Down Expand Up @@ -96,6 +98,8 @@ export class EditJobFlyoutUI extends Component {
'jobDescription',
'jobGroups',
'jobModelMemoryLimit',
'jobModelSnapshotRetentionDays',
'jobDailyModelSnapshotRetentionAfterDays',
'jobCustomUrls',
'jobDetectors',
'jobDetectorDescriptions',
Expand Down Expand Up @@ -128,6 +132,15 @@ 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 : 10;

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]
Expand All @@ -146,6 +159,8 @@ export class EditJobFlyoutUI extends Component {
jobDescription: job.description,
jobGroups: job.groups !== undefined ? job.groups : [],
jobModelMemoryLimit: mml,
jobModelSnapshotRetentionDays: modelSnapshotRetentionDays,
jobDailyModelSnapshotRetentionAfterDays: dailyModelSnapshotRetentionAfterDays,
jobDetectors: detectors,
jobDetectorDescriptions: detectors.map((d) => d.detector_description),
jobBucketSpan: bucketSpan,
Expand Down Expand Up @@ -229,6 +244,8 @@ export class EditJobFlyoutUI extends Component {
description: this.state.jobDescription,
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,
Expand Down Expand Up @@ -275,6 +292,8 @@ export class EditJobFlyoutUI extends Component {
jobDescription,
jobGroups,
jobModelMemoryLimit,
jobModelSnapshotRetentionDays,
jobDailyModelSnapshotRetentionAfterDays,
jobDetectors,
jobDetectorDescriptions,
jobBucketSpan,
Expand Down Expand Up @@ -302,6 +321,8 @@ export class EditJobFlyoutUI extends Component {
jobDescription={jobDescription}
jobGroups={jobGroups}
jobModelMemoryLimit={jobModelMemoryLimit}
jobModelSnapshotRetentionDays={jobModelSnapshotRetentionDays}
jobDailyModelSnapshotRetentionAfterDays={jobDailyModelSnapshotRetentionAfterDays}
setJobDetails={this.setJobDetails}
jobGroupsValidationError={jobGroupsValidationError}
jobModelMemoryLimitValidationError={jobModelMemoryLimitValidationError}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export function saveJob(job, newJobData, finish) {
...extractDescription(job, newJobData),
...extractGroups(job, newJobData),
...extractMML(job, newJobData),
...extractModelSnapshotRetentionDays(job, newJobData),
...extractDailyModelSnapshotRetentionAfterDays(job, newJobData),
...extractDetectorDescriptions(job, newJobData),
...extractCustomSettings(job, newJobData),
};
Expand Down Expand Up @@ -175,6 +177,22 @@ 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 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) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -24,6 +31,8 @@ export class JobDetails extends Component {
mml: '',
mmlValidationError: '',
groupsValidationError: '',
modelSnapshotRetentionDays: 1,
dailyModelSnapshotRetentionAfterDays: 1,
};

this.setJobDetails = props.setJobDetails;
Expand Down Expand Up @@ -52,6 +61,8 @@ export class JobDetails extends Component {
mml: props.jobModelMemoryLimit,
mmlValidationError: props.jobModelMemoryLimitValidationError,
groupsValidationError: props.jobGroupsValidationError,
modelSnapshotRetentionDays: props.jobModelSnapshotRetentionDays,
dailyModelSnapshotRetentionAfterDays: props.jobDailyModelSnapshotRetentionAfterDays,
};
}

Expand All @@ -63,6 +74,24 @@ export class JobDetails extends Component {
this.setJobDetails({ jobModelMemoryLimit: e.target.value });
};

onModelSnapshotRetentionDaysChange = (e) => {
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) => {
this.setJobDetails({ jobGroups: selectedGroups.map((g) => g.label) });
};
Expand Down Expand Up @@ -104,6 +133,8 @@ export class JobDetails extends Component {
groups,
mmlValidationError,
groupsValidationError,
modelSnapshotRetentionDays,
dailyModelSnapshotRetentionAfterDays,
} = this.state;
const { datafeedRunning } = this.props;
return (
Expand Down Expand Up @@ -172,6 +203,35 @@ export class JobDetails extends Component {
disabled={datafeedRunning}
/>
</EuiFormRow>
<EuiFormRow
label={
<FormattedMessage
id="xpack.ml.jobsList.editJobFlyout.jobDetails.modelSnapshotRetentionDaysLabel"
defaultMessage="Model snapshot retention days"
/>
}
>
<EuiFieldNumber
min={0}
value={modelSnapshotRetentionDays}
onChange={this.onModelSnapshotRetentionDaysChange}
/>
</EuiFormRow>
<EuiFormRow
label={
<FormattedMessage
id="xpack.ml.jobsList.editJobFlyout.jobDetails.dailyModelSnapshotRetentionAfterDaysLabel"
defaultMessage="Daily model snapshot retention after days"
/>
}
>
<EuiFieldNumber
min={0}
max={modelSnapshotRetentionDays}
value={dailyModelSnapshotRetentionAfterDays}
onChange={this.onDailyModelSnapshotRetentionAfterDaysChange}
/>
</EuiFormRow>
</EuiForm>
</React.Fragment>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit 9ee5938

Please sign in to comment.