You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by GitBox <gi...@apache.org> on 2019/01/15 19:14:40 UTC
[incubator-pinot] Diff for: [GitHub] jihaozh merged pull request #3686: [TE]
detection - duration anomaly filter
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 0000000000..7aaa823c52
--- /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 0000000000..8fb01221be
--- /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 0000000000..d64041bd62
--- /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);
+ }
+}
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org