Skip to content

Commit f1fc888

Browse files
Add DailyModelSnapshotRetentionAfterDays to ml jobs (#4812) (#4831)
Relates: elastic/elasticsearch#56125, #4803 This commit adds the DailyModelSnapshotRetentionAfterDays to ML jobs. It also updates the XML comment for ModelSnapshotRetentionDays to align with the new default in Elasticsearch 7.8. Co-authored-by: Russ Cam <russ.cam@elastic.co>
1 parent 6533731 commit f1fc888

File tree

5 files changed

+94
-22
lines changed

5 files changed

+94
-22
lines changed

src/Nest/XPack/MachineLearning/Job/Config/Job.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,27 @@ public class Job
9090

9191
/// <summary>
9292
/// The time in days that model snapshots are retained for the job.
93-
/// Older snapshots are deleted. The default value is 1 day.
93+
/// Older snapshots are deleted. The default value is 10 days in Elasticsearch 7.8.0+
94+
/// and 1 day in older versions.
9495
/// </summary>
9596
[DataMember(Name = "model_snapshot_retention_days")]
9697
public long? ModelSnapshotRetentionDays { get; set; }
9798

99+
/// <summary>
100+
/// Specifies a number of days between 0 and the value of <see cref="ModelSnapshotRetentionDays"/>.
101+
/// After this period of time, only the first model snapshot per day is retained for this job.
102+
/// Age is calculated relative to the timestamp of the newest model snapshot. For new jobs, the default
103+
/// value is <c>1</c>, which means that all snapshots are retained for one day. Older snapshots
104+
/// are thinned out such that only one per day is retained. For jobs that were
105+
/// created before this setting was available, the default value matches the
106+
/// <see cref="ModelSnapshotRetentionDays"/> value, which preserves the original behavior
107+
/// and no thinning out of model snapshots occurs.
108+
/// <para />
109+
/// Available in Elasticsearch 7.8.0+
110+
/// </summary>
111+
[DataMember(Name = "daily_model_snapshot_retention_after_days")]
112+
public long? DailyModelSnapshotRetentionAfterDays { get; set; }
113+
98114
/// <summary>
99115
/// Advanced configuration option. The period over which adjustments to the score are applied, as new data
100116
/// is seen. The default value is the longer of 30 days or 100 bucket spans.

src/Nest/XPack/MachineLearning/MachineLearningInfo/MachineLearningInfoResponse.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ public class AnomalyDetectors
3939
[DataMember(Name = "model_snapshot_retention_days")]
4040
public int ModelSnapshotRetentionDays { get; internal set; }
4141

42+
/// <summary>
43+
/// Available in Elasticsearch 7.8.0+
44+
/// </summary>
45+
[DataMember(Name = "daily_model_snapshot_retention_after_days")]
46+
public long DailyModelSnapshotRetentionAfterDays { get; internal set; }
47+
4248
[DataMember(Name = "categorization_analyzer")]
4349
public CategorizationAnalyzer CategorizationAnalyzer { get; internal set; }
4450
}

src/Nest/XPack/MachineLearning/PutJob/PutJobRequest.cs

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,27 @@ public partial interface IPutJobRequest
4848

4949
/// <summary>
5050
/// The time in days that model snapshots are retained for the job.
51-
/// Older snapshots are deleted. The default value is 1 day.
51+
/// Older snapshots are deleted. The default value is 10 days in Elasticsearch 7.8.0+
52+
/// and 1 day in older versions.
5253
/// </summary>
5354
[DataMember(Name ="model_snapshot_retention_days")]
5455
long? ModelSnapshotRetentionDays { get; set; }
5556

57+
/// <summary>
58+
/// Specifies a number of days between 0 and the value of <see cref="ModelSnapshotRetentionDays"/>.
59+
/// After this period of time, only the first model snapshot per day is retained for this job.
60+
/// Age is calculated relative to the timestamp of the newest model snapshot. For new jobs, the default
61+
/// value is <c>1</c>, which means that all snapshots are retained for one day. Older snapshots
62+
/// are thinned out such that only one per day is retained. For jobs that were
63+
/// created before this setting was available, the default value matches the
64+
/// <see cref="ModelSnapshotRetentionDays"/> value, which preserves the original behavior
65+
/// and no thinning out of model snapshots occurs.
66+
/// <para />
67+
/// Available in Elasticsearch 7.8.0+
68+
/// </summary>
69+
[DataMember(Name ="daily_model_snapshot_retention_after_days")]
70+
long? DailyModelSnapshotRetentionAfterDays { get; set; }
71+
5672
/// <summary>
5773
/// The name of the index in which to store the machine learning results.
5874
/// The default value is shared, which corresponds to the index name .ml-anomalies-shared.
@@ -93,6 +109,9 @@ public partial class PutJobRequest
93109
/// <inheritdoc />
94110
public long? ModelSnapshotRetentionDays { get; set; }
95111

112+
/// <inheritdoc />
113+
public long? DailyModelSnapshotRetentionAfterDays { get; set; }
114+
96115
/// <inheritdoc />
97116
public IndexName ResultsIndexName { get; set; }
98117

@@ -109,41 +128,46 @@ public partial class PutJobDescriptor<TDocument> where TDocument : class
109128
string IPutJobRequest.Description { get; set; }
110129
IModelPlotConfig IPutJobRequest.ModelPlotConfig { get; set; }
111130
long? IPutJobRequest.ModelSnapshotRetentionDays { get; set; }
131+
long? IPutJobRequest.DailyModelSnapshotRetentionAfterDays { get; set; }
112132
IndexName IPutJobRequest.ResultsIndexName { get; set; }
113133
bool? IPutJobRequest.AllowLazyOpen { get; set; }
114134

115-
/// <inheritdoc />
135+
/// <inheritdoc cref="IPutJobRequest.AnalysisConfig"/>
116136
public PutJobDescriptor<TDocument> AnalysisConfig(Func<AnalysisConfigDescriptor<TDocument>, IAnalysisConfig> selector) =>
117137
Assign(selector, (a, v) => a.AnalysisConfig = v?.Invoke(new AnalysisConfigDescriptor<TDocument>()));
118138

119-
/// <inheritdoc />
139+
/// <inheritdoc cref="IPutJobRequest.AnalysisLimits"/>
120140
public PutJobDescriptor<TDocument> AnalysisLimits(Func<AnalysisLimitsDescriptor, IAnalysisLimits> selector) =>
121141
Assign(selector, (a, v) => a.AnalysisLimits = v?.Invoke(new AnalysisLimitsDescriptor()));
122142

123-
/// <inheritdoc />
143+
/// <inheritdoc cref="IPutJobRequest.DataDescription"/>
124144
public PutJobDescriptor<TDocument> DataDescription(Func<DataDescriptionDescriptor<TDocument>, IDataDescription> selector) =>
125145
Assign(selector.InvokeOrDefault(new DataDescriptionDescriptor<TDocument>()), (a, v) => a.DataDescription = v);
126146

127-
/// <inheritdoc />
147+
/// <inheritdoc cref="IPutJobRequest.Description"/>
128148
public PutJobDescriptor<TDocument> Description(string description) => Assign(description, (a, v) => a.Description = v);
129149

130-
/// <inheritdoc />
150+
/// <inheritdoc cref="IPutJobRequest.ModelPlotConfig"/>
131151
public PutJobDescriptor<TDocument> ModelPlot(Func<ModelPlotConfigDescriptor<TDocument>, IModelPlotConfig> selector) =>
132152
Assign(selector, (a, v) => a.ModelPlotConfig = v?.Invoke(new ModelPlotConfigDescriptor<TDocument>()));
133153

134-
/// <inheritdoc />
154+
/// <inheritdoc cref="IPutJobRequest.ModelSnapshotRetentionDays"/>
135155
public PutJobDescriptor<TDocument> ModelSnapshotRetentionDays(long? modelSnapshotRetentionDays) =>
136156
Assign(modelSnapshotRetentionDays, (a, v) => a.ModelSnapshotRetentionDays = v);
137157

138-
/// <inheritdoc />
158+
/// <inheritdoc cref="IPutJobRequest.DailyModelSnapshotRetentionAfterDays"/>
159+
public PutJobDescriptor<TDocument> DailyModelSnapshotRetentionAfterDays(long? dailyModelSnapshotRetentionAfterDays) =>
160+
Assign(dailyModelSnapshotRetentionAfterDays, (a, v) => a.DailyModelSnapshotRetentionAfterDays = v);
161+
162+
/// <inheritdoc cref="IPutJobRequest.ResultsIndexName"/>
139163
public PutJobDescriptor<TDocument> ResultsIndexName(IndexName indexName) =>
140164
Assign(indexName, (a, v) => a.ResultsIndexName = v);
141165

142-
/// <inheritdoc />
166+
/// <inheritdoc cref="IPutJobRequest.ResultsIndexName"/>
143167
public PutJobDescriptor<TDocument> ResultsIndexName<TIndex>() =>
144168
Assign(typeof(TIndex), (a, v) => a.ResultsIndexName = v);
145169

146-
/// <inheritdoc />
170+
/// <inheritdoc cref="IPutJobRequest.AllowLazyOpen"/>
147171
public PutJobDescriptor<TDocument> AllowLazyOpen(bool? allowLazyOpen = true) =>
148172
Assign(allowLazyOpen, (a, v) => a.AllowLazyOpen = v);
149173
}

src/Nest/XPack/MachineLearning/UpdateJob/UpdateJobRequest.cs

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,27 @@ public partial interface IUpdateJobRequest
5252

5353
/// <summary>
5454
/// The time in days that model snapshots are retained for the job.
55-
/// Older snapshots are deleted. The default value is 1 day.
55+
/// Older snapshots are deleted. The default value is 10 days in Elasticsearch 7.8.0+
56+
/// and 1 day in older versions.
5657
/// </summary>
5758
[DataMember(Name ="model_snapshot_retention_days")]
5859
long? ModelSnapshotRetentionDays { get; set; }
5960

61+
/// <summary>
62+
/// Specifies a number of days between 0 and the value of <see cref="ModelSnapshotRetentionDays"/>.
63+
/// After this period of time, only the first model snapshot per day is retained for this job.
64+
/// Age is calculated relative to the timestamp of the newest model snapshot. For new jobs, the default
65+
/// value is <c>1</c>, which means that all snapshots are retained for one day. Older snapshots
66+
/// are thinned out such that only one per day is retained. For jobs that were
67+
/// created before this setting was available, the default value matches the
68+
/// <see cref="ModelSnapshotRetentionDays"/> value, which preserves the original behavior
69+
/// and no thinning out of model snapshots occurs.
70+
/// <para />
71+
/// Available in Elasticsearch 7.8.0+
72+
/// </summary>
73+
[DataMember(Name ="daily_model_snapshot_retention_after_days")]
74+
long? DailyModelSnapshotRetentionAfterDays { get; set; }
75+
6076
/// <summary>
6177
/// The period over which adjustments to the score are applied, as new data is seen.
6278
/// </summary>
@@ -104,6 +120,9 @@ public partial class UpdateJobRequest
104120
/// <inheritdoc />
105121
public long? ModelSnapshotRetentionDays { get; set; }
106122

123+
/// <inheritdoc />
124+
public long? DailyModelSnapshotRetentionAfterDays { get; set; }
125+
107126
/// <inheritdoc />
108127
public long? RenormalizationWindowDays { get; set; }
109128

@@ -123,43 +142,47 @@ public partial class UpdateJobDescriptor<TDocument> where TDocument : class
123142
string IUpdateJobRequest.Description { get; set; }
124143
IModelPlotConfigEnabled IUpdateJobRequest.ModelPlotConfig { get; set; }
125144
long? IUpdateJobRequest.ModelSnapshotRetentionDays { get; set; }
145+
long? IUpdateJobRequest.DailyModelSnapshotRetentionAfterDays { get; set; }
126146
long? IUpdateJobRequest.RenormalizationWindowDays { get; set; }
127147
long? IUpdateJobRequest.ResultsRetentionDays { get; set; }
128-
129148
bool? IUpdateJobRequest.AllowLazyOpen { get; set; }
130149

131-
/// <inheritdoc />
150+
/// <inheritdoc cref="IUpdateJobRequest.AnalysisLimits" />
132151
public UpdateJobDescriptor<TDocument> AnalysisLimits(Func<AnalysisMemoryLimitDescriptor, IAnalysisMemoryLimit> selector) =>
133152
Assign(selector, (a, v) => a.AnalysisLimits = v?.Invoke(new AnalysisMemoryLimitDescriptor()));
134153

135-
/// <inheritdoc />
154+
/// <inheritdoc cref="IUpdateJobRequest.BackgroundPersistInterval" />
136155
public UpdateJobDescriptor<TDocument> BackgroundPersistInterval(Time backgroundPersistInterval) =>
137156
Assign(backgroundPersistInterval, (a, v) => a.BackgroundPersistInterval = v);
138157

139-
/// <inheritdoc />
158+
/// <inheritdoc cref="IUpdateJobRequest.CustomSettings" />
140159
public UpdateJobDescriptor<TDocument> CustomSettings(Func<FluentDictionary<string, object>, FluentDictionary<string, object>> customSettingsDictionary
141160
) =>
142161
Assign(customSettingsDictionary(new FluentDictionary<string, object>()), (a, v) => a.CustomSettings = v);
143162

144-
/// <inheritdoc />
163+
/// <inheritdoc cref="IUpdateJobRequest.Description" />
145164
public UpdateJobDescriptor<TDocument> Description(string description) => Assign(description, (a, v) => a.Description = v);
146165

147-
/// <inheritdoc />
166+
/// <inheritdoc cref="IUpdateJobRequest.ModelPlotConfig" />
148167
public UpdateJobDescriptor<TDocument> ModelPlot(Func<ModelPlotConfigEnabledDescriptor<TDocument>, IModelPlotConfigEnabled> selector) =>
149168
Assign(selector, (a, v) => a.ModelPlotConfig = v?.Invoke(new ModelPlotConfigEnabledDescriptor<TDocument>()));
150169

151-
/// <inheritdoc />
170+
/// <inheritdoc cref="IUpdateJobRequest.ModelSnapshotRetentionDays" />
152171
public UpdateJobDescriptor<TDocument> ModelSnapshotRetentionDays(long? modelSnapshotRetentionDays) =>
153172
Assign(modelSnapshotRetentionDays, (a, v) => a.ModelSnapshotRetentionDays = v);
154173

155-
/// <inheritdoc />
174+
/// <inheritdoc cref="IUpdateJobRequest.DailyModelSnapshotRetentionAfterDays" />
175+
public UpdateJobDescriptor<TDocument> DailyModelSnapshotRetentionAfterDays(long? dailyModelSnapshotRetentionAfterDays) =>
176+
Assign(dailyModelSnapshotRetentionAfterDays, (a, v) => a.DailyModelSnapshotRetentionAfterDays = v);
177+
178+
/// <inheritdoc cref="IUpdateJobRequest.RenormalizationWindowDays" />
156179
public UpdateJobDescriptor<TDocument> RenormalizationWindowDays(long? renormalizationWindowDays) =>
157180
Assign(renormalizationWindowDays, (a, v) => a.RenormalizationWindowDays = v);
158181

159-
/// <inheritdoc />
182+
/// <inheritdoc cref="IUpdateJobRequest.ResultsRetentionDays" />
160183
public UpdateJobDescriptor<TDocument> ResultsRetentionDays(long? resultsRetentionDays) => Assign(resultsRetentionDays, (a, v) => a.ResultsRetentionDays = v);
161184

162-
/// <inheritdoc />
185+
/// <inheritdoc cref="IUpdateJobRequest.AllowLazyOpen" />
163186
public UpdateJobDescriptor<TDocument> AllowLazyOpen(bool? allowLazyOpen = true) =>
164187
Assign(allowLazyOpen, (a, v) => a.AllowLazyOpen = v);
165188
}

tests/Tests/XPack/MachineLearning/MachineLearningInfo/MachineLearningInfoApiTests.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ protected override void ExpectResponse(MachineLearningInfoResponse response)
4747
? 10
4848
: 1);
4949

50+
if (TestClient.Configuration.InRange(">=7.8.0"))
51+
anomalyDetectors.DailyModelSnapshotRetentionAfterDays.Should().Be(1);
52+
5053
response.Defaults.Datafeeds.ScrollSize.Should().Be(1000);
5154

5255
if (Cluster.ClusterConfiguration.Version >= "7.6.0")

0 commit comments

Comments
 (0)