You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by xh...@apache.org on 2020/01/21 17:04:36 UTC

[incubator-pinot] branch master updated: [TE] change anomaly fetching to use intersection (#4996)

This is an automated email from the ASF dual-hosted git repository.

xhsun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pinot.git


The following commit(s) were added to refs/heads/master by this push:
     new 5b031c3  [TE] change anomaly fetching to use intersection (#4996)
5b031c3 is described below

commit 5b031c374cc673e0a3ca769d46e5c7d54046c6d5
Author: Vincent Chen <ji...@linkedin.com>
AuthorDate: Tue Jan 21 09:04:24 2020 -0800

    [TE] change anomaly fetching to use intersection (#4996)
---
 .../api/user/dashboard/UserDashboardResource.java  | 35 +++++++++++++++-------
 .../user/dashboard/UserDashboardResourceTest.java  | 13 ++++++++
 2 files changed, 38 insertions(+), 10 deletions(-)

diff --git a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/api/user/dashboard/UserDashboardResource.java b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/api/user/dashboard/UserDashboardResource.java
index 19fd2dd..5828b0d 100644
--- a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/api/user/dashboard/UserDashboardResource.java
+++ b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/api/user/dashboard/UserDashboardResource.java
@@ -95,16 +95,31 @@ public class UserDashboardResource {
     }
     Preconditions.checkNotNull(start, "Please specify the start time of the anomaly retrieval window");
 
-    // TODO: Prefer to have intersection of anomalies rather than union
-    List<MergedAnomalyResultDTO> anomalies = new ArrayList<>();
-    // Fetch anomalies by group
-    anomalies.addAll(fetchAnomaliesBySubsGroup(start, end, group));
-    // Fetch anomalies by application
-    anomalies.addAll(fetchAnomaliesByApplication(start, end, application));
-    // Fetch anomalies by metric and/or dataset
-    anomalies.addAll(fetchAnomaliesByMetricDataset(start, end, metric, dataset));
-    // Fetch anomalies by metric dataset pairs
-    anomalies.addAll(fetchAnomaliesByMetricDatasetPairs(start, end, metricDatasetPairs));
+    List<Set<MergedAnomalyResultDTO>> anomalySets = new ArrayList<>();
+    if (group != null) {
+      // Fetch anomalies by group
+      anomalySets.add(new HashSet<>(fetchAnomaliesBySubsGroup(start, end, group)));
+    }
+    if (application != null) {
+      // Fetch anomalies by application
+      anomalySets.add(new HashSet<>(fetchAnomaliesByApplication(start, end, application)));
+    }
+    if (metric != null || dataset != null) {
+      // Fetch anomalies by metric and/or dataset
+      anomalySets.add(new HashSet<>(fetchAnomaliesByMetricDataset(start, end, metric, dataset)));
+    }
+    if (metricDatasetPairs != null && !metricDatasetPairs.isEmpty()) {
+      // Fetch anomalies by metric dataset pairs
+      anomalySets.add(new HashSet<>(fetchAnomaliesByMetricDatasetPairs(start, end, metricDatasetPairs)));
+    }
+    if (anomalySets.isEmpty()) {
+      return getAnomalyFormattedOutput(new ArrayList<>());
+    }
+    // calculate intersection of all non-empty results
+    for (int i = 1; i < anomalySets.size(); i++) {
+      anomalySets.get(0).retainAll(anomalySets.get(i));
+    }
+    List<MergedAnomalyResultDTO> anomalies = new ArrayList<>(anomalySets.get(0));
 
     // sort descending by start time
     Collections.sort(anomalies, (o1, o2) -> -1 * Long.compare(o1.getStartTime(), o2.getStartTime()));
diff --git a/thirdeye/thirdeye-pinot/src/test/java/org/apache/pinot/thirdeye/api/user/dashboard/UserDashboardResourceTest.java b/thirdeye/thirdeye-pinot/src/test/java/org/apache/pinot/thirdeye/api/user/dashboard/UserDashboardResourceTest.java
index 1d06469..12a5c85 100644
--- a/thirdeye/thirdeye-pinot/src/test/java/org/apache/pinot/thirdeye/api/user/dashboard/UserDashboardResourceTest.java
+++ b/thirdeye/thirdeye-pinot/src/test/java/org/apache/pinot/thirdeye/api/user/dashboard/UserDashboardResourceTest.java
@@ -187,6 +187,19 @@ public class UserDashboardResourceTest {
     Assert.assertEquals(extractIds(anomalies), makeSet(this.anomalyIds.get(1), this.anomalyIds.get(2), this.anomalyIds.get(3), this.anomalyIds.get(4)));
   }
 
+  @Test
+  public void testAnomaliesByApplicationAndMetric() throws Exception {
+    List<AnomalySummary> anomalies = this.resource.queryAnomalies(1000L, null, "myApplicationB", null, "test_metric_2", "test_dataset", null, false, null);
+    Assert.assertEquals(anomalies.size(), 1);
+    Assert.assertEquals(extractIds(anomalies), makeSet(this.anomalyIds.get(4)));
+  }
+
+  @Test
+  public void testAnomaliesByApplicationAndMetricEmpty() throws Exception {
+    List<AnomalySummary> anomalies = this.resource.queryAnomalies(1000L, null, "myApplicationA", null, "test_metric_2", "test_dataset", null, false, null);
+    Assert.assertEquals(anomalies.size(), 0);
+  }
+
   private MergedAnomalyResultDTO makeAnomaly(long start, long end, Long detectionId, String metric, String dataset) {
     MergedAnomalyResultDTO anomaly = new MergedAnomalyResultDTO();
     anomaly.setStartTime(start);


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org