Search in sources :

Example 1 with EventTypeMetrics

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));
}
Also used : EventPublishResult(org.zalando.nakadi.domain.EventPublishResult) EventTypeMetrics(org.zalando.nakadi.metrics.EventTypeMetrics) Test(org.junit.Test)

Example 2 with EventTypeMetrics

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;
    }
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) EventTypeMetrics(org.zalando.nakadi.metrics.EventTypeMetrics) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

EventTypeMetrics (org.zalando.nakadi.metrics.EventTypeMetrics)2 Test (org.junit.Test)1 ResponseEntity (org.springframework.http.ResponseEntity)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 EventPublishResult (org.zalando.nakadi.domain.EventPublishResult)1