apucher closed pull request #3572: [TE] Configure filters per function in
Legacy Alerter
URL: https://github.com/apache/incubator-pinot/pull/3572
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/detection/alert/filter/LegacyAlertFilter.java
b/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/alert/filter/LegacyAlertFilter.java
index f08ddbc709..56a671f5ac 100644
---
a/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/alert/filter/LegacyAlertFilter.java
+++
b/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/alert/filter/LegacyAlertFilter.java
@@ -16,10 +16,8 @@
package com.linkedin.thirdeye.detection.alert.filter;
-import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
-import com.linkedin.thirdeye.datalayer.dto.AlertConfigDTO;
import com.linkedin.thirdeye.datalayer.dto.DetectionAlertConfigDTO;
import com.linkedin.thirdeye.datalayer.dto.MergedAnomalyResultDTO;
import com.linkedin.thirdeye.detection.alert.DetectionAlertFilterRecipients;
@@ -38,10 +36,14 @@
import java.util.Set;
import javax.annotation.Nullable;
import org.apache.commons.collections.MapUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class LegacyAlertFilter extends DetectionAlertFilter {
- private static final String PROP_LEGACY_ALERT_FILTER_CONFIG =
"legacyAlertFilterConfig";
+ private final static Logger LOG =
LoggerFactory.getLogger(LegacyAlertFilter.class);
+
+ private static final String PROP_LEGACY_ALERT_FILTER_CONFIGS =
"legacyAlertFilterConfigs";
private static final String PROP_LEGACY_ALERT_FILTER_CLASS_NAME =
"legacyAlertFilterClassName";
private static final String PROP_DETECTION_CONFIG_IDS = "detectionConfigIds";
private static final String PROP_RECIPIENTS = "recipients";
@@ -49,25 +51,18 @@
private static final String PROP_CC = "cc";
private static final String PROP_BCC = "bcc";
- private BaseAlertFilter alertFilter;
private final List<Long> detectionConfigIds;
private final Map<Long, Long> vectorClocks;
public LegacyAlertFilter(DataProvider provider, DetectionAlertConfigDTO
config, long endTime) throws Exception {
super(provider, config, endTime);
- alertFilter = new DummyAlertFilter();
- if
(config.getProperties().containsKey(PROP_LEGACY_ALERT_FILTER_CLASS_NAME)) {
- String className = MapUtils.getString(config.getProperties(),
PROP_LEGACY_ALERT_FILTER_CLASS_NAME);
- alertFilter = (BaseAlertFilter) Class.forName(className).newInstance();
- alertFilter.setParameters(MapUtils.getMap(config.getProperties(),
PROP_LEGACY_ALERT_FILTER_CONFIG));
- }
this.detectionConfigIds =
ConfigUtils.getLongs(this.config.getProperties().get(PROP_DETECTION_CONFIG_IDS));
this.vectorClocks = this.config.getVectorClocks();
}
@Override
- public DetectionAlertFilterResult run() {
+ public DetectionAlertFilterResult run() throws Exception {
DetectionAlertFilterResult result = new DetectionAlertFilterResult();
Map<String, Set<String>> recipientsMap =
ConfigUtils.getMap(this.config.getProperties().get(PROP_RECIPIENTS));
@@ -76,6 +71,11 @@ public DetectionAlertFilterResult run() {
Set<String> bcc = (recipientsMap.get(PROP_BCC) == null) ?
Collections.emptySet() : new HashSet<>(recipientsMap.get(PROP_BCC));
DetectionAlertFilterRecipients recipients = new
DetectionAlertFilterRecipients(to, cc, bcc);
+ Map<String, Object> alertFilterConfig =
MapUtils.getMap(config.getProperties(), PROP_LEGACY_ALERT_FILTER_CONFIGS);
+ if (alertFilterConfig == null) {
+ LOG.info("alertFilterConfig cannot be found in notification group {}",
this.config.getId());
+ }
+
for (Long functionId : this.detectionConfigIds) {
long startTime = MapUtils.getLong(this.vectorClocks, functionId, 0L);
@@ -90,11 +90,24 @@ public DetectionAlertFilterResult run() {
candidates =
this.provider.fetchAnomalies(Collections.singletonList(slice),
functionId).get(slice);
}
+ BaseAlertFilter alertFilter = new DummyAlertFilter();
+ if
(config.getProperties().containsKey(PROP_LEGACY_ALERT_FILTER_CLASS_NAME)) {
+ String className = MapUtils.getString(config.getProperties(),
PROP_LEGACY_ALERT_FILTER_CLASS_NAME);
+ alertFilter = (BaseAlertFilter) Class.forName(className).newInstance();
+ Map<String, String> params = MapUtils.getMap(alertFilterConfig,
functionId);
+ if (params == null) {
+ LOG.info("AlertFilter cannot be found for function {} in
notification group {}", functionId, this.config.getId());
+ }
+
+ alertFilter.setParameters(params);
+ }
+
+ BaseAlertFilter finalAlertFilter = alertFilter;
Collection<MergedAnomalyResultDTO> anomalies =
Collections2.filter(candidates, new
Predicate<MergedAnomalyResultDTO>() {
@Override
public boolean apply(@Nullable MergedAnomalyResultDTO
mergedAnomaly) {
- return mergedAnomaly != null && !mergedAnomaly.isChild() &&
alertFilter.isQualified(mergedAnomaly);
+ return mergedAnomaly != null && !mergedAnomaly.isChild() &&
finalAlertFilter.isQualified(mergedAnomaly);
}
});
diff --git
a/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detector/email/filter/BaseAlertFilter.java
b/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detector/email/filter/BaseAlertFilter.java
index d1896793f4..1482b33169 100644
---
a/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detector/email/filter/BaseAlertFilter.java
+++
b/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detector/email/filter/BaseAlertFilter.java
@@ -46,7 +46,7 @@ public void setParameters(Map<String, String>
parameterSetting) {
Double value = null;
String fieldVal = null;
// Get user's value for the specified field
- if (parameterSetting.containsKey(fieldName)) {
+ if (parameterSetting != null && parameterSetting.containsKey(fieldName))
{
fieldVal = parameterSetting.get(fieldName);
if (NumberUtils.isNumber(fieldVal)) {
value = Double.parseDouble(parameterSetting.get(fieldName));
----------------------------------------------------------------
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]