You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by xh...@apache.org on 2019/04/29 22:32:50 UTC

[incubator-pinot] branch master updated: [TE] Show more debug information in preview (#4167)

This is an automated email from the ASF dual-hosted git repository.

xhsun 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 3f9a2cb  [TE] Show more debug information in preview (#4167)
3f9a2cb is described below

commit 3f9a2cbb44befda7957b94d3cfe60775be0f1e89
Author: Xiaohui Sun <xh...@linkedin.com>
AuthorDate: Mon Apr 29 15:32:44 2019 -0700

    [TE] Show more debug information in preview (#4167)
    
    * [TE] Show more debug information in preview
    
    * [TE] Revert to set detection config id as Long.MAX_VALUE
    
    * [TE] Remove duplicate code for preview
---
 .../DetectorDataInsufficientException.java         |  2 +-
 .../thirdeye/detection/yaml/YamlResource.java      | 75 +++++++++++-----------
 2 files changed, 38 insertions(+), 39 deletions(-)

diff --git a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/spi/exception/DetectorDataInsufficientException.java b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/spi/exception/DetectorDataInsufficientException.java
index f65223c..10aa936 100644
--- a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/spi/exception/DetectorDataInsufficientException.java
+++ b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/spi/exception/DetectorDataInsufficientException.java
@@ -28,7 +28,7 @@ public class DetectorDataInsufficientException extends DetectorException {
   }
 
   public DetectorDataInsufficientException() {
-    super();
+    this("Data is insufficient to run detection");
   }
 
   public DetectorDataInsufficientException(String message) {
diff --git a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/yaml/YamlResource.java b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/yaml/YamlResource.java
index c4e1160..6fe2d52 100644
--- a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/yaml/YamlResource.java
+++ b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/yaml/YamlResource.java
@@ -34,7 +34,6 @@ import java.util.Map;
 import java.util.Optional;
 import java.util.TreeMap;
 import java.util.concurrent.TimeUnit;
-import java.util.stream.Collectors;
 import javax.validation.constraints.NotNull;
 import javax.ws.rs.Consumes;
 import javax.ws.rs.GET;
@@ -566,35 +565,8 @@ public class YamlResource {
       @QueryParam("tuningStart") long tuningStart,
       @QueryParam("tuningEnd") long tuningEnd,
       @ApiParam("jsonPayload") String payload) {
-    Map<String, String> responseMessage = new HashMap<>();
-    DetectionPipelineResult result;
-    long ts = System.currentTimeMillis();
-    try {
-      Preconditions.checkArgument(StringUtils.isNotBlank(payload), "The Yaml Payload in the request is empty.");
-
-      // Translate config from YAML to detection config (JSON)
-      Map<String, Object> newDetectionConfigMap = new HashMap<>(ConfigUtils.getMap(this.yaml.load(payload)));
-      DetectionConfigDTO detectionConfig = buildDetectionConfigFromYaml(tuningStart, tuningEnd, newDetectionConfigMap, null);
-      Preconditions.checkNotNull(detectionConfig);
-      detectionConfig.setId(Long.MAX_VALUE);
-
-      DetectionPipeline pipeline = this.loader.from(this.provider, detectionConfig, start, end);
-      result = pipeline.run();
-
-    } catch (ValidationException e) {
-      LOG.warn("Validation error while running preview with payload  " + payload, e);
-      responseMessage.put("message", "Validation Error! " + e.getMessage());
-      return Response.serverError().entity(responseMessage).build();
-    } catch (InvocationTargetException e) {
-      responseMessage.put("message", "Failed to run the preview due to " + e.getTargetException().getMessage());
-      return Response.serverError().entity(responseMessage).build();
-    } catch (Exception e) {
-      LOG.error("Error running preview with payload " + payload, e);
-      responseMessage.put("message", "Failed to run the preview due to " + e.getMessage());
-      return Response.serverError().entity(responseMessage).build();
-    }
-    LOG.info("Preview successful, used {} milliseconds", System.currentTimeMillis() - ts);
-    return Response.ok(result).build();
+    Preconditions.checkArgument(StringUtils.isNotBlank(payload), "The Yaml Payload in the request is empty.");
+    return runPreview(start, end, tuningStart, tuningEnd, payload, null);
   }
 
   @POST
@@ -609,19 +581,30 @@ public class YamlResource {
       @QueryParam("tuningStart") long tuningStart,
       @QueryParam("tuningEnd") long tuningEnd,
       @ApiParam("jsonPayload") String payload) {
+    Preconditions.checkArgument(StringUtils.isNotBlank(payload), "The Yaml Payload in the request is empty.");
+    DetectionConfigDTO existingConfig = this.detectionConfigDAO.findById(id);
+    Preconditions.checkNotNull(existingConfig, "can not find existing detection config " + id);
+    return runPreview(start, end, tuningStart, tuningEnd, payload, existingConfig);
+  }
+
+  private Response runPreview(long start, long end,
+      long tuningStart, long tuningEnd, String payload, DetectionConfigDTO existingConfig) {
+    long ts = System.currentTimeMillis();
     Map<String, String> responseMessage = new HashMap<>();
     DetectionPipelineResult result;
-    long ts = System.currentTimeMillis();
     try {
-      Preconditions.checkArgument(StringUtils.isNotBlank(payload), "The Yaml Payload in the request is empty.");
-      DetectionConfigDTO existingConfig = this.detectionConfigDAO.findById(id);
-      Preconditions.checkNotNull(existingConfig, "can not find existing detection config " + id);
-
       // Translate config from YAML to detection config (JSON)
       Map<String, Object> newDetectionConfigMap = new HashMap<>(ConfigUtils.getMap(this.yaml.load(payload)));
-      DetectionConfigDTO detectionConfig = buildDetectionConfigFromYaml(tuningStart, tuningEnd, newDetectionConfigMap, existingConfig);
-      Preconditions.checkNotNull(detectionConfig);
+      DetectionConfigDTO detectionConfig;
 
+      if (existingConfig == null) {
+        detectionConfig = buildDetectionConfigFromYaml(tuningStart, tuningEnd, newDetectionConfigMap, null);
+        detectionConfig.setId(Long.MAX_VALUE);
+      } else {
+        detectionConfig = buildDetectionConfigFromYaml(tuningStart, tuningEnd, newDetectionConfigMap, existingConfig);
+      }
+
+      Preconditions.checkNotNull(detectionConfig);
       DetectionPipeline pipeline = this.loader.from(this.provider, detectionConfig, start, end);
       result = pipeline.run();
 
@@ -629,15 +612,31 @@ public class YamlResource {
       LOG.warn("Validation error while running preview with payload  " + payload, e);
       responseMessage.put("message", "Validation Error! " + e.getMessage());
       return Response.serverError().entity(responseMessage).build();
+    } catch (InvocationTargetException e) {
+      responseMessage.put("message", "Failed to run the preview due to " + e.getTargetException().getMessage());
+      return Response.serverError().entity(responseMessage).build();
     } catch (Exception e) {
       LOG.error("Error running preview with payload " + payload, e);
-      responseMessage.put("message", "Failed to run the preview due to " + e.getMessage());
+      StringBuilder sb = new StringBuilder();
+      // show more stack message to frontend for debugging
+      getErrorMessage(0, 5, e, sb);
+      responseMessage.put("message", "Failed to run the preview. Error stack: " + sb.toString());
       return Response.serverError().entity(responseMessage).build();
     }
     LOG.info("Preview successful, used {} milliseconds", System.currentTimeMillis() - ts);
     return Response.ok(result).build();
   }
 
+  private void getErrorMessage(int curLevel, int totalLevel, Throwable e, StringBuilder sb) {
+    if (curLevel <= totalLevel && e != null) {
+      sb.append("==");
+      if (e.getMessage() != null) {
+        sb.append(e.getMessage());
+      }
+      getErrorMessage(curLevel + 1, totalLevel, e.getCause(), sb);
+    }
+  }
+
   @POST
   @Path("/preview/baseline")
   @Produces(MediaType.APPLICATION_JSON)


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