You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pinot.apache.org by GitBox <gi...@apache.org> on 2019/01/22 19:48:32 UTC

[GitHub] akshayrai commented on a change in pull request #3724: [TE] Migration endpoints for anomaly function and application

akshayrai commented on a change in pull request #3724: [TE] Migration endpoints for anomaly function and application
URL: https://github.com/apache/incubator-pinot/pull/3724#discussion_r249934668
 
 

 ##########
 File path: thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/DetectionMigrationResource.java
 ##########
 @@ -288,12 +376,112 @@ private String getBucketPeriod(AnomalyFunctionDTO functionDTO) {
     recipients.put("bcc", alertConfigDTO.getReceiverAddresses().getBcc());
     yamlConfigs.put(PROP_RECIPIENTS, recipients);
 
-    Map<String, Object> alertSchemes = new LinkedHashMap<>();
-    alertSchemes.put(PROP_TYPE, "EMAIL");
-    yamlConfigs.put(PROP_ALERT_SCHEMES, alertSchemes);
+    List<Map<String, Object>> schemes = new ArrayList<>();
+    Map<String, Object> emailScheme = new LinkedHashMap<>();
+    emailScheme.put(PROP_TYPE, "EMAIL");
+    schemes.add(emailScheme);
+    yamlConfigs.put(PROP_ALERT_SCHEMES, schemes);
 
-    yamlConfigs.put(PROP_DETECTION_CONFIG_IDS, alertConfigDTO.getEmailConfig().getFunctionIds());
+    List<String> detectionNames = new ArrayList<>();
+    List<Long> detectionIds = alertConfigDTO.getEmailConfig().getFunctionIds();
+    try {
+      detectionNames.addAll(detectionIds.stream().map(detectionId ->  this.anomalyFunctionDAO.findByPredicate(
+          Predicate.EQ("baseId", detectionId)).get(0).getFunctionName()).collect(Collectors.toList()));
+    } catch (Exception e){
+      throw new IllegalArgumentException("cannot find subscribed detection id, please check the function ids");
+    }
+    yamlConfigs.put(PROP_DETECTION_NAMES, detectionNames);
 
     return yamlConfigs;
   }
+
+  @GET
+  public Response getYamlFromLegacyAnomalyFunction(long anomalyFunctionID) throws Exception {
+    AnomalyFunctionDTO anomalyFunctionDTO = this.anomalyFunctionDAO.findById(anomalyFunctionID);
+    if (anomalyFunctionDTO == null) {
+      return Response.status(Response.Status.BAD_REQUEST)
+          .entity(ImmutableMap.of("message", "Legacy Anomaly function cannot be found for id "+ anomalyFunctionID))
+          .build();
+    }
+    return Response.ok(this.yaml.dump(translateAnomalyFunctionToYaml(anomalyFunctionDTO))).build();
+  }
+
+  @GET
+  public Response getYamlFromLegacyAlert(long alertId) throws Exception {
+    AlertConfigDTO alertConfigDTO = this.alertConfigDAO.findById(alertId);
+    if (alertConfigDTO == null) {
+      return Response.status(Response.Status.BAD_REQUEST)
+          .entity(ImmutableMap.of("message", "Legacy alert cannot be found for ID "+ alertId))
+          .build();
+    }
+    return Response.ok(this.yaml.dump(translateAlertToYaml(alertConfigDTO))).build();
+  }
+
+  @POST
+  public Response migrateApplication(@QueryParam("id") String application) throws Exception {
+    List<AlertConfigDTO> alertConfigDTOList = alertConfigDAO.findByPredicate(Predicate.EQ("application", application));
+    Map<String, String> responseMessage = new HashMap<>();
+
+    for (AlertConfigDTO alertConfigDTO : alertConfigDTOList) {
+      LOGGER.info(String.format("[MIG] Migrating alert %d_%s", alertConfigDTO.getId(), alertConfigDTO.getName()));
+      try {
+        // Skip if the alert is already migrated
+        if (alertConfigDTO.getName().contains(MIGRATED_TAG)) {
+          LOGGER.info(String.format("[MIG] Alert %d is already migrated. Skipping!", alertConfigDTO.getId()));
+          continue;
+        }
+
+        // Build the new alert object
+        Map<String, Object> detectionAlertYaml = translateAlertToYaml(alertConfigDTO);
+        DetectionAlertConfigDTO alertConfig = new YamlDetectionAlertConfigTranslator(detectionConfigDAO).translate(detectionAlertYaml);
+
+        // Migrate all the subscribed anomaly functions
+        long currentTimestamp = System.currentTimeMillis();
+        List<Long> newDetectionIds = new ArrayList<>();
+        Map<Long, Long> vectorClocks = new HashMap<>();
+        List<Long> detectionIds = ConfigUtils.getLongs(alertConfig.getProperties().get(PROP_DETECTION_CONFIG_IDS));
+        for (long detectionId : detectionIds) {
 
 Review comment:
   This is a good idea! The issue is that the vector clocks in the translator set the time watermark to 0, while here, since we do not want to resend the anomalies we need to override the clock to the current timestamp. Let's sync up offline to see if we really need to set the timestamp to 0 in the first place.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

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