[TE] Include admin recipients in every email alert (cc address)
package org.apache.pinot.thirdeye.detection.alert.scheme;
import com.google.common.base.Preconditions;
+import java.util.HashSet;
import org.apache.pinot.thirdeye.alert.commons.EmailContentFormatterFactory;
import org.apache.pinot.thirdeye.alert.commons.EmailEntity;
import org.apache.pinot.thirdeye.alert.content.EmailContentFormatter;
@@ -62,7 +63,10 @@ public class DetectionEmailAlerter extends DetectionAlertScheme {
private static final Comparator<AnomalyResult> COMPARATOR_DESC =
(o1, o2) -> -1 * Long.compare(o1.getStartTime(), o2.getStartTime());
- private static final String EMAIL_WHITELIST_KEY = "emailWhitelist";
+
+ private static final String PROP_EMAIL_WHITELIST = "emailWhitelist";
+ private static final String PROP_ADMIN_RECIPIENTS = "adminRecipients";
+
private static final String PROP_EMAIL_SCHEME = "emailScheme";
private static final String PROP_EMAIL_TEMPLATE = "template";
private static final String PROP_EMAIL_SUBJECT_STYLE = "subject";
@@ -86,7 +90,7 @@ public class DetectionEmailAlerter extends DetectionAlertScheme {
private void whitelistRecipients(DetectionAlertFilterRecipients recipients) {
if (recipients != null) {
List<String> emailWhitelist = ConfigUtils.getList(
- this.teConfig.getAlerterConfiguration().get(SMTP_CONFIG_KEY).get(EMAIL_WHITELIST_KEY));
+ this.teConfig.getAlerterConfiguration().get(SMTP_CONFIG_KEY).get(PROP_EMAIL_WHITELIST));
if (!emailWhitelist.isEmpty()) {
recipients.setTo(retainWhitelisted(recipients.getTo(), emailWhitelist));
recipients.setCc(retainWhitelisted(recipients.getCc(), emailWhitelist));
@@ -198,15 +202,15 @@ public class DetectionEmailAlerter extends DetectionAlertScheme {
new EmailContentFormatterContext());
HtmlEmail email = emailEntity.getContent();
+ email.setSubject(emailEntity.getSubject());
email.setFrom(this.config.getFrom());
email.setTo(AlertUtils.toAddress(recipients.getTo()));
- email.setSubject(emailEntity.getSubject());
- if (CollectionUtils.isNotEmpty(recipients.getCc())) {
- email.setCc(AlertUtils.toAddress(recipients.getCc()));
+ if (recipients.getCc() == null) {
+ recipients.setCc(new HashSet<>());
}
- if (CollectionUtils.isNotEmpty(recipients.getBcc())) {
+ recipients.getCc().addAll(ConfigUtils.getList(this.teConfig.getAlerterConfiguration().get(PROP_ADMIN_RECIPIENTS)));
+ email.setCc(AlertUtils.toAddress(recipients.getCc()));
email.setBcc(AlertUtils.toAddress(recipients.getBcc()));
- }
sendEmail(emailEntity);
}
