You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by ji...@apache.org on 2019/02/26 01:38:33 UTC

[incubator-pinot] branch master updated: [TE] Migration - fill in metric urn for old anomalies (#3880)

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 4e7ffb3  [TE] Migration - fill in metric urn for old anomalies (#3880)
4e7ffb3 is described below

commit 4e7ffb31c1261aed5201c33b09c2429f0035cb43
Author: Jihao Zhang <ji...@linkedin.com>
AuthorDate: Mon Feb 25 17:38:25 2019 -0800

    [TE] Migration - fill in metric urn for old anomalies (#3880)
    
    Fill in the metric urn for old anomalies in migration to keep the dimension information.
---
 .../detection/DetectionMigrationResource.java       | 21 ++++++++++++++++++++-
 .../detection/DetectionMigrationResourceTest.java   |  4 ++++
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/DetectionMigrationResource.java b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/DetectionMigrationResource.java
index 3a585f2..beadf8d 100644
--- a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/DetectionMigrationResource.java
+++ b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/DetectionMigrationResource.java
@@ -20,7 +20,9 @@
 package org.apache.pinot.thirdeye.detection;
 
 import com.google.common.base.Preconditions;
+import com.google.common.collect.ArrayListMultimap;
 import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Multimap;
 import com.wordnik.swagger.annotations.Api;
 import com.wordnik.swagger.annotations.ApiOperation;
 import java.util.ArrayList;
@@ -45,6 +47,7 @@ import javax.xml.bind.ValidationException;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.pinot.thirdeye.anomaly.detection.AnomalyDetectionInputContextBuilder;
 import org.apache.pinot.thirdeye.api.Constants;
+import org.apache.pinot.thirdeye.common.dimension.DimensionMap;
 import org.apache.pinot.thirdeye.datalayer.bao.AlertConfigManager;
 import org.apache.pinot.thirdeye.datalayer.bao.AnomalyFunctionManager;
 import org.apache.pinot.thirdeye.datalayer.bao.ApplicationManager;
@@ -65,8 +68,8 @@ import org.apache.pinot.thirdeye.datalayer.util.Predicate;
 import org.apache.pinot.thirdeye.detection.alert.filter.ToAllRecipientsDetectionAlertFilter;
 import org.apache.pinot.thirdeye.detection.yaml.YamlDetectionAlertConfigTranslator;
 import org.apache.pinot.thirdeye.detection.yaml.YamlResource;
+import org.apache.pinot.thirdeye.rootcause.impl.MetricEntity;
 import org.joda.time.Period;
-import org.omg.CORBA.OBJ_ADAPTER;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.yaml.snakeyaml.DumperOptions;
@@ -364,6 +367,7 @@ public class DetectionMigrationResource {
       if (anomaly.getProperties() != null) {
         anomaly.getProperties().remove("anomalyTimelinesView");
       }
+      anomaly.setMetricUrn(buildMetricUrn(anomaly));
       anomaly.setDetectionConfigId(detectionConfig.getId());
       int affectedRows = mergedAnomalyResultDAO.update(anomaly);
       if (affectedRows == 0) {
@@ -387,6 +391,21 @@ public class DetectionMigrationResource {
     return detectionConfig.getId();
   }
 
+  private String buildMetricUrn(MergedAnomalyResultDTO anomaly) {
+    try {
+      DimensionMap dimensionMap = anomaly.getDimensions();
+      Multimap<String, String> filters = ArrayListMultimap.create();
+      for (DimensionMap.Entry<String, String> entry : dimensionMap.entrySet()) {
+        filters.put(entry.getKey(), entry.getValue());
+      }
+      MetricEntity me = MetricEntity.fromMetric(1.0, metricConfigDAO.findByMetricAndDataset(anomaly.getMetric(), anomaly.getCollection()).getId(), filters);
+      return me.getUrn();
+    } catch (Exception e) {
+      throw new RuntimeException("Resolve metric urn failed for anomaly " + anomaly.getId(), e);
+    }
+  }
+
+
   private void migrateLegacyNotification(AlertConfigDTO alertConfigDTO) {
     int anomalyFailureCount = 0;
     int anomalyWarningCount = 0;
diff --git a/thirdeye/thirdeye-pinot/src/test/java/org/apache/pinot/thirdeye/detection/DetectionMigrationResourceTest.java b/thirdeye/thirdeye-pinot/src/test/java/org/apache/pinot/thirdeye/detection/DetectionMigrationResourceTest.java
index 5a9c0b3..4b796ed 100644
--- a/thirdeye/thirdeye-pinot/src/test/java/org/apache/pinot/thirdeye/detection/DetectionMigrationResourceTest.java
+++ b/thirdeye/thirdeye-pinot/src/test/java/org/apache/pinot/thirdeye/detection/DetectionMigrationResourceTest.java
@@ -181,6 +181,8 @@ public class DetectionMigrationResourceTest {
 
     MergedAnomalyResultDTO mergedAnomalyResultDTO = new MergedAnomalyResultDTO();
     mergedAnomalyResultDTO.setFunction(actual);
+    mergedAnomalyResultDTO.setMetric("test_metric");
+    mergedAnomalyResultDTO.setCollection("test_collection");
     anomalyDAO.save(mergedAnomalyResultDTO);
 
     Response responseId = migrationResource.migrateAnomalyFunction(oldID);
@@ -216,6 +218,8 @@ public class DetectionMigrationResourceTest {
 
     MergedAnomalyResultDTO mergedAnomalyResultDTO = new MergedAnomalyResultDTO();
     mergedAnomalyResultDTO.setFunction(actual);
+    mergedAnomalyResultDTO.setMetric("test_metric");
+    mergedAnomalyResultDTO.setCollection("test_collection");
     anomalyDAO.save(mergedAnomalyResultDTO);
 
     Response responseId = migrationResource.migrateAnomalyFunction(oldID);


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org