From 3a06ebbf88cfc47f605e74563b30b440c32beed0 Mon Sep 17 00:00:00 2001 From: Yizhe Liu Date: Mon, 26 Oct 2020 23:16:16 -0700 Subject: [PATCH 1/2] Fix edge case where entities found for preview is emtpy --- .../opendistroforelasticsearch/ad/AnomalyDetectorRunner.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/AnomalyDetectorRunner.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/AnomalyDetectorRunner.java index 9f5b3d5b..43efa0b9 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/AnomalyDetectorRunner.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/AnomalyDetectorRunner.java @@ -72,6 +72,9 @@ public void executeDetector(AnomalyDetector detector, Instant startTime, Instant if (categoryField != null && !categoryField.isEmpty()) { featureManager.getPreviewEntities(detector, startTime.toEpochMilli(), endTime.toEpochMilli(), ActionListener.wrap(entities -> { + if (entities == null || entities.isEmpty()) { + listener.onResponse(Collections.emptyList()); + } ActionListener entityAnomalyResultListener = ActionListener .wrap( entityAnomalyResult -> { listener.onResponse(entityAnomalyResult.getAnomalyResults()); }, From 3dc93764ceefe2b73a37220f8831f8bf4ad9aab2 Mon Sep 17 00:00:00 2001 From: Yizhe Liu Date: Wed, 28 Oct 2020 17:38:42 -0700 Subject: [PATCH 2/2] Add TODO to further improve reponse of Preview API and error handling on Front-end --- .../ad/AnomalyDetectorRunner.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/AnomalyDetectorRunner.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/AnomalyDetectorRunner.java index 43efa0b9..6bcd5d7f 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/AnomalyDetectorRunner.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/AnomalyDetectorRunner.java @@ -73,6 +73,9 @@ public void executeDetector(AnomalyDetector detector, Instant startTime, Instant featureManager.getPreviewEntities(detector, startTime.toEpochMilli(), endTime.toEpochMilli(), ActionListener.wrap(entities -> { if (entities == null || entities.isEmpty()) { + // TODO return exception like IllegalArgumentException to explain data is not enough for preview + // This also requires front-end change to handle error message correspondingly + // We return empty list for now to avoid breaking front-end listener.onResponse(Collections.emptyList()); } ActionListener entityAnomalyResultListener = ActionListener @@ -119,6 +122,9 @@ public void executeDetector(AnomalyDetector detector, Instant startTime, Instant private void onFailure(Exception e, ActionListener> listener, String detectorId) { logger.info("Fail to preview anomaly detector " + detectorId, e); + // TODO return exception like IllegalArgumentException to explain data is not enough for preview + // This also requires front-end change to handle error message correspondingly + // We return empty list for now to avoid breaking front-end listener.onResponse(Collections.emptyList()); }