Skip to content

Commit

Permalink
adding daily_model_snapshot_retention_after_days
Browse files Browse the repository at this point in the history
  • Loading branch information
jgowdyelastic committed Jun 12, 2020
1 parent ab19e54 commit cc5f6f1
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export class EditJobFlyoutUI extends Component {
jobGroups: [],
jobModelMemoryLimit: '',
jobModelSnapshotRetentionDays: 1,
jobDailyModelSnapshotRetentionAfterDays: 1,
jobDetectors: [],
jobDetectorDescriptions: [],
jobCustomUrls: [],
Expand Down Expand Up @@ -98,6 +99,7 @@ export class EditJobFlyoutUI extends Component {
'jobGroups',
'jobModelMemoryLimit',
'jobModelSnapshotRetentionDays',
'jobDailyModelSnapshotRetentionAfterDays',
'jobCustomUrls',
'jobDetectors',
'jobDetectorDescriptions',
Expand Down Expand Up @@ -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]
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -283,6 +293,7 @@ export class EditJobFlyoutUI extends Component {
jobGroups,
jobModelMemoryLimit,
jobModelSnapshotRetentionDays,
jobDailyModelSnapshotRetentionAfterDays,
jobDetectors,
jobDetectorDescriptions,
jobBucketSpan,
Expand Down Expand Up @@ -311,6 +322,7 @@ export class EditJobFlyoutUI extends Component {
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 @@ -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),
};
Expand Down Expand Up @@ -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) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class JobDetails extends Component {
mmlValidationError: '',
groupsValidationError: '',
modelSnapshotRetentionDays: 1,
dailyModelSnapshotRetentionAfterDays: 1,
};

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

Expand All @@ -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) => {
Expand Down Expand Up @@ -118,6 +134,7 @@ export class JobDetails extends Component {
mmlValidationError,
groupsValidationError,
modelSnapshotRetentionDays,
dailyModelSnapshotRetentionAfterDays,
} = this.state;
const { datafeedRunning } = this.props;
return (
Expand Down Expand Up @@ -200,6 +217,21 @@ export class JobDetails extends Component {
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

0 comments on commit cc5f6f1

Please sign in to comment.