@Override public void handle(ChannelHandlerContext ctx, HttpRequest request) { Tracker.getInstance().track(request); final String tenantId = request.getHeader("tenantId"); if (!(request instanceof HTTPRequestWithDecodedQueryParams)) { sendResponse( ctx, request, "Missing query params: from, to, points", HttpResponseStatus.BAD_REQUEST); return; } final String body = request.getContent().toString(Constants.DEFAULT_CHARSET); if (body == null || body.isEmpty()) { sendResponse( ctx, request, "Invalid body. Expected JSON array of metrics.", HttpResponseStatus.BAD_REQUEST); return; } List<String> locators = new ArrayList<String>(); try { locators.addAll(getLocatorsFromJSONBody(tenantId, body)); } catch (Exception ex) { log.debug(ex.getMessage(), ex); sendResponse(ctx, request, ex.getMessage(), HttpResponseStatus.BAD_REQUEST); return; } if (locators.size() > maxMetricsPerRequest) { sendResponse( ctx, request, "Too many metrics fetch in a single call. Max limit is " + maxMetricsPerRequest + ".", HttpResponseStatus.BAD_REQUEST); return; } HTTPRequestWithDecodedQueryParams requestWithParams = (HTTPRequestWithDecodedQueryParams) request; final Timer.Context httpBatchMetricsFetchTimerContext = httpBatchMetricsFetchTimer.time(); try { RollupsQueryParams params = PlotRequestParser.parseParams(requestWithParams.getQueryParams()); Map<Locator, MetricData> results = getRollupByGranularity( tenantId, locators, params.getRange().getStart(), params.getRange().getStop(), params.getGranularity(tenantId)); JSONObject metrics = serializer.transformRollupData(results, params.getStats()); final JsonElement element = parser.parse(metrics.toString()); final String jsonStringRep = gson.toJson(element); sendResponse(ctx, request, jsonStringRep, HttpResponseStatus.OK); } catch (InvalidRequestException e) { log.debug(e.getMessage()); sendResponse(ctx, request, e.getMessage(), HttpResponseStatus.BAD_REQUEST); } catch (SerializationException e) { log.debug(e.getMessage(), e); sendResponse(ctx, request, e.getMessage(), HttpResponseStatus.INTERNAL_SERVER_ERROR); } catch (Exception e) { log.error(e.getMessage(), e); sendResponse(ctx, request, e.getMessage(), HttpResponseStatus.INTERNAL_SERVER_ERROR); } finally { httpBatchMetricsFetchTimerContext.stop(); } }