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 21b83d9 [TE] Update the formatter to handle composite alert to extract metric names (#6544) 21b83d9 is described below commit 21b83d9eaaeeca50ee29624748208de75710acd1 Author: Bryan Chen <brc...@linkedin.com> AuthorDate: Thu Feb 4 13:34:14 2021 -0800 [TE] Update the formatter to handle composite alert to extract metric names (#6544) modified the formatter to handle composite alert config in order to extract the list of metric names --- .../formatter/DetectionConfigFormatterTest.java | 20 ++++++ .../sample-detection-composite-config.yml | 74 ++++++++++++++++++++++ .../validators/DetectionConfigValidator.java | 4 +- .../formatter/DetectionConfigFormatter.java | 20 +++++- 4 files changed, 115 insertions(+), 3 deletions(-) diff --git a/thirdeye/thirdeye-dashboard/src/test/java/org/apache/pinot/thirdeye/formatter/DetectionConfigFormatterTest.java b/thirdeye/thirdeye-dashboard/src/test/java/org/apache/pinot/thirdeye/formatter/DetectionConfigFormatterTest.java index 8e12047..8a45e9b 100644 --- a/thirdeye/thirdeye-dashboard/src/test/java/org/apache/pinot/thirdeye/formatter/DetectionConfigFormatterTest.java +++ b/thirdeye/thirdeye-dashboard/src/test/java/org/apache/pinot/thirdeye/formatter/DetectionConfigFormatterTest.java @@ -75,10 +75,30 @@ public class DetectionConfigFormatterTest { Assert.assertEquals(result.get(ATTR_UPDATED_BY), configDTO.getUpdatedBy()); Assert.assertTrue(ConfigUtils.getList(result.get(ATTR_METRIC_URNS)) .containsAll(Arrays.asList("thirdeye:metric:1", "thirdeye:metric:2"))); + Assert.assertTrue(ConfigUtils.getList(result.get(ATTR_METRIC)) + .containsAll(Arrays.asList("cost"))); Assert.assertEquals(result.get(ATTR_ALERT_DETAILS_WINDOW_SIZE), TimeUnit.DAYS.toMillis(30)); Assert.assertEquals(ConfigUtils.getList(result.get(ATTR_RULES)).size(), 1); } + @Test + public void testFormatCompositeConfig() throws IOException { + DetectionConfigDTO configDTO = new DetectionConfigDTO(); + configDTO.setName("test"); + configDTO.setActive(true); + configDTO.setYaml(IOUtils.toString(Thread.currentThread().getContextClassLoader().getResourceAsStream("sample-detection-composite-config.yml"))); + configDTO.setDescription("description"); + configDTO.setCreatedBy("test"); + configDTO.setUpdatedBy("test"); + configDTO.setId(1L); + configDTO.setProperties(ImmutableMap.of("nestedMetricUrns", Collections.singleton("thirdeye:metric:1"), "nested", + Collections.singletonList(ImmutableMap.of("nestedMetricUrns", Collections.singleton("thirdeye:metric:2"))))); + DetectionConfigFormatter formatter = + new DetectionConfigFormatter(this.daoRegistry.getMetricConfigDAO(), this.daoRegistry.getDatasetConfigDAO()); + Map<String, Object> result = formatter.format(configDTO); + Assert.assertTrue(ConfigUtils.getList(result.get(ATTR_METRIC)).containsAll(Arrays.asList("metric1", "metric2", "metric3", "metric4"))); + } + @AfterMethod(alwaysRun = true) void afterClass() { testDAOProvider.cleanup(); diff --git a/thirdeye/thirdeye-dashboard/src/test/resources/sample-detection-composite-config.yml b/thirdeye/thirdeye-dashboard/src/test/resources/sample-detection-composite-config.yml new file mode 100644 index 0000000..8a4be17 --- /dev/null +++ b/thirdeye/thirdeye-dashboard/src/test/resources/sample-detection-composite-config.yml @@ -0,0 +1,74 @@ +detectionName: sample_composite_detection +description: Simple composite aert +type: COMPOSITE_ALERT +cron: "0 0 5 1/1 * ? *" +alerts: + - type: METRIC_ALERT + name: metric1 + metric: metric1 + dataset: dataset1 + rules: + - detection: + - name: detection_rule_1 + type: THRESHOLD + params: + max: 900 + min: 100 + monitoringGranularity: 1_HOURS + + - type: METRIC_ALERT + name: metric2 + metric: metric2 + dataset: dataset2 + rules: + - detection: + - name: detection_rule_2 + type: THRESHOLD + params: + max: 900 + min: 100 + monitoringGranularity: 1_HOURS + - type: COMPOSITE_ALERT + alerts: + - type: METRIC_ALERT + name: metric3 + metric: metric3 + dataset: dataset3 + rules: + - detection: + - name: detection_rule_3 + type: THRESHOLD + params: + max: 900 + min: 100 + monitoringGranularity: 1_HOURS + - type: METRIC_ALERT + name: metric4 + metric: metric4 + dataset: dataset4 + rules: + - detection: + - name: detection_rule_4 + type: THRESHOLD + params: + max: 900 + min: 100 + monitoringGranularity: 1_HOURS + grouper: + - type: GROUPER + name: grouper1 + params: + operator: OR + leftOp: + value: metric3 + rightOp: + value: metric4 +grouper: + - type : GROUPER + name: grouper2 + params: + operator: OR + leftOp: + value: metric1 + rightOp: + value: metric2 \ No newline at end of file diff --git a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/validators/DetectionConfigValidator.java b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/validators/DetectionConfigValidator.java index 9f6d9f8..49e15dc 100644 --- a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/validators/DetectionConfigValidator.java +++ b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/validators/DetectionConfigValidator.java @@ -53,9 +53,9 @@ public class DetectionConfigValidator extends ThirdEyeUserConfigValidator<Detect public static final String PROP_METRIC = "metric"; public static final String PROP_DATASET = "dataset"; public static final String PROP_RULES = "rules"; - private static final String PROP_ALERTS = "alerts"; + public static final String PROP_ALERTS = "alerts"; + public static final String PROP_TYPE = "type"; private static final String PROP_GROUPER = "grouper"; - private static final String PROP_TYPE = "type"; private static final String PROP_NAME = "name"; private static final String PROP_DETECTION_NAME = "detectionName"; diff --git a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/formatter/DetectionConfigFormatter.java b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/formatter/DetectionConfigFormatter.java index 127b8a8..6a552d0 100644 --- a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/formatter/DetectionConfigFormatter.java +++ b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/formatter/DetectionConfigFormatter.java @@ -86,6 +86,8 @@ public class DetectionConfigFormatter implements DTOFormatter<DetectionConfigDTO private static final long DEFAULT_PRESENTING_WINDOW_SIZE_DAILY = TimeUnit.DAYS.toMillis(30); private static final TimeGranularity DEFAULT_SHOW_GRANULARITY = new TimeGranularity(1, TimeUnit.DAYS); + private static final String METRIC_ALERT_TYPE = "METRIC_ALERT"; + private static final String COMPOSITE_ALERT_TYPE = "COMPOSITE_ALERT"; private static final String ALGORITHM_TYPE = "ALGORITHM"; private static final String CONFIGURATION = "configuration"; @@ -119,6 +121,7 @@ public class DetectionConfigFormatter implements DTOFormatter<DetectionConfigDTO output.put(ATTR_HEALTH, getDetectionHealth(config)); Set<String> metricUrns = extractMetricUrnsFromProperties(config.getProperties()); + Set<String> metrics = new HashSet<>(); Map<String, MetricConfigDTO> metricUrnToMetricDTOs = new HashMap<>(); for (String metricUrn : metricUrns) { @@ -140,7 +143,7 @@ public class DetectionConfigFormatter implements DTOFormatter<DetectionConfigDTO output.put(ATTR_GRANULARITY, granularities.stream().map(TimeGranularity::toAggregationGranularityString).distinct().collect(Collectors.toList())); // the default window size of the alert details page output.put(ATTR_ALERT_DETAILS_WINDOW_SIZE, getAlertDetailsDefaultWindowSize(granularities)); - output.put(ATTR_METRIC, yamlObject.get(PROP_METRIC)); + output.put(ATTR_METRIC, extractMetric(yamlObject, metrics)); output.put(ATTR_FILTERS, yamlObject.get(PROP_FILTERS)); output.put(ATTR_DIMENSION_EXPLORE, yamlObject.get(PROP_DIMENSION_EXPLORATION)); output.put(ATTR_DATASET_NAME, getDatasetDisplayNames(metricUrnToDatasets, yamlObject)); @@ -148,6 +151,21 @@ public class DetectionConfigFormatter implements DTOFormatter<DetectionConfigDTO return output; } + private Set<String> extractMetric(Map<String, Object> yamlObject, Set<String> metrics) { + if (yamlObject.get(PROP_TYPE) != null && COMPOSITE_ALERT_TYPE.equals(yamlObject.get(PROP_TYPE).toString())) { + if (yamlObject.get(PROP_ALERTS) != null) { + List<Map<String,Object>> nestedAlerts = (List<Map<String, Object>>) yamlObject.get(PROP_ALERTS); + nestedAlerts.forEach(alert -> extractMetric(alert, metrics)); + return metrics; + } else { + throw new RuntimeException("Invalid alert config: composite alert without the alerts clause."); + } + } else { + metrics.add(yamlObject.get(PROP_METRIC).toString()); + return metrics; + } + } + /** * Extract the list of metric urns in the detection config properties * @param properties the detection config properties --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org