diff --git a/plugin/src/main/java/org/elasticsearch/xpack/ml/job/process/DataStreamDiagnostics.java b/plugin/src/main/java/org/elasticsearch/xpack/ml/job/process/DataStreamDiagnostics.java index 2ff9be9af77..524b111ef23 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/ml/job/process/DataStreamDiagnostics.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/ml/job/process/DataStreamDiagnostics.java @@ -81,7 +81,9 @@ public class DataStreamDiagnostics { */ public void flush() { // flush all we know - flush(movingBucketHistogram.lastKey() + 1); + if (movingBucketHistogram.isEmpty() == false) { + flush(movingBucketHistogram.lastKey() + 1); + } } /** diff --git a/plugin/src/test/java/org/elasticsearch/xpack/ml/job/process/DataStreamDiagnosticsTests.java b/plugin/src/test/java/org/elasticsearch/xpack/ml/job/process/DataStreamDiagnosticsTests.java index eccd712c1c0..7b80febdf20 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/ml/job/process/DataStreamDiagnosticsTests.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/ml/job/process/DataStreamDiagnosticsTests.java @@ -259,6 +259,12 @@ public class DataStreamDiagnosticsTests extends ESTestCase { assertEquals(null, d.getLatestEmptyBucketTime()); } + public void testFlushAfterZeroRecords() { + DataStreamDiagnostics d = new DataStreamDiagnostics(job); + d.flush(); + assertEquals(0, d.getBucketCount()); + } + private void sendManyDataPoints(DataStreamDiagnostics d, long recordTimestampInMsMin, long recordTimestampInMsMax, long howMuch) { long range = recordTimestampInMsMax - recordTimestampInMsMin;