Search in sources :

Example 1 with Builder

use of io.jaegertracing.internal.reporters.RemoteReporter.Builder in project jaeger-client-java by jaegertracing.

the class RemoteReporterTest method testFlushIsCalledOnSender.

@Test
public void testFlushIsCalledOnSender() throws InterruptedException {
    CountDownLatch latch = new CountDownLatch(1);
    InMemorySender sender = new InMemorySender() {

        @Override
        public int flush() throws SenderException {
            latch.countDown();
            return super.flush();
        }
    };
    RemoteReporter remoteReporter = new Builder().withSender(sender).withFlushInterval(flushInterval).withMaxQueueSize(maxQueueSize).withMetrics(metrics).build();
    tracer = new JaegerTracer.Builder("test-remote-reporter").withReporter(remoteReporter).withSampler(new ConstSampler(true)).withMetrics(metrics).build();
    tracer.buildSpan("mySpan").start().finish();
    remoteReporter.flush();
    latch.await();
    assertEquals("Should have called the custom sender flush", 0, latch.getCount());
    assertEquals("mySpan", (sender.getReceived().get(0)).getOperationName());
}
Also used : Builder(io.jaegertracing.internal.reporters.RemoteReporter.Builder) InMemorySender(io.jaegertracing.internal.senders.InMemorySender) ConstSampler(io.jaegertracing.internal.samplers.ConstSampler) CountDownLatch(java.util.concurrent.CountDownLatch) JaegerTracer(io.jaegertracing.internal.JaegerTracer) Test(org.junit.Test)

Example 2 with Builder

use of io.jaegertracing.internal.reporters.RemoteReporter.Builder in project jaeger-client-java by jaegertracing.

the class RemoteReporterTest method testUpdateErrorMetricWhenCommandExecuteFails.

@Test
public void testUpdateErrorMetricWhenCommandExecuteFails() throws Exception {
    int reporterFailures = 5;
    sender = new InMemorySender() {

        @Override
        public int append(JaegerSpan span) throws SenderException {
            throw new SenderException("", reporterFailures);
        }
    };
    RemoteReporter reporter = new Builder().withSender(sender).withFlushInterval(flushInterval).withMaxQueueSize(maxQueueSize).withMetrics(metrics).build();
    reporter.report(newSpan());
    reporter.close();
    assertEquals(reporterFailures, metricsFactory.getCounter("jaeger_tracer_reporter_spans", "result=err"));
}
Also used : Builder(io.jaegertracing.internal.reporters.RemoteReporter.Builder) JaegerSpan(io.jaegertracing.internal.JaegerSpan) InMemorySender(io.jaegertracing.internal.senders.InMemorySender) SenderException(io.jaegertracing.internal.exceptions.SenderException) Test(org.junit.Test)

Example 3 with Builder

use of io.jaegertracing.internal.reporters.RemoteReporter.Builder in project jaeger-client-java by jaegertracing.

the class RemoteReporterTest method testFlushErrorsLoggedJustOnce.

@Test
public void testFlushErrorsLoggedJustOnce() throws InterruptedException {
    Object logMonitor = new Object();
    AtomicReference<String> logMsg = new AtomicReference<>(null);
    mockLogger(e -> {
        synchronized (logMonitor) {
            logMsg.set(e.getFormattedMessage());
            logMonitor.notifyAll();
        }
    });
    class FailingSender extends InMemorySender {

        private final AtomicInteger flushCounter = new AtomicInteger(0);

        @Override
        public int flush() throws SenderException {
            int i = super.flush();
            switch(flushCounter.getAndIncrement()) {
                case 1:
                case 2:
                case 3:
                    throw new SenderException("test1", i);
                default:
                    return i;
            }
        }

        private String awaitMessage(AtomicReference<String> ref) throws InterruptedException {
            synchronized (logMonitor) {
                while (ref.get() == null) {
                    logMonitor.wait();
                }
                return ref.getAndSet(null);
            }
        }
    }
    FailingSender sender = new FailingSender();
    RemoteReporter remoteReporter = new Builder().withSender(sender).withFlushInterval(Integer.MAX_VALUE).withMaxQueueSize(maxQueueSize).withMetrics(metrics).build();
    tracer = new JaegerTracer.Builder("test-remote-reporter").withReporter(remoteReporter).withSampler(new ConstSampler(true)).withMetrics(metrics).build();
    assertEquals(0, sender.flushCounter.get());
    tracer.buildSpan("mySpan").start().finish();
    remoteReporter.flush();
    // 1. SenderException is thrown (log should be produced)
    await().with().pollInterval(1, TimeUnit.MILLISECONDS).until(() -> sender.flushCounter.get() == 1);
    tracer.buildSpan("mySpan").start().finish();
    remoteReporter.flush();
    assertEquals("FlushCommand execution failed! Repeated errors of this command will not be logged.", sender.awaitMessage(logMsg));
    // 2. SenderException is thrown (log should not be produced)
    await().with().pollInterval(1, TimeUnit.MILLISECONDS).until(() -> sender.flushCounter.get() == 2);
    remoteReporter.flush();
    // 3. SenderException is thrown (log should not be produced)
    await().with().pollInterval(1, TimeUnit.MILLISECONDS).until(() -> sender.flushCounter.get() == 3);
    remoteReporter.flush();
    // No SenderException is thrown now, but 0 span is ready -> still stay in failing state
    await().with().pollInterval(1, TimeUnit.MILLISECONDS).until(() -> sender.flushCounter.get() == 4);
    remoteReporter.flush();
    // No SenderException is thrown now, but 1 span is ready -> move to working state
    tracer.buildSpan("mySpan").start().finish();
    remoteReporter.flush();
    assertEquals("FlushCommand is working again!", sender.awaitMessage(logMsg));
    await().with().pollInterval(1, TimeUnit.MILLISECONDS).until(() -> sender.getFlushed().size() == 3);
}
Also used : Builder(io.jaegertracing.internal.reporters.RemoteReporter.Builder) AtomicReference(java.util.concurrent.atomic.AtomicReference) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InMemorySender(io.jaegertracing.internal.senders.InMemorySender) ConstSampler(io.jaegertracing.internal.samplers.ConstSampler) SenderException(io.jaegertracing.internal.exceptions.SenderException) JaegerTracer(io.jaegertracing.internal.JaegerTracer) Test(org.junit.Test)

Example 4 with Builder

use of io.jaegertracing.internal.reporters.RemoteReporter.Builder in project jaeger-client-java by jaegertracing.

the class RemoteReporterTest method testUpdateSuccessMetricWhenAppendFlushed.

@Test
public void testUpdateSuccessMetricWhenAppendFlushed() throws InterruptedException {
    int totalSpans = 3;
    int flushSize = 2;
    CountDownLatch latch = new CountDownLatch(1);
    sender = new InMemorySender() {

        @Override
        public int append(JaegerSpan span) {
            try {
                super.append(span);
                if (getAppended().size() >= flushSize) {
                    return flush();
                }
                if (getReceived().size() == totalSpans) {
                    latch.countDown();
                }
                return 0;
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    };
    reporter = new Builder().withSender(sender).withFlushInterval(Integer.MAX_VALUE).withMaxQueueSize(maxQueueSize).withMetrics(metrics).build();
    tracer = new JaegerTracer.Builder("test-remote-reporter").withReporter(reporter).withSampler(new ConstSampler(true)).withMetrics(metrics).build();
    for (int i = 0; i < totalSpans; i++) {
        reporter.report(newSpan());
    }
    latch.await(1, TimeUnit.SECONDS);
    assertEquals(flushSize, metricsFactory.getCounter("jaeger_tracer_reporter_spans", "result=ok"));
    assertEquals(0, metricsFactory.getCounter("jaeger_tracer_reporter_spans", "result=err"));
    assertEquals(0, metricsFactory.getCounter("jaeger_tracer_reporter_spans", "result=dropped"));
}
Also used : Builder(io.jaegertracing.internal.reporters.RemoteReporter.Builder) JaegerSpan(io.jaegertracing.internal.JaegerSpan) InMemorySender(io.jaegertracing.internal.senders.InMemorySender) ConstSampler(io.jaegertracing.internal.samplers.ConstSampler) CountDownLatch(java.util.concurrent.CountDownLatch) SenderException(io.jaegertracing.internal.exceptions.SenderException) JaegerTracer(io.jaegertracing.internal.JaegerTracer) Test(org.junit.Test)

Aggregations

Builder (io.jaegertracing.internal.reporters.RemoteReporter.Builder)4 InMemorySender (io.jaegertracing.internal.senders.InMemorySender)4 Test (org.junit.Test)4 JaegerTracer (io.jaegertracing.internal.JaegerTracer)3 SenderException (io.jaegertracing.internal.exceptions.SenderException)3 ConstSampler (io.jaegertracing.internal.samplers.ConstSampler)3 JaegerSpan (io.jaegertracing.internal.JaegerSpan)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1