Skip to content

Commit 44f5a8c

Browse files
authored
Use snapshot's latest result time rather than snapshot's creation time when creating an annotation (elastic#56093) (elastic#56103)
1 parent e197b6c commit 44f5a8c

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/process/autodetect/state/ModelSnapshot.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ private static ObjectParser<Builder, Void> createParser(boolean ignoreUnknownFie
8989
*/
9090
private final Version minVersion;
9191

92+
/**
93+
* This is model snapshot's creation wall clock time.
94+
* Use {@code latestResultTimeStamp} if you need model time instead.
95+
*/
9296
private final Date timestamp;
9397
private final String description;
9498
private final String snapshotId;

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/output/AutodetectResultProcessor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,8 @@ private Annotation createModelSnapshotAnnotation(ModelSnapshot modelSnapshot) {
332332
Messages.getMessage(Messages.JOB_AUDIT_SNAPSHOT_STORED, modelSnapshot.getSnapshotId()),
333333
currentTime,
334334
XPackUser.NAME,
335-
modelSnapshot.getTimestamp(),
336-
modelSnapshot.getTimestamp(),
335+
modelSnapshot.getLatestResultTimeStamp(),
336+
modelSnapshot.getLatestResultTimeStamp(),
337337
jobId,
338338
currentTime,
339339
XPackUser.NAME,

x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/AutodetectResultProcessorIT.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,8 @@ private static ModelSizeStats createModelSizeStats() {
482482
private static ModelSnapshot createModelSnapshot() {
483483
return new ModelSnapshot.Builder(JOB_ID)
484484
.setSnapshotId(randomAlphaOfLength(12))
485-
.setTimestamp(Date.from(Instant.ofEpochMilli(1000000000)))
485+
.setLatestResultTimeStamp(Date.from(Instant.ofEpochMilli(1000_000_000)))
486+
.setTimestamp(Date.from(Instant.ofEpochMilli(2000_000_000)))
486487
.build();
487488
}
488489

x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/process/autodetect/output/AutodetectResultProcessorTests.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,8 @@ public void testProcessResult_modelSnapshot() {
365365
AutodetectResult result = mock(AutodetectResult.class);
366366
ModelSnapshot modelSnapshot = new ModelSnapshot.Builder(JOB_ID)
367367
.setSnapshotId("a_snapshot_id")
368-
.setTimestamp(Date.from(Instant.ofEpochMilli(1000000000)))
368+
.setLatestResultTimeStamp(Date.from(Instant.ofEpochMilli(1000_000_000)))
369+
.setTimestamp(Date.from(Instant.ofEpochMilli(2000_000_000)))
369370
.setMinVersion(Version.CURRENT)
370371
.build();
371372
when(result.getModelSnapshot()).thenReturn(modelSnapshot);
@@ -389,8 +390,8 @@ public void testProcessResult_modelSnapshot() {
389390
"Job model snapshot with id [a_snapshot_id] stored",
390391
Date.from(CURRENT_TIME),
391392
XPackUser.NAME,
392-
modelSnapshot.getTimestamp(),
393-
modelSnapshot.getTimestamp(),
393+
Date.from(Instant.ofEpochMilli(1000_000_000)),
394+
Date.from(Instant.ofEpochMilli(1000_000_000)),
394395
JOB_ID,
395396
Date.from(CURRENT_TIME),
396397
XPackUser.NAME,

0 commit comments

Comments
 (0)