Search in sources :

Example 6 with Collector

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

the class ITKafkaCollector 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);
    KafkaCollector.Builder builder = builder("storage_exception").storage(storage);
    produceSpans(THRIFT.encodeList(spans), builder.topic);
    // tossed on error
    produceSpans(THRIFT.encodeList(spans), builder.topic);
    produceSpans(THRIFT.encodeList(spans), builder.topic);
    try (KafkaCollector 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(kafkaMetrics.messages()).isEqualTo(3);
    // storage failure isn't a message failure
    assertThat(kafkaMetrics.messagesDropped()).isZero();
    assertThat(kafkaMetrics.bytes()).isEqualTo(THRIFT.encodeList(spans).length * 3);
    assertThat(kafkaMetrics.spans()).isEqualTo(spans.size() * 3);
    // only one dropped
    assertThat(kafkaMetrics.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 7 with Collector

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

the class CollectorTest method accept_storageError.

@Test
public void accept_storageError() {
    StorageComponent storage = mock(StorageComponent.class);
    RuntimeException error = new RuntimeException("storage disabled");
    when(storage.spanConsumer()).thenThrow(error);
    collector = new Collector.Builder(LoggerFactory.getLogger("")).metrics(metrics).storage(storage).build();
    collector.accept(TRACE, callback);
    // error is async
    verify(callback).onSuccess(null);
    assertDebugLogIs("Cannot store spans [1, 2, 2, ...] due to RuntimeException(storage disabled)");
    verify(metrics).incrementSpans(4);
    verify(metrics).incrementSpansDropped(4);
}
Also used : StorageComponent(zipkin2.storage.StorageComponent) Test(org.junit.Test)

Example 8 with Collector

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

the class ZipkinGrpcCollector method grpcCollectorConfigurator.

@Bean
ArmeriaServerConfigurator grpcCollectorConfigurator(StorageComponent storage, CollectorSampler sampler, CollectorMetrics metrics) {
    CollectorMetrics grpcMetrics = metrics.forTransport("grpc");
    Collector collector = Collector.newBuilder(getClass()).storage(storage).sampler(sampler).metrics(grpcMetrics).build();
    return sb -> sb.service("/zipkin.proto3.SpanService/Report", new SpanService(collector, grpcMetrics));
}
Also used : CommonPools(com.linecorp.armeria.common.CommonPools) CollectorSampler(zipkin2.collector.CollectorSampler) SpanBytesDecoder(zipkin2.codec.SpanBytesDecoder) Collector(zipkin2.collector.Collector) AbstractUnsafeUnaryGrpcService(com.linecorp.armeria.server.grpc.protocol.AbstractUnsafeUnaryGrpcService) ArmeriaServerConfigurator(com.linecorp.armeria.spring.ArmeriaServerConfigurator) ServiceRequestContext(com.linecorp.armeria.server.ServiceRequestContext) Executor(java.util.concurrent.Executor) CompletableFuture(java.util.concurrent.CompletableFuture) Unpooled(io.netty.buffer.Unpooled) CompletionStage(java.util.concurrent.CompletionStage) ByteBuf(io.netty.buffer.ByteBuf) Callback(zipkin2.Callback) Bean(org.springframework.context.annotation.Bean) CollectorMetrics(zipkin2.collector.CollectorMetrics) StorageComponent(zipkin2.storage.StorageComponent) ConditionalOnProperty(org.springframework.boot.autoconfigure.condition.ConditionalOnProperty) Collector(zipkin2.collector.Collector) CollectorMetrics(zipkin2.collector.CollectorMetrics) Bean(org.springframework.context.annotation.Bean)

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