From a0e5ae06ddd97d14a0c7dd1830b250c7b7fa6b77 Mon Sep 17 00:00:00 2001 From: Przemyslaw Witek Date: Mon, 4 May 2020 08:49:15 +0200 Subject: [PATCH 1/2] Use snapshot's latest result time rather than snapshot's creation time when creating an annotation --- .../autodetect/output/AutodetectResultProcessor.java | 4 ++-- .../autodetect/output/AutodetectResultProcessorTests.java | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/output/AutodetectResultProcessor.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/output/AutodetectResultProcessor.java index 49a687b264bd2..fe2b94d294665 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/output/AutodetectResultProcessor.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/output/AutodetectResultProcessor.java @@ -332,8 +332,8 @@ private Annotation createModelSnapshotAnnotation(ModelSnapshot modelSnapshot) { Messages.getMessage(Messages.JOB_AUDIT_SNAPSHOT_STORED, modelSnapshot.getSnapshotId()), currentTime, XPackUser.NAME, - modelSnapshot.getTimestamp(), - modelSnapshot.getTimestamp(), + modelSnapshot.getLatestResultTimeStamp(), + modelSnapshot.getLatestResultTimeStamp(), jobId, currentTime, XPackUser.NAME, diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/process/autodetect/output/AutodetectResultProcessorTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/process/autodetect/output/AutodetectResultProcessorTests.java index 116a9b773a07a..3d2ff15f261d6 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/process/autodetect/output/AutodetectResultProcessorTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/process/autodetect/output/AutodetectResultProcessorTests.java @@ -365,7 +365,8 @@ public void testProcessResult_modelSnapshot() { AutodetectResult result = mock(AutodetectResult.class); ModelSnapshot modelSnapshot = new ModelSnapshot.Builder(JOB_ID) .setSnapshotId("a_snapshot_id") - .setTimestamp(Date.from(Instant.ofEpochMilli(1000000000))) + .setTimestamp(Date.from(Instant.ofEpochMilli(2000000000))) + .setLatestResultTimeStamp(Date.from(Instant.ofEpochMilli(1200000000))) .setMinVersion(Version.CURRENT) .build(); when(result.getModelSnapshot()).thenReturn(modelSnapshot); @@ -389,8 +390,8 @@ public void testProcessResult_modelSnapshot() { "Job model snapshot with id [a_snapshot_id] stored", Date.from(CURRENT_TIME), XPackUser.NAME, - modelSnapshot.getTimestamp(), - modelSnapshot.getTimestamp(), + Date.from(Instant.ofEpochMilli(1200000000)), + Date.from(Instant.ofEpochMilli(1200000000)), JOB_ID, Date.from(CURRENT_TIME), XPackUser.NAME, From 1ab2ae090d7a9046e535716c36add0c44ace7f21 Mon Sep 17 00:00:00 2001 From: Przemyslaw Witek Date: Mon, 4 May 2020 09:30:20 +0200 Subject: [PATCH 2/2] Fix integration tests. Add field comment. --- .../ml/job/process/autodetect/state/ModelSnapshot.java | 4 ++++ .../xpack/ml/integration/AutodetectResultProcessorIT.java | 3 ++- .../autodetect/output/AutodetectResultProcessorTests.java | 8 ++++---- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/process/autodetect/state/ModelSnapshot.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/process/autodetect/state/ModelSnapshot.java index 035579b2243b0..c028bd220df0a 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/process/autodetect/state/ModelSnapshot.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/process/autodetect/state/ModelSnapshot.java @@ -89,6 +89,10 @@ private static ObjectParser createParser(boolean ignoreUnknownFie */ private final Version minVersion; + /** + * This is model snapshot's creation wall clock time. + * Use {@code latestResultTimeStamp} if you need model time instead. + */ private final Date timestamp; private final String description; private final String snapshotId; diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/AutodetectResultProcessorIT.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/AutodetectResultProcessorIT.java index dc68c69251272..d493ecbf4539f 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/AutodetectResultProcessorIT.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/AutodetectResultProcessorIT.java @@ -480,7 +480,8 @@ private static ModelSizeStats createModelSizeStats() { private static ModelSnapshot createModelSnapshot() { return new ModelSnapshot.Builder(JOB_ID) .setSnapshotId(randomAlphaOfLength(12)) - .setTimestamp(Date.from(Instant.ofEpochMilli(1000000000))) + .setLatestResultTimeStamp(Date.from(Instant.ofEpochMilli(1000_000_000))) + .setTimestamp(Date.from(Instant.ofEpochMilli(2000_000_000))) .build(); } diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/process/autodetect/output/AutodetectResultProcessorTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/process/autodetect/output/AutodetectResultProcessorTests.java index 3d2ff15f261d6..689debf005b65 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/process/autodetect/output/AutodetectResultProcessorTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/process/autodetect/output/AutodetectResultProcessorTests.java @@ -365,8 +365,8 @@ public void testProcessResult_modelSnapshot() { AutodetectResult result = mock(AutodetectResult.class); ModelSnapshot modelSnapshot = new ModelSnapshot.Builder(JOB_ID) .setSnapshotId("a_snapshot_id") - .setTimestamp(Date.from(Instant.ofEpochMilli(2000000000))) - .setLatestResultTimeStamp(Date.from(Instant.ofEpochMilli(1200000000))) + .setLatestResultTimeStamp(Date.from(Instant.ofEpochMilli(1000_000_000))) + .setTimestamp(Date.from(Instant.ofEpochMilli(2000_000_000))) .setMinVersion(Version.CURRENT) .build(); when(result.getModelSnapshot()).thenReturn(modelSnapshot); @@ -390,8 +390,8 @@ public void testProcessResult_modelSnapshot() { "Job model snapshot with id [a_snapshot_id] stored", Date.from(CURRENT_TIME), XPackUser.NAME, - Date.from(Instant.ofEpochMilli(1200000000)), - Date.from(Instant.ofEpochMilli(1200000000)), + Date.from(Instant.ofEpochMilli(1000_000_000)), + Date.from(Instant.ofEpochMilli(1000_000_000)), JOB_ID, Date.from(CURRENT_TIME), XPackUser.NAME,