You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by ap...@apache.org on 2018/11/29 19:25:28 UTC
[incubator-pinot] branch master updated: [TE] Legacy Alert Filter
should pick recipients from new alerter configs (#3565)
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 eceaf76 [TE] Legacy Alert Filter should pick recipients from new alerter configs (#3565)
eceaf76 is described below
commit eceaf76b0b3f896cee0f6035147b16bb82e93bb3
Author: Akshay Rai <ak...@gmail.com>
AuthorDate: Thu Nov 29 11:25:23 2018 -0800
[TE] Legacy Alert Filter should pick recipients from new alerter configs (#3565)
---
.../thirdeye/detection/DefaultDataProvider.java | 2 +-
.../detection/alert/filter/LegacyAlertFilter.java | 24 ++++++++++-------
.../alert/filter/LegacyAlertFilterTest.java | 31 ++++++++++------------
3 files changed, 30 insertions(+), 27 deletions(-)
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 a13138d..f600c44 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 class DefaultDataProvider implements DataProvider {
);
}
- 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 488f1f2..f08ddbc 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.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;
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.Collections;
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 class LegacyAlertFilter extends DetectionAlertFilter {
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 class LegacyAlertFilter extends DetectionAlertFilter {
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 class LegacyAlertFilter extends DetectionAlertFilter {
}
});
- 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 6cff774..166e834 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.DetectionAlertConfigDTO;
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.HashMap;
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 @@ public class LegacyAlertFilterTest {
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 = "test@example.com,mytest@example.org";
- private static final String CC_RECIPIENTS_VALUES = "iamcc@host.domain,iamcc2@host.domain";
- private static final String BCC_RECIPIENTS_VALUES = "iambcc@host.domain";
-
- 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("test@example.com", "mytest@example.org"));
+ private static final Set<String> CC_RECIPIENTS_VALUES = new HashSet<>(Arrays.asList("iamcc@host.domain", "iamcc2@host.domain"));
+ private static final Set<String> BCC_RECIPIENTS_VALUES = new HashSet<>(Arrays.asList("iambcc@host.domain"));
+ 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 class LegacyAlertFilterTest {
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 @@ public class LegacyAlertFilterTest {
@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)));
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org