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 60a72e4  [TE] detection - add two side pattern in rule filters (#3510)
60a72e4 is described below

commit 60a72e490e72305d6c4369cd22acc9c67885a2c0
Author: Jihao Zhang <[email protected]>
AuthorDate: Mon Nov 19 10:30:24 2018 -0800

    [TE] detection - add two side pattern in rule filters (#3510)
    
    add two side pattern in absolute change/percentage change/SWI filters
---
 .../com/linkedin/thirdeye/detection/Pattern.java   |  3 ++-
 .../components/AbsoluteChangeRuleDetector.java     |  8 ++++++--
 .../components/PercentageChangeRuleDetector.java   |  7 ++++++-
 .../SitewideImpactRuleAnomalyFilter.java           |  3 +--
 .../spec/AbsoluteChangeRuleDetectorSpec.java       |  3 ---
 .../PercentageChangeRuleDetectorTest.java          | 23 ++++++++++++++++++++++
 6 files changed, 38 insertions(+), 9 deletions(-)

diff --git 
a/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/Pattern.java
 
b/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/Pattern.java
index 40b14bf..d89db12 100644
--- 
a/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/Pattern.java
+++ 
b/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/Pattern.java
@@ -21,5 +21,6 @@ package com.linkedin.thirdeye.detection;
  */
 public enum Pattern {
   UP,
-  DOWN
+  DOWN,
+  UP_OR_DOWN
 }
diff --git 
a/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/components/AbsoluteChangeRuleDetector.java
 
b/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/components/AbsoluteChangeRuleDetector.java
index 0c812c7..1838ced 100644
--- 
a/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/components/AbsoluteChangeRuleDetector.java
+++ 
b/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/components/AbsoluteChangeRuleDetector.java
@@ -83,10 +83,14 @@ public class AbsoluteChangeRuleDetector implements 
AnomalyDetector<AbsoluteChang
 
     // defaults
     df.addSeries(COL_ANOMALY, BooleanSeries.fillValues(df.size(), false));
-
     // absolute change
     if (!Double.isNaN(this.absoluteChange)) {
-      df.addSeries(COL_PATTERN, this.pattern.equals(Pattern.UP) ? 
df.getDoubles(COL_DIFF).gt(0) : df.getDoubles(COL_DIFF).lt(0));
+      // consistent with pattern
+      if (pattern.equals(Pattern.UP_OR_DOWN) ) {
+        df.addSeries(COL_PATTERN, BooleanSeries.fillValues(df.size(), true));
+      } else {
+        df.addSeries(COL_PATTERN, this.pattern.equals(Pattern.UP) ? 
df.getDoubles(COL_DIFF).gt(0) : df.getDoubles(COL_DIFF).lt(0));
+      }
       df.addSeries(COL_DIFF_VIOLATION, 
df.getDoubles(COL_DIFF).abs().gte(this.absoluteChange));
       df.mapInPlace(BooleanSeries.ALL_TRUE, COL_ANOMALY, COL_PATTERN, 
COL_DIFF_VIOLATION);
     }
diff --git 
a/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/components/PercentageChangeRuleDetector.java
 
b/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/components/PercentageChangeRuleDetector.java
index 14f09d5..be35f7d 100644
--- 
a/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/components/PercentageChangeRuleDetector.java
+++ 
b/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/components/PercentageChangeRuleDetector.java
@@ -94,7 +94,12 @@ public class PercentageChangeRuleDetector implements 
AnomalyDetector<PercentageC
 
     // relative change
     if (!Double.isNaN(this.percentageChange)) {
-      df.addSeries(COL_PATTERN, this.pattern.equals(Pattern.UP) ? 
df.getDoubles(COL_CHANGE).gt(0) : df.getDoubles(COL_CHANGE).lt(0));
+      // consistent with pattern
+      if (pattern.equals(Pattern.UP_OR_DOWN) ) {
+        df.addSeries(COL_PATTERN, BooleanSeries.fillValues(df.size(), true));
+      } else {
+        df.addSeries(COL_PATTERN, this.pattern.equals(Pattern.UP) ? 
df.getDoubles(COL_CHANGE).gt(0) : df.getDoubles(COL_CHANGE).lt(0));
+      }
       df.addSeries(COL_CHANGE_VIOLATION, 
df.getDoubles(COL_CHANGE).abs().gte(this.percentageChange));
       df.mapInPlace(BooleanSeries.ALL_TRUE, COL_ANOMALY, COL_PATTERN, 
COL_CHANGE_VIOLATION);
     }
diff --git 
a/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/components/SitewideImpactRuleAnomalyFilter.java
 
b/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/components/SitewideImpactRuleAnomalyFilter.java
index 5f85d18..1eee883 100644
--- 
a/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/components/SitewideImpactRuleAnomalyFilter.java
+++ 
b/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/components/SitewideImpactRuleAnomalyFilter.java
@@ -75,8 +75,7 @@ public class SitewideImpactRuleAnomalyFilter implements 
AnomalyFilter<SitewideIm
     double siteWideBaselineValue = getValueFromAggregates(siteWideSlice, 
aggregates);
 
     // if inconsistent with up/down, filter the anomaly
-    if ((currentValue < baselineValue && pattern.equals(Pattern.UP)) || 
(currentValue > baselineValue && pattern.equals(
-        Pattern.DOWN))) {
+    if (!pattern.equals(Pattern.UP_OR_DOWN) && (currentValue < baselineValue 
&& pattern.equals(Pattern.UP)) || (currentValue > baselineValue && 
pattern.equals(Pattern.DOWN))) {
       return false;
     }
     // if doesn't pass the threshold, filter the anomaly
diff --git 
a/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/spec/AbsoluteChangeRuleDetectorSpec.java
 
b/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/spec/AbsoluteChangeRuleDetectorSpec.java
index c6b25aa..26f5d66 100644
--- 
a/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/spec/AbsoluteChangeRuleDetectorSpec.java
+++ 
b/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/spec/AbsoluteChangeRuleDetectorSpec.java
@@ -16,9 +16,6 @@
 
 package com.linkedin.thirdeye.detection.spec;
 
-import com.linkedin.thirdeye.detection.Pattern;
-
-
 public class AbsoluteChangeRuleDetectorSpec extends AbstractSpec {
   private double absoluteChange = Double.NaN;
   private String offset = "wo1w";
diff --git 
a/thirdeye/thirdeye-pinot/src/test/java/com/linkedin/thirdeye/detection/components/PercentageChangeRuleDetectorTest.java
 
b/thirdeye/thirdeye-pinot/src/test/java/com/linkedin/thirdeye/detection/components/PercentageChangeRuleDetectorTest.java
index d3f4e6d..016f8e2 100644
--- 
a/thirdeye/thirdeye-pinot/src/test/java/com/linkedin/thirdeye/detection/components/PercentageChangeRuleDetectorTest.java
+++ 
b/thirdeye/thirdeye-pinot/src/test/java/com/linkedin/thirdeye/detection/components/PercentageChangeRuleDetectorTest.java
@@ -125,4 +125,27 @@ public class PercentageChangeRuleDetectorTest {
     Assert.assertEquals(anomalies.get(0).getStartTime(), 2181600000L);
     Assert.assertEquals(anomalies.get(0).getEndTime(), 2185200000L);
   }
+
+  @Test
+  public void testThreeWeekMedianChangeUporDown() {
+    PercentageChangeRuleDetector detector = new PercentageChangeRuleDetector();
+    PercentageChangeRuleDetectorSpec spec = new 
PercentageChangeRuleDetectorSpec();
+    spec.setPercentageChange(0.3);
+    spec.setOffset("median3w");
+    spec.setPattern("up_or_down");
+    detector.init(spec, new DefaultInputDataFetcher(this.provider, -1));
+    List<MergedAnomalyResultDTO> anomalies = detector.runDetection(new 
Interval(1814400000L, 2419200000L), "thirdeye:metric:1");
+    Assert.assertEquals(anomalies.size(), 5);
+    Assert.assertEquals(anomalies.get(0).getStartTime(), 2005200000L);
+    Assert.assertEquals(anomalies.get(0).getEndTime(), 2008800000L);
+    Assert.assertEquals(anomalies.get(1).getStartTime(), 2134800000L);
+    Assert.assertEquals(anomalies.get(1).getEndTime(), 2138400000L);
+    Assert.assertEquals(anomalies.get(2).getStartTime(), 2152800000L);
+    Assert.assertEquals(anomalies.get(2).getEndTime(), 2156400000L);
+    Assert.assertEquals(anomalies.get(3).getStartTime(), 2181600000L);
+    Assert.assertEquals(anomalies.get(3).getEndTime(), 2185200000L);
+    Assert.assertEquals(anomalies.get(4).getStartTime(), 2322000000L);
+    Assert.assertEquals(anomalies.get(4).getEndTime(), 2325600000L);
+  }
+
 }
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to