}
@Override
public void handle(ChannelHandlerContext ctx, HttpRequest request) {
final String tenantId = request.getHeader("tenantId");
JSONMetricsContainer jsonMetricsContainer = null;
final Timer.Context jsonTimerContext = jsonTimer.time();
final String body = request.getContent().toString(Constants.DEFAULT_CHARSET);
try {
jsonMetricsContainer = createContainer(body, tenantId);
if (!jsonMetricsContainer.isValid()) {
throw new IOException("Invalid JSONMetricsContainer");
}
} catch (JsonParseException e) {
log.warn("Exception parsing content", e);
sendResponse(ctx, request, "Cannot parse content", HttpResponseStatus.BAD_REQUEST);
return;
} catch (JsonMappingException e) {
log.warn("Exception parsing content", e);
sendResponse(ctx, request, "Cannot parse content", HttpResponseStatus.BAD_REQUEST);
return;
} catch (IOException e) {
log.warn("IO Exception parsing content", e);
sendResponse(ctx, request, "Cannot parse content", HttpResponseStatus.BAD_REQUEST);
return;
} catch (Exception e) {
log.warn("Other exception while trying to parse content", e);
sendResponse(ctx, request, "Failed parsing content", HttpResponseStatus.INTERNAL_SERVER_ERROR);
return;
}
if (jsonMetricsContainer == null) {
log.warn(ctx.getChannel().getRemoteAddress() + " No valid metrics");
sendResponse(ctx, request, "No valid metrics", HttpResponseStatus.BAD_REQUEST);
return;
}
List<Metric> containerMetrics;
try {
containerMetrics = jsonMetricsContainer.toMetrics();
forceTTLsIfConfigured(containerMetrics);
} catch (InvalidDataException ex) {
// todo: we should measure these. if they spike, we track down the bad client.
// this is strictly a client problem. Someting wasn't right (data out of range, etc.)
log.warn(ctx.getChannel().getRemoteAddress() + " " + ex.getMessage());