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/03/18 23:23:27 UTC

[incubator-pinot] branch master updated: [TE] detection - preview a yaml with existing anomalies (#3983)

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 9e8e373  [TE] detection - preview a yaml with existing anomalies (#3983)
9e8e373 is described below

commit 9e8e3731cd6cc356a421fc3f27b34cba15f1afc8
Author: Jihao Zhang <ji...@linkedin.com>
AuthorDate: Mon Mar 18 16:23:22 2019 -0700

    [TE] detection - preview a yaml with existing anomalies (#3983)
    
    Preview a YAML with existing anomalies.
---
 .../thirdeye/detection/DetectionResource.java      |  5 +++
 .../thirdeye/detection/yaml/YamlResource.java      | 40 ++++++++++++++++++++++
 2 files changed, 45 insertions(+)

diff --git a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/DetectionResource.java b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/DetectionResource.java
index 0b3146a..894b2ac 100644
--- a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/DetectionResource.java
+++ b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/DetectionResource.java
@@ -177,6 +177,7 @@ public class DetectionResource {
 
   @POST
   @Path("/preview")
+  @ApiOperation("preview a detection with detection config json")
   public Response detectionPreview(
       @QueryParam("start") long start,
       @QueryParam("end") long end,
@@ -230,6 +231,7 @@ public class DetectionResource {
 
   @POST
   @Path("/preview/{id}")
+  @ApiOperation("preview a detection with a existing detection config")
   public Response detectionPreview(
       @PathParam("id") long id,
       @QueryParam("start") long start,
@@ -340,6 +342,8 @@ public class DetectionResource {
    */
   @POST
   @Path("/legacy-replay/{id}")
+  @ApiOperation("Legacy replay endpoint. Replay all the moving windows within start time and end time. "
+      + "Saves anomaly for each moving window before starting detection for next window and emulates the cron schedule")
   public Response legacyReplay(
       @PathParam("id") long configId,
       @QueryParam("start") long start,
@@ -400,6 +404,7 @@ public class DetectionResource {
    */
   @POST
   @Path("/replay/{id}")
+  @ApiOperation("Replay for a given time range for a existing detection config id")
   public Response detectionReplay(
       @PathParam("id") long detectionId,
       @QueryParam("start") long start,
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 67e7327..98945a5 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
@@ -586,6 +586,46 @@ public class YamlResource {
     return Response.ok(result).build();
   }
 
+  @POST
+  @Path("/preview/{id}")
+  @Produces(MediaType.APPLICATION_JSON)
+  @Consumes(MediaType.TEXT_PLAIN)
+  @ApiOperation("Preview the anomaly detection result of a YAML configuration, with an existing config and historical anomalies")
+  public Response yamlPreviewWithHistoricalAnomalies(
+      @PathParam("id") long id,
+      @QueryParam("start") long start,
+      @QueryParam("end") long end,
+      @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.");
+      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);
+
+      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 (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();
+  }
 
   /**
    * List all yaml configurations as JSON enhanced with detection config id, isActive and createBy information.


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