use of com.linkedin.thirdeye.dashboard.views.heatmap.HeatMapViewHandler 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);
}
use of com.linkedin.thirdeye.dashboard.views.heatmap.HeatMapViewHandler 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;
}
use of com.linkedin.thirdeye.dashboard.views.heatmap.HeatMapViewHandler 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;
}
Aggregations