This is an automated email from the ASF dual-hosted git repository.

apucher 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 213ff9c  [TE] Configure Filters per Alert in Legacy Alerter (#3572)
213ff9c is described below

commit 213ff9cf0bd5f251652b1afb4dfba7993ab3c4f4
Author: Akshay Rai <akshayra...@gmail.com>
AuthorDate: Fri Nov 30 15:54:04 2018 -0800

    [TE] Configure Filters per Alert in Legacy Alerter (#3572)
---
 .../detection/alert/filter/LegacyAlertFilter.java  | 37 +++++++++++++++-------
 .../detector/email/filter/BaseAlertFilter.java     |  2 +-
 2 files changed, 26 insertions(+), 13 deletions(-)

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 f08ddbc..56a671f 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.Map;
 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 @@ public class LegacyAlertFilter extends DetectionAlertFilter 
{
   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 class LegacyAlertFilter extends DetectionAlertFilter {
     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 class LegacyAlertFilter extends DetectionAlertFilter 
{
         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 d189679..1482b33 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 abstract class BaseAlertFilter implements AlertFilter {
       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));


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

Reply via email to