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/01/15 19:14:42 UTC

[incubator-pinot] branch master updated: [TE] detection - duration anomaly filter (#3686)

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 74e2d5f  [TE] detection - duration anomaly filter (#3686)
74e2d5f is described below

commit 74e2d5f827aac051099e4314c314c3d8ac949dc5
Author: Jihao Zhang <ji...@linkedin.com>
AuthorDate: Tue Jan 15 11:14:38 2019 -0800

    [TE] detection - duration anomaly filter (#3686)
    
    The anomaly filter that filters anomalies based on the anomaly duration.
---
 .../components/DurationAnomalyFilter.java          | 56 ++++++++++++++++++++++
 .../detection/spec/DurationAnomalyFilterSpec.java  | 42 ++++++++++++++++
 .../components/DurationAnomalyFilterTest.java      | 46 ++++++++++++++++++
 3 files changed, 144 insertions(+)

diff --git a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/components/DurationAnomalyFilter.java b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/components/DurationAnomalyFilter.java
new file mode 100644
index 0000000..7aaa823
--- /dev/null
+++ b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/components/DurationAnomalyFilter.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.pinot.thirdeye.detection.components;
+
+import java.time.Duration;
+import org.apache.pinot.thirdeye.datalayer.dto.MergedAnomalyResultDTO;
+import org.apache.pinot.thirdeye.detection.InputDataFetcher;
+import org.apache.pinot.thirdeye.detection.annotation.Components;
+import org.apache.pinot.thirdeye.detection.spec.DurationAnomalyFilterSpec;
+import org.apache.pinot.thirdeye.detection.spi.components.AnomalyFilter;
+
+
+/**
+ * Duration filter. Filter the anomaly based on the anomaly duration.
+ * USE WITH CAUTION. If min duration is set larger than the maximum possible anomaly duration
+ * the detection module produced, all anomalies would potentially be filtered.
+ */
+@Components(type = "DURATION_FILTER")
+public class DurationAnomalyFilter implements AnomalyFilter<DurationAnomalyFilterSpec> {
+  private Duration minDuration;
+  private Duration maxDuration;
+
+  @Override
+  public boolean isQualified(MergedAnomalyResultDTO anomaly) {
+    long anomalyDuration = anomaly.getEndTime() - anomaly.getStartTime();
+    return anomalyDuration >= this.minDuration.toMillis() && anomalyDuration <= this.maxDuration.toMillis();
+  }
+
+  @Override
+  public void init(DurationAnomalyFilterSpec spec, InputDataFetcher dataFetcher) {
+    if (spec.getMinDuration() != null){
+      this.minDuration = Duration.parse(spec.getMinDuration());
+    }
+    if (spec.getMaxDuration() != null) {
+      this.maxDuration = Duration.parse(spec.getMaxDuration());
+    }
+  }
+}
diff --git a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/spec/DurationAnomalyFilterSpec.java b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/spec/DurationAnomalyFilterSpec.java
new file mode 100644
index 0000000..8fb0122
--- /dev/null
+++ b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/spec/DurationAnomalyFilterSpec.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.pinot.thirdeye.detection.spec;
+
+public class DurationAnomalyFilterSpec extends AbstractSpec {
+  private String minDuration;
+  private String maxDuration;
+
+  public String getMinDuration() {
+    return minDuration;
+  }
+
+  public void setMinDuration(String minDuration) {
+    this.minDuration = minDuration;
+  }
+
+  public String getMaxDuration() {
+    return maxDuration;
+  }
+
+  public void setMaxDuration(String maxDuration) {
+    this.maxDuration = maxDuration;
+  }
+}
diff --git a/thirdeye/thirdeye-pinot/src/test/java/org/apache/pinot/thirdeye/detection/components/DurationAnomalyFilterTest.java b/thirdeye/thirdeye-pinot/src/test/java/org/apache/pinot/thirdeye/detection/components/DurationAnomalyFilterTest.java
new file mode 100644
index 0000000..d64041b
--- /dev/null
+++ b/thirdeye/thirdeye-pinot/src/test/java/org/apache/pinot/thirdeye/detection/components/DurationAnomalyFilterTest.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.pinot.thirdeye.detection.components;
+
+import org.apache.pinot.thirdeye.detection.DefaultInputDataFetcher;
+import org.apache.pinot.thirdeye.detection.MockDataProvider;
+import org.apache.pinot.thirdeye.detection.spec.DurationAnomalyFilterSpec;
+import org.apache.pinot.thirdeye.detection.spi.components.AnomalyFilter;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import static org.apache.pinot.thirdeye.detection.DetectionTestUtils.*;
+
+
+public class DurationAnomalyFilterTest {
+  @Test
+  public void testIsQualified() {
+    AnomalyFilter anomalyFilter = new DurationAnomalyFilter();
+    DurationAnomalyFilterSpec spec = new DurationAnomalyFilterSpec();
+    spec.setMaxDuration("PT3H");
+    spec.setMinDuration("PT2H");
+    anomalyFilter.init(spec, new DefaultInputDataFetcher(new MockDataProvider(), -1));
+    Assert.assertEquals(anomalyFilter.isQualified(makeAnomaly(1547164800000L, 1547168400000L)), false);
+    Assert.assertEquals(anomalyFilter.isQualified(makeAnomaly(1547164800000L, 1547172000000L)), true);
+    Assert.assertEquals(anomalyFilter.isQualified(makeAnomaly(1547164800000L, 1547175600000L)), true);
+    Assert.assertEquals(anomalyFilter.isQualified(makeAnomaly(1547164800000L, 1547179200000L)), false);
+  }
+}


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