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/05/13 17:24:49 UTC

[incubator-pinot] branch master updated: [TE] Threshold filter on current value of an anomaly (#4203)

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 74ddc3a  [TE] Threshold filter on current value of an anomaly (#4203)
74ddc3a is described below

commit 74ddc3a1634ad9144fca3882169a4693e80b1734
Author: Jihao Zhang <ji...@linkedin.com>
AuthorDate: Mon May 13 10:24:43 2019 -0700

    [TE] Threshold filter on current value of an anomaly (#4203)
    
    This PR makes it possible for the threshold filter to filter on the current value of the anomaly.
---
 .../components/ThresholdRuleAnomalyFilter.java       | 10 +++++++++-
 .../detection/spec/ThresholdRuleFilterSpec.java      | 20 ++++++++++++++++++--
 .../components/ThresholdRuleAnomalyFilterTest.java   | 13 +++++++++++++
 3 files changed, 40 insertions(+), 3 deletions(-)

diff --git a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/components/ThresholdRuleAnomalyFilter.java b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/components/ThresholdRuleAnomalyFilter.java
index be7fae0..4a1245d 100644
--- a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/components/ThresholdRuleAnomalyFilter.java
+++ b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/components/ThresholdRuleAnomalyFilter.java
@@ -50,6 +50,8 @@ public class ThresholdRuleAnomalyFilter implements AnomalyFilter<ThresholdRuleFi
   private double maxValueHourly;
   private double minValueDaily;
   private double maxValueDaily;
+  private double maxValue;
+  private double minValue;
   private InputDataFetcher dataFetcher;
 
   @Override
@@ -64,13 +66,17 @@ public class ThresholdRuleAnomalyFilter implements AnomalyFilter<ThresholdRuleFi
     Interval anomalyInterval = new Interval(anomaly.getStartTime(), anomaly.getEndTime());
     double hourlyMultiplier = TimeUnit.HOURS.toMillis(1) / (double) anomalyInterval.toDurationMillis();
     double dailyMultiplier = TimeUnit.DAYS.toMillis(1) / (double) anomalyInterval.toDurationMillis();
+    if (!Double.isNaN(this.minValue) && currentValue < this.minValue
+        || !Double.isNaN(this.maxValue) && currentValue > this.maxValue) {
+      return false;
+    }
     if (!Double.isNaN(this.minValueHourly) && currentValue * hourlyMultiplier < this.minValueHourly) {
       return false;
     }
     if (!Double.isNaN(this.maxValueHourly) && currentValue * hourlyMultiplier > this.maxValueHourly) {
       return false;
     }
-    if (!Double.isNaN(this.minValueDaily) && currentValue * dailyMultiplier< this.minValueDaily) {
+    if (!Double.isNaN(this.minValueDaily) && currentValue * dailyMultiplier < this.minValueDaily) {
       return false;
     }
     if (!Double.isNaN(this.maxValueDaily) && currentValue * dailyMultiplier > this.maxValueDaily) {
@@ -85,6 +91,8 @@ public class ThresholdRuleAnomalyFilter implements AnomalyFilter<ThresholdRuleFi
     this.maxValueHourly = spec.getMaxValueHourly();
     this.minValueDaily = spec.getMinValueDaily();
     this.maxValueDaily = spec.getMaxValueDaily();
+    this.maxValue = spec.getMaxValue();
+    this.minValue = spec.getMinValue();
     this.dataFetcher = dataFetcher;
   }
 
diff --git a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/spec/ThresholdRuleFilterSpec.java b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/spec/ThresholdRuleFilterSpec.java
index 2c97df5..b22ea30 100644
--- a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/spec/ThresholdRuleFilterSpec.java
+++ b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/spec/ThresholdRuleFilterSpec.java
@@ -26,10 +26,10 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
 public class ThresholdRuleFilterSpec extends AbstractSpec {
   private double minValueHourly = Double.NaN;
   private double minValueDaily = Double.NaN;
-
   private double maxValueHourly = Double.NaN;
   private double maxValueDaily = Double.NaN;
-
+  private double minValue = Double.NaN;
+  private double maxValue = Double.NaN;
 
   public double getMinValueHourly() {
     return minValueHourly;
@@ -62,4 +62,20 @@ public class ThresholdRuleFilterSpec extends AbstractSpec {
   public void setMaxValueDaily(double maxValueDaily) {
     this.maxValueDaily = maxValueDaily;
   }
+
+  public double getMinValue() {
+    return minValue;
+  }
+
+  public void setMinValue(double minValue) {
+    this.minValue = minValue;
+  }
+
+  public double getMaxValue() {
+    return maxValue;
+  }
+
+  public void setMaxValue(double maxValue) {
+    this.maxValue = maxValue;
+  }
 }
diff --git a/thirdeye/thirdeye-pinot/src/test/java/org/apache/pinot/thirdeye/detection/components/ThresholdRuleAnomalyFilterTest.java b/thirdeye/thirdeye-pinot/src/test/java/org/apache/pinot/thirdeye/detection/components/ThresholdRuleAnomalyFilterTest.java
index 84ae901..3429d27 100644
--- a/thirdeye/thirdeye-pinot/src/test/java/org/apache/pinot/thirdeye/detection/components/ThresholdRuleAnomalyFilterTest.java
+++ b/thirdeye/thirdeye-pinot/src/test/java/org/apache/pinot/thirdeye/detection/components/ThresholdRuleAnomalyFilterTest.java
@@ -192,6 +192,19 @@ public class ThresholdRuleAnomalyFilterTest {
     Assert.assertEquals(anomalies.get(2), this.anomalies.get(2));
   }
 
+  @Test(priority = 6)
+  public void testThresholdRuleFilterCurrentMinAndMax() throws Exception {
+    this.specs.put("minValue", 300);
+    this.specs.put("maxValue", 500);
+    this.thresholdRuleFilter = new AnomalyFilterWrapper(this.testDataProvider, this.config, 1551186000000L, 1551189600000L);
+    DetectionPipelineResult result = this.thresholdRuleFilter.run();
+    List<MergedAnomalyResultDTO> anomalies = result.getAnomalies();
+    Assert.assertEquals(result.getLastTimestamp(), 1551200400000L);
+    Assert.assertEquals(anomalies.size(), 1);
+    Assert.assertEquals(anomalies.get(0), this.anomalies.get(2));
+  }
+
+
   private static MergedAnomalyResultDTO makeAnomaly(long start, long end) {
     MergedAnomalyResultDTO anomaly = DetectionTestUtils.makeAnomaly(125L, start, end);
     anomaly.setMetricUrn(METRIC_URN);


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