use of co.cask.cdap.metrics.query.MetricsQueryHelper in project cdap by caskdata.
the class PreviewHttpHandler method query.
@POST
@Path("previews/{preview-id}/metrics/query")
public void query(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("preview-id") String previewId, @QueryParam("metric") List<String> metrics, @QueryParam("groupBy") List<String> groupBy, @QueryParam("tag") List<String> tags) throws Exception {
MetricsQueryHelper helper = getMetricsQueryHelper(namespaceId, previewId);
try {
if (new QueryStringDecoder(request.getUri()).getParameters().isEmpty()) {
if (HttpHeaders.getContentLength(request) > 0) {
Map<String, MetricsQueryHelper.QueryRequestFormat> queries = GSON.fromJson(request.getContent().toString(Charsets.UTF_8), new TypeToken<Map<String, MetricsQueryHelper.QueryRequestFormat>>() {
}.getType());
overrideQueries(queries, namespaceId, previewId);
responder.sendJson(HttpResponseStatus.OK, helper.executeBatchQueries(queries));
return;
}
responder.sendJson(HttpResponseStatus.BAD_REQUEST, "Batch request with empty content");
}
tags = overrideTags(tags, namespaceId, previewId);
responder.sendJson(HttpResponseStatus.OK, helper.executeTagQuery(tags, metrics, groupBy, new QueryStringDecoder(request.getUri()).getParameters()));
} catch (IllegalArgumentException e) {
LOG.warn("Invalid request", e);
responder.sendString(HttpResponseStatus.BAD_REQUEST, e.getMessage());
} catch (Exception e) {
LOG.error("Exception querying metrics ", e);
responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, "Internal error while querying for metrics");
}
}
Aggregations