jihaozh closed pull request #3551: [TE] Alerts created by YAML to show up in
the alert list
URL: https://github.com/apache/incubator-pinot/pull/3551
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-frontend/app/mirage/endpoints/selfserve.js
b/thirdeye/thirdeye-frontend/app/mirage/endpoints/selfserve.js
index 71686b6d71..957237a8aa 100644
--- a/thirdeye/thirdeye-frontend/app/mirage/endpoints/selfserve.js
+++ b/thirdeye/thirdeye-frontend/app/mirage/endpoints/selfserve.js
@@ -206,4 +206,18 @@ export default function (server) {
const idArray = request.queryParams.anomalyIds ?
request.queryParams.anomalyIds : [ 38456269 ];
return anomalySet(idArray.split(','));
});
+
+ /**
+ * get request for all detection alerters
+ */
+ server.get('/thirdeye/entity/DETECTION_ALERT_CONFIG', () => {
+ return [];
+ });
+
+ /**
+ * get request for list yaml configs
+ */
+ server.get('/yaml/list', () => {
+ return [];
+ })
}
diff --git a/thirdeye/thirdeye-frontend/app/pods/manage/alerts/index/route.js
b/thirdeye/thirdeye-frontend/app/pods/manage/alerts/index/route.js
index cac8f9e0b8..d5c036a1d9 100644
--- a/thirdeye/thirdeye-frontend/app/pods/manage/alerts/index/route.js
+++ b/thirdeye/thirdeye-frontend/app/pods/manage/alerts/index/route.js
@@ -26,14 +26,16 @@ export default Route.extend({
return hash({
rawAlerts: fetch('/thirdeye/entity/ANOMALY_FUNCTION').then(checkStatus),
subscriberGroups:
fetch('/thirdeye/entity/ALERT_CONFIG').then(checkStatus),
- applications: fetch('/thirdeye/entity/APPLICATION').then(checkStatus)
+ applications: fetch('/thirdeye/entity/APPLICATION').then(checkStatus),
+ detectionAlertConfig:
fetch('/thirdeye/entity/DETECTION_ALERT_CONFIG').then(checkStatus),
+ detectionYaml: fetch('/yaml/list').then(checkStatus)
});
},
afterModel(model) {
this._super(model);
// Work only with valid alerts - with metric association
- const alerts = model.rawAlerts.filter(alert => isPresent(alert.metric));
+ let alerts = model.rawAlerts.filter(alert => isPresent(alert.metric));
// Itereate through config groups to enhance all alerts with extra
properties (group name, application)
for (let config of model.subscriberGroups) {
@@ -49,6 +51,35 @@ export default Route.extend({
}
}
+ // format Yaml configs
+ const yamlAlerts = model.detectionYaml;
+ for (let yamlAlert of yamlAlerts) {
+ Object.assign(yamlAlert, {
+ functionName: yamlAlert.detectionName,
+ collection: yamlAlert.dataset,
+ type: yamlAlert.pipelineType,
+ exploreDimensions: yamlAlert.dimensions,
+ filters: this._formatYamlFilter(yamlAlert.filters)
+ });
+ }
+
+ // Itereate through detection alerter to enhance all yaml alert with extra
properties (group name, application)
+ for (let detectionAlert of model.detectionAlertConfig){
+ const detectionConfigIds = Object.keys(detectionAlert.vectorClocks);
+ for (let id of detectionConfigIds) {
+ let foundAlert = yamlAlerts.find(yamlAlert => yamlAlert.id.toString()
=== id);
+ if (foundAlert) {
+ Object.assign(foundAlert, {
+ application: detectionAlert.application,
+ group: detectionAlert.name
+ });
+ }
+ }
+ }
+
+ // concat legacy alerts and yaml alerts
+ alerts = alerts.concat(yamlAlerts);
+
// Perform initial filters for our 'primary' filter types and add counts
const user = getWithDefault(get(this, 'session'),
'data.authenticated.name', null);
const myAlertIds = user ? this._findAlertIdsByUserGroup(user,
model.subscriberGroups) : [];
@@ -146,6 +177,35 @@ export default Route.extend({
});
},
+ /**
+ * The yaml filters formatter. Convert filters in the yaml file in to a
legacy filters string
+ * For example, filters = {
+ * "country": ["us", "cn"],
+ * "browser": ["chrome"]
+ * }
+ * will be convert into "country=us;country=cn;browser=chrome"
+ *
+ * @method _formatYamlFilter
+ * @param {Map} filters multimap of filters
+ * @return {String} - formatted filters string
+ */
+ _formatYamlFilter(filters) {
+ if (filters){
+ const filterStrings = [];
+ Object.keys(filters).forEach(
+ function(filterKey) {
+ filters[filterKey].forEach(
+ function (filterValue) {
+ filterStrings.push(filterKey + "=" + filterValue);
+ }
+ );
+ }
+ );
+ return filterStrings.join(";");
+ }
+ return "";
+ },
+
/**
* A local helper to find "Alerts I subscribe to"
* @method _findAlertIdsByUserGroup
diff --git
a/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/yaml/YamlResource.java
b/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/yaml/YamlResource.java
index 3ab02aa56e..56c01b2557 100644
---
a/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/yaml/YamlResource.java
+++
b/thirdeye/thirdeye-pinot/src/main/java/com/linkedin/thirdeye/detection/yaml/YamlResource.java
@@ -23,6 +23,7 @@
import com.linkedin.thirdeye.detection.DefaultDataProvider;
import com.linkedin.thirdeye.detection.DetectionPipelineLoader;
import com.wordnik.swagger.annotations.ApiParam;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
@@ -30,6 +31,7 @@
import java.util.Map;
import java.util.Set;
import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
@@ -50,7 +52,7 @@
private static final String PROP_TYPE = "type";
private static final String PROP_DETECTION_CONFIG_ID = "detectionConfigIds";
- private static final Yaml YAML_READER = new Yaml();
+ private static final Yaml YAML = new Yaml();
private final DetectionConfigManager detectionConfigDAO;
private final DetectionAlertConfigManager detectionAlertConfigDAO;
@@ -98,7 +100,7 @@ public Response setUpDetectionPipeline(@ApiParam("payload")
String payload,
if (Strings.isNullOrEmpty(payload)) {
throw new IllegalArgumentException("Empty Payload");
}
- Map<String, Object> yamlConfig = (Map<String, Object>)
this.YAML_READER.load(payload);
+ Map<String, Object> yamlConfig = (Map<String, Object>)
this.YAML.load(payload);
Preconditions.checkArgument(yamlConfig.containsKey(PROP_NAME), "missing "
+ PROP_NAME);
// retrieve id if detection config already exists
@@ -172,4 +174,34 @@ private DetectionAlertConfigDTO
getDetectionAlertConfig(Map<String, Object> aler
}
}
}
+
+ /**
+ List all yaml configurations enhanced with detection config id, isActive
and createBy information.
+ @param id id of a specific detection config yaml to list (optional)
+ @return the yaml configuration converted in to JSON, with enhanced
information from detection config DTO.
+ */
+ @GET
+ @Path("/list")
+ @Produces(MediaType.APPLICATION_JSON)
+ public List<Object> listYamls(@QueryParam("id") Long id){
+ List<DetectionConfigDTO> detectionConfigDTOs;
+ if (id == null) {
+ detectionConfigDTOs = this.detectionConfigDAO.findAll();
+ } else {
+ detectionConfigDTOs =
Collections.singletonList(this.detectionConfigDAO.findById(id));
+ }
+
+ List<Object> yamlObjects = new ArrayList<>();
+ for (DetectionConfigDTO detectionConfigDTO : detectionConfigDTOs) {
+ if (detectionConfigDTO.getYaml() != null) {
+ Map<String, Object> yamlObject = new HashMap<>();
+ yamlObject.putAll((Map<? extends String, ?>)
this.YAML.load(detectionConfigDTO.getYaml()));
+ yamlObject.put("id", detectionConfigDTO.getId());
+ yamlObject.put("isActive", detectionConfigDTO.isActive());
+ yamlObject.put("createdBy", detectionConfigDTO.getCreatedBy());
+ yamlObjects.add(yamlObject);
+ }
+ }
+ return yamlObjects;
+ }
}
----------------------------------------------------------------
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]