Search in sources :

Example 1 with HeatMapViewResponse

use of com.linkedin.thirdeye.dashboard.views.heatmap.HeatMapViewResponse in project pinot by linkedin.

the class HeatMapTest method main.

public static void main(String[] args) throws Exception {
    HeatMapViewRequest request = new HeatMapViewRequest();
    String collection = "thirdeyeAbook";
    DateTime baselineStart = new DateTime(2016, 3, 23, 00, 00);
    List<MetricExpression> metricExpressions = new ArrayList<>();
    metricExpressions.add(new MetricExpression("__COUNT", "__COUNT"));
    request.setCollection(collection);
    request.setBaselineStart(baselineStart);
    request.setBaselineEnd(baselineStart.plusHours(1));
    request.setCurrentStart(baselineStart.plusDays(7));
    request.setCurrentEnd(baselineStart.plusDays(7).plusHours(1));
    request.setTimeGranularity(new TimeGranularity(1, TimeUnit.HOURS));
    request.setMetricExpressions(metricExpressions);
    // TODO
    PinotThirdEyeClient pinotThirdEyeClient = PinotThirdEyeClient.getDefaultTestClient();
    // make
    // this
    // configurable;
    QueryCache queryCache = new QueryCache(pinotThirdEyeClient, Executors.newFixedThreadPool(10));
    HeatMapViewHandler handler = new HeatMapViewHandler(queryCache);
    HeatMapViewResponse response = handler.process(request);
    ObjectMapper mapper = new ObjectMapper();
    String jsonResponse = mapper.writeValueAsString(response);
    System.out.println(jsonResponse);
}
Also used : PinotThirdEyeClient(com.linkedin.thirdeye.client.pinot.PinotThirdEyeClient) QueryCache(com.linkedin.thirdeye.client.cache.QueryCache) HeatMapViewResponse(com.linkedin.thirdeye.dashboard.views.heatmap.HeatMapViewResponse) ArrayList(java.util.ArrayList) HeatMapViewRequest(com.linkedin.thirdeye.dashboard.views.heatmap.HeatMapViewRequest) TimeGranularity(com.linkedin.thirdeye.api.TimeGranularity) HeatMapViewHandler(com.linkedin.thirdeye.dashboard.views.heatmap.HeatMapViewHandler) MetricExpression(com.linkedin.thirdeye.client.MetricExpression) DateTime(org.joda.time.DateTime) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with HeatMapViewResponse

use of com.linkedin.thirdeye.dashboard.views.heatmap.HeatMapViewResponse in project pinot by linkedin.

the class DataResource method getHeatMap.

//------------- HeatMap -----------------
@GET
@Path(value = "heatmap/{metricId}/{currentStart}/{currentEnd}/{baselineStart}/{baselineEnd}")
@Produces(MediaType.APPLICATION_JSON)
public HeatMapViewResponse getHeatMap(@QueryParam("filters") String filters, @PathParam("baselineStart") Long baselineStart, @PathParam("baselineEnd") Long baselineEnd, @PathParam("currentStart") Long currentStart, @PathParam("currentEnd") Long currentEnd, @PathParam("metricId") Long metricId) throws Exception {
    MetricConfigDTO metricConfigDTO = metricConfigDAO.findById(metricId);
    String collection = metricConfigDTO.getDataset();
    String metric = metricConfigDTO.getName();
    HeatMapViewRequest request = new HeatMapViewRequest();
    request.setCollection(collection);
    List<MetricExpression> metricExpressions = Utils.convertToMetricExpressions(metric, MetricAggFunction.SUM, collection);
    request.setMetricExpressions(metricExpressions);
    long maxDataTime = collectionMaxDataTimeCache.get(collection);
    if (currentEnd > maxDataTime) {
        long delta = currentEnd - maxDataTime;
        currentEnd = currentEnd - delta;
        baselineEnd = baselineEnd - delta;
    }
    // See {@link #getDashboardData} for the reason that the start and end time are stored in a
    // DateTime object with data's timezone.
    DateTimeZone timeZoneForCollection = Utils.getDataTimeZone(collection);
    request.setBaselineStart(new DateTime(baselineStart, timeZoneForCollection));
    request.setBaselineEnd(new DateTime(baselineEnd, timeZoneForCollection));
    request.setCurrentStart(new DateTime(currentStart, timeZoneForCollection));
    request.setCurrentEnd(new DateTime(currentEnd, timeZoneForCollection));
    // filter
    if (filters != null && !filters.isEmpty()) {
        filters = URLDecoder.decode(filters, "UTF-8");
        request.setFilters(ThirdEyeUtils.convertToMultiMap(filters));
    }
    HeatMapViewHandler handler = new HeatMapViewHandler(queryCache);
    HeatMapViewResponse response = handler.process(request);
    return response;
}
Also used : MetricConfigDTO(com.linkedin.thirdeye.datalayer.dto.MetricConfigDTO) HeatMapViewResponse(com.linkedin.thirdeye.dashboard.views.heatmap.HeatMapViewResponse) HeatMapViewRequest(com.linkedin.thirdeye.dashboard.views.heatmap.HeatMapViewRequest) HeatMapViewHandler(com.linkedin.thirdeye.dashboard.views.heatmap.HeatMapViewHandler) MetricExpression(com.linkedin.thirdeye.client.MetricExpression) DateTimeZone(org.joda.time.DateTimeZone) DateTime(org.joda.time.DateTime) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with HeatMapViewResponse

use of com.linkedin.thirdeye.dashboard.views.heatmap.HeatMapViewResponse in project pinot by linkedin.

the class DashboardResource method getHeatMap.

@GET
@Path(value = "/data/heatmap")
@Produces(MediaType.APPLICATION_JSON)
public String getHeatMap(@QueryParam("dataset") String collection, @QueryParam("filters") String filterJson, @QueryParam("timeZone") @DefaultValue(DEFAULT_TIMEZONE_ID) String timeZone, @QueryParam("baselineStart") Long baselineStart, @QueryParam("baselineEnd") Long baselineEnd, @QueryParam("currentStart") Long currentStart, @QueryParam("currentEnd") Long currentEnd, @QueryParam("compareMode") String compareMode, @QueryParam("metrics") String metricsJson) throws Exception {
    HeatMapViewRequest request = new HeatMapViewRequest();
    request.setCollection(collection);
    List<MetricExpression> metricExpressions = Utils.convertToMetricExpressions(metricsJson, MetricAggFunction.SUM, collection);
    request.setMetricExpressions(metricExpressions);
    long maxDataTime = collectionMaxDataTimeCache.get(collection);
    if (currentEnd > maxDataTime) {
        long delta = currentEnd - maxDataTime;
        currentEnd = currentEnd - delta;
        baselineEnd = baselineEnd - delta;
    }
    // See {@link #getDashboardData} for the reason that the start and end time are stored in a
    // DateTime object with data's timezone.
    DateTimeZone timeZoneForCollection = Utils.getDataTimeZone(collection);
    request.setBaselineStart(new DateTime(baselineStart, timeZoneForCollection));
    request.setBaselineEnd(new DateTime(baselineEnd, timeZoneForCollection));
    request.setCurrentStart(new DateTime(currentStart, timeZoneForCollection));
    request.setCurrentEnd(new DateTime(currentEnd, timeZoneForCollection));
    // filter
    if (filterJson != null && !filterJson.isEmpty()) {
        filterJson = URLDecoder.decode(filterJson, "UTF-8");
        request.setFilters(ThirdEyeUtils.convertToMultiMap(filterJson));
    }
    HeatMapViewHandler handler = new HeatMapViewHandler(queryCache);
    HeatMapViewResponse response;
    String jsonResponse = null;
    try {
        response = handler.process(request);
        jsonResponse = OBJECT_MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(response);
        LOG.debug("Heatmap response {}", jsonResponse);
    } catch (Exception e) {
        LOG.error("Error generating heatmap response", e);
    }
    return jsonResponse;
}
Also used : HeatMapViewResponse(com.linkedin.thirdeye.dashboard.views.heatmap.HeatMapViewResponse) HeatMapViewRequest(com.linkedin.thirdeye.dashboard.views.heatmap.HeatMapViewRequest) HeatMapViewHandler(com.linkedin.thirdeye.dashboard.views.heatmap.HeatMapViewHandler) MetricExpression(com.linkedin.thirdeye.client.MetricExpression) DateTimeZone(org.joda.time.DateTimeZone) DateTime(org.joda.time.DateTime) JSONException(org.json.JSONException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

MetricExpression (com.linkedin.thirdeye.client.MetricExpression)3 HeatMapViewHandler (com.linkedin.thirdeye.dashboard.views.heatmap.HeatMapViewHandler)3 HeatMapViewRequest (com.linkedin.thirdeye.dashboard.views.heatmap.HeatMapViewRequest)3 HeatMapViewResponse (com.linkedin.thirdeye.dashboard.views.heatmap.HeatMapViewResponse)3 DateTime (org.joda.time.DateTime)3 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 DateTimeZone (org.joda.time.DateTimeZone)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 TimeGranularity (com.linkedin.thirdeye.api.TimeGranularity)1 QueryCache (com.linkedin.thirdeye.client.cache.QueryCache)1 PinotThirdEyeClient (com.linkedin.thirdeye.client.pinot.PinotThirdEyeClient)1 MetricConfigDTO (com.linkedin.thirdeye.datalayer.dto.MetricConfigDTO)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 ExecutionException (java.util.concurrent.ExecutionException)1 JSONException (org.json.JSONException)1