use of org.zalando.nakadi.metrics.EventTypeMetrics in project nakadi by zalando.
the class EventPublishingControllerTest method publishedEventsAreReportedPerEventType.
@Test
public void publishedEventsAreReportedPerEventType() throws Exception {
final EventPublishResult success = new EventPublishResult(SUBMITTED, null, submittedResponses(3));
Mockito.doReturn(success).doReturn(success).doThrow(InternalNakadiException.class).when(publisher).publish(any(), any());
postBatch(TOPIC, EVENT_BATCH);
postBatch(TOPIC, EVENT_BATCH);
postBatch(TOPIC, EVENT_BATCH);
final EventTypeMetrics eventTypeMetrics = eventTypeMetricRegistry.metricsFor(TOPIC);
assertThat(eventTypeMetrics.getResponseCount(200), equalTo(2L));
assertThat(eventTypeMetrics.getResponseCount(500), equalTo(1L));
}
use of org.zalando.nakadi.metrics.EventTypeMetrics in project nakadi by zalando.
the class EventPublishingController method postEvent.
@RequestMapping(value = "/event-types/{eventTypeName}/events", method = POST)
public ResponseEntity postEvent(@PathVariable final String eventTypeName, @RequestBody final String eventsAsString, final NativeWebRequest request, final Client client) throws AccessDeniedException {
LOG.trace("Received event {} for event type {}", eventsAsString, eventTypeName);
final EventTypeMetrics eventTypeMetrics = eventTypeMetricRegistry.metricsFor(eventTypeName);
try {
if (blacklistService.isProductionBlocked(eventTypeName, client.getClientId())) {
return Responses.create(Problem.valueOf(Response.Status.FORBIDDEN, "Application or event type is blocked"), request);
}
final ResponseEntity response = postEventInternal(eventTypeName, eventsAsString, request, eventTypeMetrics, client);
eventTypeMetrics.incrementResponseCount(response.getStatusCode().value());
return response;
} catch (final RuntimeException ex) {
eventTypeMetrics.incrementResponseCount(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
throw ex;
}
}
Aggregations