Search in sources :

Example 1 with RequestLogEvent

use of org.apache.druid.server.log.RequestLogEvent in project druid by druid-io.

the class KafkaEmitterTest method testKafkaEmitter.

// there is 1 seconds wait in kafka emitter before it starts sending events to broker, set a timeout for 5 seconds
@Test(timeout = 5_000)
public void testKafkaEmitter() throws InterruptedException {
    final List<ServiceMetricEvent> serviceMetricEvents = ImmutableList.of(ServiceMetricEvent.builder().build("m1", 1).build("service", "host"));
    final List<AlertEvent> alertEvents = ImmutableList.of(new AlertEvent("service", "host", "description"));
    final List<RequestLogEvent> requestLogEvents = ImmutableList.of(DefaultRequestLogEventBuilderFactory.instance().createRequestLogEventBuilder("requests", RequestLogLine.forSql("", null, DateTimes.nowUtc(), null, new QueryStats(ImmutableMap.of()))).build("service", "host"));
    int totalEvents = serviceMetricEvents.size() + alertEvents.size() + requestLogEvents.size();
    int totalEventsExcludingRequestLogEvents = totalEvents - requestLogEvents.size();
    final CountDownLatch countDownSentEvents = new CountDownLatch(requestTopic == null ? totalEventsExcludingRequestLogEvents : totalEvents);
    final KafkaProducer<String, String> producer = mock(KafkaProducer.class);
    final KafkaEmitter kafkaEmitter = new KafkaEmitter(new KafkaEmitterConfig("", "metrics", "alerts", requestTopic, "test-cluster", null), new ObjectMapper()) {

        @Override
        protected Producer<String, String> setKafkaProducer() {
            // override send interval to 1 second
            sendInterval = 1;
            return producer;
        }
    };
    when(producer.send(any(), any())).then((invocation) -> {
        countDownSentEvents.countDown();
        return null;
    });
    kafkaEmitter.start();
    for (Event event : serviceMetricEvents) {
        kafkaEmitter.emit(event);
    }
    for (Event event : alertEvents) {
        kafkaEmitter.emit(event);
    }
    for (Event event : requestLogEvents) {
        kafkaEmitter.emit(event);
    }
    countDownSentEvents.await();
    Assert.assertEquals(0, kafkaEmitter.getMetricLostCount());
    Assert.assertEquals(0, kafkaEmitter.getAlertLostCount());
    Assert.assertEquals(requestTopic == null ? requestLogEvents.size() : 0, kafkaEmitter.getRequestLostCount());
    Assert.assertEquals(0, kafkaEmitter.getInvalidLostCount());
}
Also used : AlertEvent(org.apache.druid.java.util.emitter.service.AlertEvent) CountDownLatch(java.util.concurrent.CountDownLatch) QueryStats(org.apache.druid.server.QueryStats) RequestLogEvent(org.apache.druid.server.log.RequestLogEvent) AlertEvent(org.apache.druid.java.util.emitter.service.AlertEvent) RequestLogEvent(org.apache.druid.server.log.RequestLogEvent) ServiceMetricEvent(org.apache.druid.java.util.emitter.service.ServiceMetricEvent) Event(org.apache.druid.java.util.emitter.core.Event) ServiceMetricEvent(org.apache.druid.java.util.emitter.service.ServiceMetricEvent) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Event (org.apache.druid.java.util.emitter.core.Event)1 AlertEvent (org.apache.druid.java.util.emitter.service.AlertEvent)1 ServiceMetricEvent (org.apache.druid.java.util.emitter.service.ServiceMetricEvent)1 QueryStats (org.apache.druid.server.QueryStats)1 RequestLogEvent (org.apache.druid.server.log.RequestLogEvent)1 Test (org.junit.Test)1