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] Allow editing of model_snapshot_retention_days #69003

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
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
Copy link
Contributor

Choose a reason for hiding this comment

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

I found that you can still save values with fractional numbers of days, but the back-end then floors the input, so I think the behaviour is ok. This happens even if you add a step={1} on the EuiFieldNumber. The input does indicate invalid input although the Save button remains enabled:

image

Copy link
Member Author

Choose a reason for hiding this comment

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

I've wrapped the onChange input in a Math.floor so when the user inputs a float, it immediately changes to an int.

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