akshayrai closed pull request #3590: [TE] Update alert schemes and suppressors
in the annotation alert registry
URL: https://github.com/apache/incubator-pinot/pull/3590
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git
a/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/anomaly/ThirdEyeAnomalyApplication.java
b/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/anomaly/ThirdEyeAnomalyApplication.java
index 888d632f3a..ffe34dcbe1 100644
---
a/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/anomaly/ThirdEyeAnomalyApplication.java
+++
b/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/anomaly/ThirdEyeAnomalyApplication.java
@@ -38,7 +38,8 @@
import
com.linkedin.thirdeye.datasource.pinot.resources.PinotDataSourceResource;
import com.linkedin.thirdeye.detection.DetectionPipelineScheduler;
import com.linkedin.thirdeye.detection.alert.DetectionAlertScheduler;
-import com.linkedin.thirdeye.detection.annotation.DetectionRegistry;
+import
com.linkedin.thirdeye.detection.annotation.registry.DetectionAlertRegistry;
+import com.linkedin.thirdeye.detection.annotation.registry.DetectionRegistry;
import com.linkedin.thirdeye.detector.email.filter.AlertFilterFactory;
import com.linkedin.thirdeye.detector.function.AnomalyFunctionFactory;
import com.linkedin.thirdeye.tracking.RequestStatisticsLogger;
@@ -113,8 +114,9 @@ public void run(final ThirdEyeAnomalyConfiguration config,
final Environment env
LOG.error("Exception while loading caches", e);
}
- // instantiate detection registry
+ // instantiate registry
DetectionRegistry.init();
+ DetectionAlertRegistry.init();
environment.getObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);
environment.getObjectMapper().registerModule(makeMapperModule());
diff --git
a/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/dashboard/ThirdEyeDashboardApplication.java
b/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/dashboard/ThirdEyeDashboardApplication.java
index 5014431b74..52831daa3e 100644
---
a/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/dashboard/ThirdEyeDashboardApplication.java
+++
b/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/dashboard/ThirdEyeDashboardApplication.java
@@ -69,7 +69,8 @@
import com.linkedin.thirdeye.detection.DetectionMigrationResource;
import com.linkedin.thirdeye.detection.DetectionResource;
import
com.linkedin.thirdeye.detection.annotation.DetectionConfigurationResource;
-import com.linkedin.thirdeye.detection.annotation.DetectionRegistry;
+import
com.linkedin.thirdeye.detection.annotation.registry.DetectionAlertRegistry;
+import com.linkedin.thirdeye.detection.annotation.registry.DetectionRegistry;
import com.linkedin.thirdeye.detection.yaml.YamlResource;
import com.linkedin.thirdeye.detector.email.filter.AlertFilterFactory;
import com.linkedin.thirdeye.detector.function.AnomalyFunctionFactory;
@@ -151,8 +152,9 @@ public void run(ThirdEyeDashboardConfiguration config,
Environment env)
LOG.error("Exception while loading caches", e);
}
- // instantiate detection registry
+ // instantiate registry
DetectionRegistry.init();
+ DetectionAlertRegistry.init();
AnomalyFunctionFactory anomalyFunctionFactory = new
AnomalyFunctionFactory(config.getFunctionConfigPath());
AlertFilterFactory alertFilterFactory = new
AlertFilterFactory(config.getAlertFilterConfigPath());
diff --git
a/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/alert/scheme/DetectionEmailAlerter.java
b/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/alert/scheme/DetectionEmailAlerter.java
index a956b9042c..53e6e91ebc 100644
---
a/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/alert/scheme/DetectionEmailAlerter.java
+++
b/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/alert/scheme/DetectionEmailAlerter.java
@@ -32,6 +32,7 @@
import com.linkedin.thirdeye.detection.alert.AlertUtils;
import com.linkedin.thirdeye.detection.alert.DetectionAlertFilterRecipients;
import com.linkedin.thirdeye.detection.alert.DetectionAlertFilterResult;
+import com.linkedin.thirdeye.detection.annotation.AlertScheme;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -50,6 +51,7 @@
import static com.linkedin.thirdeye.anomaly.SmtpConfiguration.SMTP_CONFIG_KEY;
+@AlertScheme(type = "EMAIL")
public class DetectionEmailAlerter extends DetectionAlertScheme {
private static final Logger LOG =
LoggerFactory.getLogger(DetectionEmailAlerter.class);
diff --git
a/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/alert/suppress/DetectionAlertTimeWindowSuppressor.java
b/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/alert/suppress/DetectionAlertTimeWindowSuppressor.java
index 9fd5ded544..d4a42eaec7 100644
---
a/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/alert/suppress/DetectionAlertTimeWindowSuppressor.java
+++
b/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/alert/suppress/DetectionAlertTimeWindowSuppressor.java
@@ -10,6 +10,7 @@
import com.linkedin.thirdeye.datasource.DAORegistry;
import com.linkedin.thirdeye.detection.ConfigUtils;
import com.linkedin.thirdeye.detection.alert.DetectionAlertFilterResult;
+import com.linkedin.thirdeye.detection.annotation.AlertSuppressor;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -27,6 +28,7 @@
* 2. Suppress alerts in the time window based on some thresholds.
* ({@link #EXPECTED_CHANGE_KEY} and {@link #ACCEPTABLE_DEVIATION_KEY})
*/
+@AlertSuppressor(type = "TIME_WINDOW")
public class DetectionAlertTimeWindowSuppressor extends
DetectionAlertSuppressor {
private static final Logger LOG =
LoggerFactory.getLogger(DetectionAlertTimeWindowSuppressor.class);
diff --git
a/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/annotation/AlertScheme.java
b/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/annotation/AlertScheme.java
new file mode 100644
index 0000000000..517abc23dd
--- /dev/null
+++
b/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/annotation/AlertScheme.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2014-2018 LinkedIn Corp. ([email protected])
+ *
+ * Licensed 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 com.linkedin.thirdeye.detection.annotation;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+
+@Target({ElementType.TYPE})
+@Retention(RetentionPolicy.RUNTIME)
+@Inherited
+public @interface AlertScheme {
+ @JsonProperty String type() default "";
+}
diff --git
a/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/annotation/AlertSuppressor.java
b/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/annotation/AlertSuppressor.java
new file mode 100644
index 0000000000..da5e0dbddf
--- /dev/null
+++
b/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/annotation/AlertSuppressor.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2014-2018 LinkedIn Corp. ([email protected])
+ *
+ * Licensed 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 com.linkedin.thirdeye.detection.annotation;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+
+@Target({ElementType.TYPE})
+@Retention(RetentionPolicy.RUNTIME)
+@Inherited
+public @interface AlertSuppressor {
+ @JsonProperty String type() default "";
+}
diff --git
a/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/annotation/DetectionConfigurationResource.java
b/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/annotation/DetectionConfigurationResource.java
index 2c3ee2d75a..719d49c325 100644
---
a/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/annotation/DetectionConfigurationResource.java
+++
b/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/annotation/DetectionConfigurationResource.java
@@ -17,6 +17,7 @@
package com.linkedin.thirdeye.detection.annotation;
import com.fasterxml.jackson.databind.ObjectMapper;
+import com.linkedin.thirdeye.detection.annotation.registry.DetectionRegistry;
import com.wordnik.swagger.annotations.ApiParam;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
diff --git
a/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/annotation/registry/DetectionAlertRegistry.java
b/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/annotation/registry/DetectionAlertRegistry.java
new file mode 100644
index 0000000000..83efc22d5a
--- /dev/null
+++
b/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/annotation/registry/DetectionAlertRegistry.java
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2014-2018 LinkedIn Corp. ([email protected])
+ *
+ * Licensed 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 com.linkedin.thirdeye.detection.annotation.registry;
+
+import com.google.common.base.Preconditions;
+import com.linkedin.thirdeye.detection.alert.scheme.DetectionAlertScheme;
+import com.linkedin.thirdeye.detection.alert.suppress.DetectionAlertSuppressor;
+import com.linkedin.thirdeye.detection.annotation.AlertScheme;
+import com.linkedin.thirdeye.detection.annotation.AlertSuppressor;
+import java.lang.annotation.Annotation;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import org.reflections.Reflections;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * The detection alert registry.
+ */
+public class DetectionAlertRegistry {
+ private static final Logger LOG =
LoggerFactory.getLogger(DetectionAlertRegistry.class);
+
+ // Alert Scheme type to Alert Scheme class name
+ private static final Map<String, String> ALERT_SCHEME_MAP = new HashMap<>();
+
+ // Alert Suppressor type to Alert Suppressor class name
+ private static final Map<String, String> ALERT_SUPPRESSOR_MAP = new
HashMap<>();
+
+ private static final DetectionAlertRegistry INSTANCE = new
DetectionAlertRegistry();
+
+ public static DetectionAlertRegistry getInstance() {
+ return INSTANCE;
+ }
+
+ /**
+ * Read all the alert schemes and suppressors and initialize the registry.
+ */
+ public static void init() {
+ try {
+ Reflections reflections = new Reflections();
+
+ // register alert schemes
+ Set<Class<? extends DetectionAlertScheme>> alertSchemeClasses =
+ reflections.getSubTypesOf(DetectionAlertScheme.class);
+ for (Class clazz : alertSchemeClasses) {
+ for (Annotation annotation : clazz.getAnnotations()) {
+ if (annotation instanceof AlertScheme) {
+ ALERT_SCHEME_MAP.put(((AlertScheme) annotation).type(),
clazz.getName());
+ }
+ }
+ }
+
+ // register alert suppressors
+ Set<Class<? extends DetectionAlertSuppressor>> alertSuppressorClasses =
+ reflections.getSubTypesOf(DetectionAlertSuppressor.class);
+ for (Class clazz : alertSuppressorClasses) {
+ for (Annotation annotation : clazz.getAnnotations()) {
+ if (annotation instanceof AlertSuppressor) {
+ ALERT_SUPPRESSOR_MAP.put(((AlertSuppressor) annotation).type(),
clazz.getName());
+ }
+ }
+ }
+ } catch (Exception e) {
+ LOG.warn("initialize detection registry error", e);
+ }
+ }
+
+ /**
+ * Look up the {@link #ALERT_SCHEME_MAP} for the Alert scheme class name
from the type
+ */
+ public String lookupAlertSchemes(String schemeType) {
+ Preconditions.checkArgument(ALERT_SCHEME_MAP.containsKey(schemeType),
schemeType + " not found in registry");
+ return ALERT_SCHEME_MAP.get(schemeType);
+ }
+
+ /**
+ * Look up the {@link #ALERT_SUPPRESSOR_MAP} for the Alert suppressor class
name from the type
+ */
+ public String lookupAlertSuppressors(String suppressorType) {
+
Preconditions.checkArgument(ALERT_SUPPRESSOR_MAP.containsKey(suppressorType),
suppressorType + " not found in registry");
+ return ALERT_SUPPRESSOR_MAP.get(suppressorType);
+ }
+}
diff --git
a/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/annotation/DetectionRegistry.java
b/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/annotation/registry/DetectionRegistry.java
similarity index 95%
rename from
thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/annotation/DetectionRegistry.java
rename to
thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/annotation/registry/DetectionRegistry.java
index 7741eb16f9..5d859b6cb5 100644
---
a/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/annotation/DetectionRegistry.java
+++
b/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/annotation/registry/DetectionRegistry.java
@@ -14,10 +14,13 @@
* limitations under the License.
*/
-package com.linkedin.thirdeye.detection.annotation;
+package com.linkedin.thirdeye.detection.annotation.registry;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
+import com.linkedin.thirdeye.detection.annotation.Components;
+import com.linkedin.thirdeye.detection.annotation.Tune;
+import com.linkedin.thirdeye.detection.annotation.Yaml;
import com.linkedin.thirdeye.detection.spi.components.BaseComponent;
import com.linkedin.thirdeye.detection.yaml.YamlDetectionConfigTranslator;
import java.lang.annotation.Annotation;
diff --git
a/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/yaml/CompositePipelineConfigTranslator.java
b/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/yaml/CompositePipelineConfigTranslator.java
index 45ecf73bd9..b33399d39e 100644
---
a/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/yaml/CompositePipelineConfigTranslator.java
+++
b/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/yaml/CompositePipelineConfigTranslator.java
@@ -13,7 +13,7 @@
import com.linkedin.thirdeye.detection.DefaultInputDataFetcher;
import com.linkedin.thirdeye.detection.InputDataFetcher;
import com.linkedin.thirdeye.detection.algorithm.DimensionWrapper;
-import com.linkedin.thirdeye.detection.annotation.DetectionRegistry;
+import com.linkedin.thirdeye.detection.annotation.registry.DetectionRegistry;
import com.linkedin.thirdeye.detection.annotation.Yaml;
import com.linkedin.thirdeye.detection.spec.AbstractSpec;
import com.linkedin.thirdeye.detection.spi.components.Tunable;
diff --git
a/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/yaml/YamlDetectionAlertConfigTranslator.java
b/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/yaml/YamlDetectionAlertConfigTranslator.java
index 65d71969d1..1caa94a683 100644
---
a/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/yaml/YamlDetectionAlertConfigTranslator.java
+++
b/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/yaml/YamlDetectionAlertConfigTranslator.java
@@ -2,7 +2,7 @@
import com.google.common.base.Preconditions;
import com.linkedin.thirdeye.datalayer.dto.DetectionAlertConfigDTO;
-import com.linkedin.thirdeye.detection.annotation.DetectionRegistry;
+import com.linkedin.thirdeye.detection.annotation.registry.DetectionRegistry;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
@@ -79,4 +79,4 @@ private void fillInProperties(Map<String, Object> properties,
Map<String, Object
}
}
}
-}
+}
\ No newline at end of file
diff --git
a/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/yaml/YamlDetectionTranslatorLoader.java
b/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/yaml/YamlDetectionTranslatorLoader.java
index 0d6b2319a6..acea6a9f8c 100644
---
a/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/yaml/YamlDetectionTranslatorLoader.java
+++
b/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/yaml/YamlDetectionTranslatorLoader.java
@@ -1,7 +1,7 @@
package com.linkedin.thirdeye.detection.yaml;
import com.linkedin.thirdeye.detection.DataProvider;
-import com.linkedin.thirdeye.detection.annotation.DetectionRegistry;
+import com.linkedin.thirdeye.detection.annotation.registry.DetectionRegistry;
import java.lang.reflect.Constructor;
import java.util.Map;
diff --git
a/thirdeye/thirdeye-pinot/src/test/java/com/linkedin/thirdeye/detection/yaml/CompositePipelineConfigTranslatorTest.java
b/thirdeye/thirdeye-pinot/src/test/java/com/linkedin/thirdeye/detection/yaml/CompositePipelineConfigTranslatorTest.java
index 3abce8b206..d57d77292a 100644
---
a/thirdeye/thirdeye-pinot/src/test/java/com/linkedin/thirdeye/detection/yaml/CompositePipelineConfigTranslatorTest.java
+++
b/thirdeye/thirdeye-pinot/src/test/java/com/linkedin/thirdeye/detection/yaml/CompositePipelineConfigTranslatorTest.java
@@ -6,7 +6,7 @@
import com.linkedin.thirdeye.datalayer.dto.MetricConfigDTO;
import com.linkedin.thirdeye.detection.DataProvider;
import com.linkedin.thirdeye.detection.MockDataProvider;
-import com.linkedin.thirdeye.detection.annotation.DetectionRegistry;
+import com.linkedin.thirdeye.detection.annotation.registry.DetectionRegistry;
import com.linkedin.thirdeye.detection.components.RuleBaselineProvider;
import com.linkedin.thirdeye.detection.components.ThresholdRuleAnomalyFilter;
import com.linkedin.thirdeye.detection.components.ThresholdRuleDetector;
diff --git
a/thirdeye/thirdeye-pinot/src/test/java/com/linkedin/thirdeye/detection/yaml/YamlDetectionAlertConfigTranslatorTest.java
b/thirdeye/thirdeye-pinot/src/test/java/com/linkedin/thirdeye/detection/yaml/YamlDetectionAlertConfigTranslatorTest.java
index a8b148b4d2..29d3ead776 100644
---
a/thirdeye/thirdeye-pinot/src/test/java/com/linkedin/thirdeye/detection/yaml/YamlDetectionAlertConfigTranslatorTest.java
+++
b/thirdeye/thirdeye-pinot/src/test/java/com/linkedin/thirdeye/detection/yaml/YamlDetectionAlertConfigTranslatorTest.java
@@ -1,8 +1,7 @@
package com.linkedin.thirdeye.detection.yaml;
import com.linkedin.thirdeye.datalayer.dto.DetectionAlertConfigDTO;
-import
com.linkedin.thirdeye.detection.alert.filter.ToAllRecipientsDetectionAlertFilter;
-import com.linkedin.thirdeye.detection.annotation.DetectionRegistry;
+import com.linkedin.thirdeye.detection.annotation.registry.DetectionRegistry;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]