You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by ji...@apache.org on 2019/09/16 19:07:13 UTC

[incubator-pinot] branch master updated: [TE] consider anomaly type during merge (#4613)

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

jihao 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 09207f9  [TE] consider anomaly type during merge (#4613)
09207f9 is described below

commit 09207f9f0729dcdac8f756dfa475b674e7f5c1f3
Author: Xiaohui Sun <xh...@linkedin.com>
AuthorDate: Mon Sep 16 12:07:08 2019 -0700

    [TE] consider anomaly type during merge (#4613)
    
    This PR fixes the logic so that we don't merge two anomalies if they have different types.
---
 .../thirdeye/detection/algorithm/MergeWrapper.java | 13 +++++++----
 .../wrapper/ChildKeepingMergeWrapper.java          |  3 ++-
 .../detection/algorithm/MergeWrapperTest.java      | 26 ++++++++++++++++++++++
 3 files changed, 37 insertions(+), 5 deletions(-)

diff --git a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/algorithm/MergeWrapper.java b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/algorithm/MergeWrapper.java
index a11ae54..c6f809d 100644
--- a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/algorithm/MergeWrapper.java
+++ b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/algorithm/MergeWrapper.java
@@ -33,6 +33,7 @@ import java.util.Set;
 import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 import org.apache.commons.collections4.MapUtils;
+import org.apache.pinot.thirdeye.anomaly.AnomalyType;
 import org.apache.pinot.thirdeye.common.dimension.DimensionMap;
 import org.apache.pinot.thirdeye.datalayer.dto.DetectionConfigDTO;
 import org.apache.pinot.thirdeye.datalayer.dto.EvaluationDTO;
@@ -328,6 +329,7 @@ public class MergeWrapper extends DetectionPipeline {
     to.setScore(from.getScore());
     to.setWeight(from.getWeight());
     to.setProperties(from.getProperties());
+    to.setType(from.getType());
     return to;
   }
 
@@ -337,18 +339,21 @@ public class MergeWrapper extends DetectionPipeline {
     final DimensionMap dimensions;
     final String mergeKey;
     final String componentKey;
+    final AnomalyType type;
 
-    public AnomalyKey(String metric, String collection, DimensionMap dimensions, String mergeKey, String componentKey) {
+    public AnomalyKey(String metric, String collection, DimensionMap dimensions, String mergeKey, String componentKey,
+        AnomalyType type) {
       this.metric = metric;
       this.collection = collection;
       this.dimensions = dimensions;
       this.mergeKey = mergeKey;
       this.componentKey = componentKey;
+      this.type = type;
     }
 
     public static AnomalyKey from(MergedAnomalyResultDTO anomaly) {
       return new AnomalyKey(anomaly.getMetric(), anomaly.getCollection(), anomaly.getDimensions(), anomaly.getProperties().get(PROP_MERGE_KEY),
-          anomaly.getProperties().get(PROP_DETECTOR_COMPONENT_NAME));
+          anomaly.getProperties().get(PROP_DETECTOR_COMPONENT_NAME), anomaly.getType());
     }
 
     @Override
@@ -362,12 +367,12 @@ public class MergeWrapper extends DetectionPipeline {
       AnomalyKey that = (AnomalyKey) o;
       return Objects.equals(metric, that.metric) && Objects.equals(collection, that.collection) && Objects.equals(
           dimensions, that.dimensions) && Objects.equals(mergeKey, that.mergeKey) && Objects.equals(componentKey,
-          that.componentKey);
+          that.componentKey) && Objects.equals(type, that.type);
     }
 
     @Override
     public int hashCode() {
-      return Objects.hash(metric, collection, dimensions, mergeKey, componentKey);
+      return Objects.hash(metric, collection, dimensions, mergeKey, componentKey, type);
     }
   }
 }
diff --git a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/wrapper/ChildKeepingMergeWrapper.java b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/wrapper/ChildKeepingMergeWrapper.java
index 89438aa..1becf9b 100644
--- a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/wrapper/ChildKeepingMergeWrapper.java
+++ b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/wrapper/ChildKeepingMergeWrapper.java
@@ -79,7 +79,8 @@ public class ChildKeepingMergeWrapper extends BaselineFillingMergeWrapper {
       }
 
       MergeWrapper.AnomalyKey key =
-          new MergeWrapper.AnomalyKey(anomaly.getMetric(), anomaly.getCollection(), anomaly.getDimensions(), groupKey, "");
+          new MergeWrapper.AnomalyKey(anomaly.getMetric(), anomaly.getCollection(), anomaly.getDimensions(), groupKey, "",
+              anomaly.getType());
       MergedAnomalyResultDTO parent = parents.get(key);
 
       if (parent == null || anomaly.getStartTime() - parent.getEndTime() > this.maxGap) {
diff --git a/thirdeye/thirdeye-pinot/src/test/java/org/apache/pinot/thirdeye/detection/algorithm/MergeWrapperTest.java b/thirdeye/thirdeye-pinot/src/test/java/org/apache/pinot/thirdeye/detection/algorithm/MergeWrapperTest.java
index 5a008ab..c5e98f5 100644
--- a/thirdeye/thirdeye-pinot/src/test/java/org/apache/pinot/thirdeye/detection/algorithm/MergeWrapperTest.java
+++ b/thirdeye/thirdeye-pinot/src/test/java/org/apache/pinot/thirdeye/detection/algorithm/MergeWrapperTest.java
@@ -24,6 +24,7 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import org.apache.pinot.thirdeye.anomaly.AnomalyType;
 import org.apache.pinot.thirdeye.datalayer.dto.DetectionConfigDTO;
 import org.apache.pinot.thirdeye.datalayer.dto.MergedAnomalyResultDTO;
 import org.apache.pinot.thirdeye.detection.DataProvider;
@@ -320,4 +321,29 @@ public class MergeWrapperTest {
     Assert.assertTrue(output.getAnomalies().contains(setAnomalyId(makeAnomaly(50, 2800), 0)));
     Assert.assertTrue(output.getAnomalies().get(0).getProperties().get(propertyKey).equals(propertyValue));
   }
+
+  @Test
+  public void testMergerAnomalyType() throws Exception {
+    this.config.getProperties().put(PROP_MAX_GAP, 100);
+
+    MergedAnomalyResultDTO trendAnomaly = makeAnomaly(100, 1000);
+    trendAnomaly.setType(AnomalyType.TREND_CHANGE);
+
+    MergedAnomalyResultDTO deviationAnomaly = makeAnomaly(50, 1200);
+    deviationAnomaly.setType(AnomalyType.DEVIATION);
+
+    this.outputs.add(new MockPipelineOutput(Arrays.asList(trendAnomaly, deviationAnomaly), 3700));
+
+    Map<String, Object> nestedProperties = new HashMap<>();
+    nestedProperties.put(PROP_CLASS_NAME, "none");
+    nestedProperties.put(PROP_METRIC_URN, "thirdeye:metric:3");
+
+    this.nestedProperties.add(nestedProperties);
+
+    this.wrapper = new MergeWrapper(this.provider, this.config, 1000, 3000);
+    DetectionPipelineResult output = this.wrapper.run();
+
+    // trend anomaly was not merged with deviation Anomaly
+    Assert.assertTrue(output.getAnomalies().contains(trendAnomaly));
+  }
 }


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