Search in sources :

Example 1 with Collector

use of zipkin2.collector.Collector in project zipkin by openzipkin.

the class ITActiveMQCollector method skipsOnSpanStorageException.

/**
 * Guards against errors that leak from storage, such as InvalidQueryException
 */
@Test
public void skipsOnSpanStorageException() throws Exception {
    collector.close();
    AtomicInteger counter = new AtomicInteger();
    consumer = (input) -> new Call.Base<Void>() {

        @Override
        protected Void doExecute() {
            throw new AssertionError();
        }

        @Override
        protected void doEnqueue(Callback<Void> callback) {
            if (counter.getAndIncrement() == 1) {
                callback.onError(new RuntimeException("storage fell over"));
            } else {
                receivedSpans.add(spans);
                callback.onSuccess(null);
            }
        }

        @Override
        public Call<Void> clone() {
            throw new AssertionError();
        }
    };
    activemq.pushMessage(collector.queue, PROTO3.encodeList(spans));
    // tossed on error
    activemq.pushMessage(collector.queue, PROTO3.encodeList(spans));
    activemq.pushMessage(collector.queue, PROTO3.encodeList(spans));
    collector = builder().storage(buildStorage(consumer)).build().start();
    assertThat(receivedSpans.take()).containsExactlyElementsOf(spans);
    // the only way we could read this, is if the malformed span was skipped.
    assertThat(receivedSpans.take()).containsExactlyElementsOf(spans);
    assertThat(activemqMetrics.messages()).isEqualTo(3);
    // storage failure not message failure
    assertThat(activemqMetrics.messagesDropped()).isZero();
    assertThat(activemqMetrics.bytes()).isEqualTo(PROTO3.encodeList(spans).length * 3);
    assertThat(activemqMetrics.spans()).isEqualTo(spans.size() * 3);
    // only one dropped
    assertThat(activemqMetrics.spansDropped()).isEqualTo(spans.size());
}
Also used : Call(zipkin2.Call) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Example 2 with Collector

use of zipkin2.collector.Collector in project zipkin by openzipkin.

the class ITRabbitMQCollector method skipsOnSpanStorageException.

/**
 * Guards against errors that leak from storage, such as InvalidQueryException
 */
@Test
void skipsOnSpanStorageException() throws Exception {
    AtomicInteger counter = new AtomicInteger();
    consumer = (input) -> new Call.Base<Void>() {

        @Override
        protected Void doExecute() {
            throw new AssertionError();
        }

        @Override
        protected void doEnqueue(Callback<Void> callback) {
            if (counter.getAndIncrement() == 1) {
                callback.onError(new RuntimeException("storage fell over"));
            } else {
                receivedSpans.add(spans);
                callback.onSuccess(null);
            }
        }

        @Override
        public Call<Void> clone() {
            throw new AssertionError();
        }
    };
    final StorageComponent storage = buildStorage(consumer);
    RabbitMQCollector.Builder builder = builder("storage_exception").storage(storage);
    produceSpans(THRIFT.encodeList(spans), builder.queue);
    // tossed on error
    produceSpans(THRIFT.encodeList(spans), builder.queue);
    produceSpans(THRIFT.encodeList(spans), builder.queue);
    try (RabbitMQCollector collector = builder.build()) {
        collector.start();
        assertThat(receivedSpans.take()).containsExactlyElementsOf(spans);
        // the only way we could read this, is if the malformed span was skipped.
        assertThat(receivedSpans.take()).containsExactlyElementsOf(spans);
    }
    assertThat(rabbitmqMetrics.messages()).isEqualTo(3);
    // storage failure isn't a message failure
    assertThat(rabbitmqMetrics.messagesDropped()).isZero();
    assertThat(rabbitmqMetrics.bytes()).isEqualTo(THRIFT.encodeList(spans).length * 3);
    assertThat(rabbitmqMetrics.spans()).isEqualTo(spans.size() * 3);
    // only one dropped
    assertThat(rabbitmqMetrics.spansDropped()).isEqualTo(spans.size());
}
Also used : Call(zipkin2.Call) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) StorageComponent(zipkin2.storage.StorageComponent) ForwardingStorageComponent(zipkin2.storage.ForwardingStorageComponent) Test(org.junit.jupiter.api.Test)

Example 3 with Collector

use of zipkin2.collector.Collector in project zipkin by openzipkin.

the class ITScribeCollector method normal.

@Test
void normal() throws Exception {
    // Java version of this sample code
    // https://github.com/facebookarchive/scribe/wiki/Logging-Messages
    TTransport transport = new TFramedTransport(new TSocket("localhost", server.port()));
    TProtocol protocol = new TBinaryProtocol(transport, false, false);
    Scribe.Iface client = new Scribe.Client(protocol);
    List<LogEntry> entries = TestObjects.TRACE.stream().map(ITScribeCollector::logEntry).collect(Collectors.toList());
    transport.open();
    try {
        ResultCode code = client.Log(entries);
        assertThat(code).isEqualTo(ResultCode.OK);
        code = client.Log(entries);
        assertThat(code).isEqualTo(ResultCode.OK);
    } finally {
        transport.close();
    }
    verify(collector, times(2)).accept(eq(TestObjects.TRACE), any(), eq(CommonPools.blockingTaskExecutor()));
    verify(metrics, times(2)).incrementMessages();
}
Also used : Scribe(zipkin2.collector.scribe.generated.Scribe) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) TFramedTransport(org.apache.thrift.transport.layered.TFramedTransport) TTransport(org.apache.thrift.transport.TTransport) LogEntry(zipkin2.collector.scribe.generated.LogEntry) ResultCode(zipkin2.collector.scribe.generated.ResultCode) TSocket(org.apache.thrift.transport.TSocket) Test(org.junit.jupiter.api.Test)

Example 4 with Collector

use of zipkin2.collector.Collector in project zipkin-azure by openzipkin.

the class EventHubCollectorTest method check_failsOnRuntimeException_registration.

@Test
public void check_failsOnRuntimeException_registration() {
    RuntimeException exception = new RuntimeException();
    EventHubCollector collector = new EventHubCollector(new LazyFuture() {

        @Override
        protected Future<?> compute() {
            registration.completeExceptionally(exception);
            return registration;
        }
    });
    CheckResult result = collector.check();
    assertThat(result.error()).isEqualTo(exception);
}
Also used : CheckResult(zipkin2.CheckResult) Future(java.util.concurrent.Future) CompletableFuture(java.util.concurrent.CompletableFuture) Test(org.junit.Test)

Example 5 with Collector

use of zipkin2.collector.Collector in project zipkin-azure by openzipkin.

the class EventHubCollectorTest method check_failsOnRuntimeException_registering.

@Test
public void check_failsOnRuntimeException_registering() {
    RuntimeException exception = new RuntimeException();
    EventHubCollector collector = new EventHubCollector(new LazyFuture() {

        @Override
        protected Future<?> compute() {
            throw exception;
        }
    });
    CheckResult result = collector.check();
    assertThat(result.error()).isEqualTo(exception);
}
Also used : CheckResult(zipkin2.CheckResult) Future(java.util.concurrent.Future) CompletableFuture(java.util.concurrent.CompletableFuture) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 StorageComponent (zipkin2.storage.StorageComponent)4 CompletableFuture (java.util.concurrent.CompletableFuture)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 Test (org.junit.jupiter.api.Test)3 Call (zipkin2.Call)3 Future (java.util.concurrent.Future)2 CheckResult (zipkin2.CheckResult)2 ForwardingStorageComponent (zipkin2.storage.ForwardingStorageComponent)2 CommonPools (com.linecorp.armeria.common.CommonPools)1 ServiceRequestContext (com.linecorp.armeria.server.ServiceRequestContext)1 AbstractUnsafeUnaryGrpcService (com.linecorp.armeria.server.grpc.protocol.AbstractUnsafeUnaryGrpcService)1 ArmeriaServerConfigurator (com.linecorp.armeria.spring.ArmeriaServerConfigurator)1 ByteBuf (io.netty.buffer.ByteBuf)1 Unpooled (io.netty.buffer.Unpooled)1 CompletionStage (java.util.concurrent.CompletionStage)1 Executor (java.util.concurrent.Executor)1 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)1 TProtocol (org.apache.thrift.protocol.TProtocol)1 TSocket (org.apache.thrift.transport.TSocket)1