This is an automated email from the ASF dual-hosted git repository.
jihao 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 e23f953 [TE] Alerts created by YAML to show up in the alert list
(#3551)
e23f953 is described below
commit e23f953cebcae4f04055abe26374bc3505ad2346
Author: Jihao Zhang <[email protected]>
AuthorDate: Mon Nov 26 17:37:00 2018 -0800
[TE] Alerts created by YAML to show up in the alert list (#3551)
The alerts created by YAML editor to show up in the alert list.
---
.../app/mirage/endpoints/selfserve.js | 14 +++++
.../app/pods/manage/alerts/index/route.js | 64 +++++++++++++++++++++-
.../thirdeye/detection/yaml/YamlResource.java | 36 +++++++++++-
3 files changed, 110 insertions(+), 4 deletions(-)
diff --git a/thirdeye/thirdeye-frontend/app/mirage/endpoints/selfserve.js
b/thirdeye/thirdeye-frontend/app/mirage/endpoints/selfserve.js
index 71686b6..957237a 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 cac8f9e..d5c036a 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) : [];
@@ -147,6 +178,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
* @param {String} user - current logged in user's email alias
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 3ab02aa..56c01b2 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.DataProvider;
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.List;
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 @@ public class YamlResource {
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 class YamlResource {
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 @@ public class YamlResource {
}
}
}
+
+ /**
+ 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;
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]