apucher closed pull request #3565: [TE] Legacy Alert Filter should pick 
recipients from new alerter configs
URL: https://github.com/apache/incubator-pinot/pull/3565
 
 
   

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/DefaultDataProvider.java
 
b/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/DefaultDataProvider.java
index a13138d486..f600c44212 100644
--- 
a/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/DefaultDataProvider.java
+++ 
b/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/DefaultDataProvider.java
@@ -161,7 +161,7 @@ public DataFrame call() throws Exception {
         );
       }
 
-      LOG.info("Fetched {} legacy anomalies between (startTime = {}, endTime = 
{}) with confid Id = {}", anomalies.size(),
+      LOG.info("Fetched {} anomalies between (startTime = {}, endTime = {}) 
with confid Id = {}", anomalies.size(),
           slice.getStart(), slice.getEnd(), configId);
       output.putAll(slice, anomalies);
     }
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 488f1f2748..f08ddbc709 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
@@ -22,6 +22,7 @@
 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;
 import com.linkedin.thirdeye.detection.spi.model.AnomalySlice;
 import com.linkedin.thirdeye.detection.ConfigUtils;
 import com.linkedin.thirdeye.detection.DataProvider;
@@ -34,19 +35,20 @@
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import javax.annotation.Nullable;
 import org.apache.commons.collections.MapUtils;
 
 
 public class LegacyAlertFilter extends DetectionAlertFilter {
   private static final String PROP_LEGACY_ALERT_FILTER_CONFIG = 
"legacyAlertFilterConfig";
-  private static final String PROP_LEGACY_ALERT_CONFIG = "legacyAlertConfig";
   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";
+  private static final String PROP_TO = "to";
+  private static final String PROP_CC = "cc";
+  private static final String PROP_BCC = "bcc";
 
-  private static ObjectMapper OBJECT_MAPPER = new ObjectMapper();
-
-  private AlertConfigDTO alertConfig;
   private BaseAlertFilter alertFilter;
   private final List<Long> detectionConfigIds;
   private final Map<Long, Long> vectorClocks;
@@ -54,8 +56,6 @@
   public LegacyAlertFilter(DataProvider provider, DetectionAlertConfigDTO 
config, long endTime) throws Exception {
     super(provider, config, endTime);
 
-    String alertConfigStr = 
OBJECT_MAPPER.writeValueAsString(MapUtils.getMap(config.getProperties(), 
PROP_LEGACY_ALERT_CONFIG));
-    alertConfig = OBJECT_MAPPER.readValue(alertConfigStr, 
AlertConfigDTO.class);
     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);
@@ -70,6 +70,12 @@ public LegacyAlertFilter(DataProvider provider, 
DetectionAlertConfigDTO config,
   public DetectionAlertFilterResult run() {
     DetectionAlertFilterResult result = new DetectionAlertFilterResult();
 
+    Map<String, Set<String>> recipientsMap = 
ConfigUtils.getMap(this.config.getProperties().get(PROP_RECIPIENTS));
+    Set<String> to = (recipientsMap.get(PROP_TO) == null) ? 
Collections.emptySet() : new HashSet<>(recipientsMap.get(PROP_TO));
+    Set<String> cc = (recipientsMap.get(PROP_CC) == null) ? 
Collections.emptySet() : new HashSet<>(recipientsMap.get(PROP_CC));
+    Set<String> bcc = (recipientsMap.get(PROP_BCC) == null) ? 
Collections.emptySet() : new HashSet<>(recipientsMap.get(PROP_BCC));
+    DetectionAlertFilterRecipients recipients = new 
DetectionAlertFilterRecipients(to, cc, bcc);
+
     for (Long functionId : this.detectionConfigIds) {
       long startTime = MapUtils.getLong(this.vectorClocks, functionId, 0L);
 
@@ -92,10 +98,10 @@ public boolean apply(@Nullable MergedAnomalyResultDTO 
mergedAnomaly) {
             }
           });
 
-      if (result.getResult().get(this.alertConfig.getReceiverAddresses()) == 
null) {
-        result.addMapping(this.alertConfig.getReceiverAddresses(), new 
HashSet<>(anomalies));
+      if (result.getResult().isEmpty()) {
+        result.addMapping(recipients, new HashSet<>(anomalies));
       } else {
-        
result.getResult().get(this.alertConfig.getReceiverAddresses()).addAll(anomalies);
+        result.getResult().get(recipients).addAll(anomalies);
       }
     }
 
diff --git 
a/thirdeye/thirdeye-pinot/src/test/java/com/linkedin/thirdeye/detection/alert/filter/LegacyAlertFilterTest.java
 
b/thirdeye/thirdeye-pinot/src/test/java/com/linkedin/thirdeye/detection/alert/filter/LegacyAlertFilterTest.java
index 6cff774ca9..166e83432d 100644
--- 
a/thirdeye/thirdeye-pinot/src/test/java/com/linkedin/thirdeye/detection/alert/filter/LegacyAlertFilterTest.java
+++ 
b/thirdeye/thirdeye-pinot/src/test/java/com/linkedin/thirdeye/detection/alert/filter/LegacyAlertFilterTest.java
@@ -20,7 +20,6 @@
 import com.linkedin.thirdeye.datalayer.dto.MergedAnomalyResultDTO;
 import com.linkedin.thirdeye.detection.DataProvider;
 import com.linkedin.thirdeye.detection.MockDataProvider;
-import com.linkedin.thirdeye.detection.alert.DetectionAlertFilterRecipients;
 import com.linkedin.thirdeye.detection.alert.DetectionAlertFilterResult;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -28,6 +27,7 @@
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import org.testng.Assert;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
@@ -39,20 +39,16 @@
   private static final String PROP_DETECTION_CONFIG_IDS = "detectionConfigIds";
   private static final List<Long> PROP_ID_VALUE = Arrays.asList(1001L, 1002L);
   private static final String PROP_LEGACY_ALERT_FILTER_CONFIG = 
"legacyAlertFilterConfig";
-  private static final String PROP_LEGACY_ALERT_CONFIG = "legacyAlertConfig";
   private static final String PROP_LEGACY_ALERT_FILTER_CLASS_NAME = 
"legacyAlertFilterClassName";
-  private static final String TO_RECIPIENTS_VALUES = 
"[email protected],[email protected]";
-  private static final String CC_RECIPIENTS_VALUES = 
"[email protected],[email protected]";
-  private static final String BCC_RECIPIENTS_VALUES = "[email protected]";
-
-  private static final DetectionAlertFilterRecipients RECEIVER_ADDRESSES = new 
DetectionAlertFilterRecipients(
-      new HashSet<>(Arrays.asList(TO_RECIPIENTS_VALUES)),
-      new HashSet<>(Arrays.asList(CC_RECIPIENTS_VALUES)),
-      new HashSet<>(Arrays.asList(BCC_RECIPIENTS_VALUES)));
+  private static final Set<String> TO_RECIPIENTS_VALUES = new 
HashSet<>(Arrays.asList("[email protected]", "[email protected]"));
+  private static final Set<String> CC_RECIPIENTS_VALUES = new 
HashSet<>(Arrays.asList("[email protected]", "[email protected]"));
+  private static final Set<String> BCC_RECIPIENTS_VALUES = new 
HashSet<>(Arrays.asList("[email protected]"));
+  private static final String PROP_RECIPIENTS = "recipients";
 
   private List<MergedAnomalyResultDTO> detectedAnomalies;
   private LegacyAlertFilter legacyAlertFilter;
   private LegacyAlertFilter legacyAlertFilterOnLegacyAnomalies;
+  private Map<String, Set<String>> recipientsMap;
 
   @BeforeMethod
   public void beforeMethod() throws Exception {
@@ -78,17 +74,20 @@ public void beforeMethod() throws Exception {
     DetectionAlertConfigDTO detectionAlertConfigLegacyAnomalies = 
createDetectionAlertConfig();
     detectionAlertConfigLegacyAnomalies.setOnlyFetchLegacyAnomalies(true);
     this.legacyAlertFilterOnLegacyAnomalies = new 
LegacyAlertFilter(mockDataProvider, detectionAlertConfigLegacyAnomalies, 2500L);
+
+    this.recipientsMap = new HashMap<>();
+    recipientsMap.put("to", TO_RECIPIENTS_VALUES);
+    recipientsMap.put("cc", CC_RECIPIENTS_VALUES);
+    recipientsMap.put("bcc", BCC_RECIPIENTS_VALUES);
   }
 
   private DetectionAlertConfigDTO createDetectionAlertConfig() {
     DetectionAlertConfigDTO detectionAlertConfig = new 
DetectionAlertConfigDTO();
     Map<String, Object> properties = new HashMap<>();
     properties.put(PROP_DETECTION_CONFIG_IDS, PROP_ID_VALUE);
-    Map<String, Object> alertConfig = new HashMap<>();
-    alertConfig.put("receiverAddresses", RECEIVER_ADDRESSES);
-    properties.put(PROP_LEGACY_ALERT_CONFIG, alertConfig);
     properties.put(PROP_LEGACY_ALERT_FILTER_CLASS_NAME, 
"com.linkedin.thirdeye.detector.email.filter.DummyAlertFilter");
     properties.put(PROP_LEGACY_ALERT_FILTER_CONFIG, "");
+    properties.put(PROP_RECIPIENTS, recipientsMap);
     detectionAlertConfig.setProperties(properties);
     detectionAlertConfig.setVectorClocks(new HashMap<Long, Long>());
 
@@ -98,15 +97,13 @@ private DetectionAlertConfigDTO 
createDetectionAlertConfig() {
   @Test
   public void testRun() throws Exception {
     DetectionAlertFilterResult result = this.legacyAlertFilter.run();
-    Assert.assertEquals(result.getResult().get(RECEIVER_ADDRESSES),
-        new HashSet<>(this.detectedAnomalies.subList(0, 4)));
+    Assert.assertEquals(result.getAllAnomalies(), new 
HashSet<>(this.detectedAnomalies.subList(0, 4)));
   }
 
   @Test
   public void testFetchingLegacyAnomalies() throws Exception {
     DetectionAlertFilterResult result = 
this.legacyAlertFilterOnLegacyAnomalies.run();
     Assert.assertEquals(result.getAllAnomalies().size(), 2);
-    Assert.assertEquals(result.getResult().get(RECEIVER_ADDRESSES),
-        new HashSet<>(this.detectedAnomalies.subList(7, 9)));
+    Assert.assertEquals(result.getAllAnomalies(), new 
HashSet<>(this.detectedAnomalies.subList(7, 9)));
   }
 }


 

----------------------------------------------------------------
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]

Reply via email to