Search in sources :

Example 6 with Builder

use of zipkin2.elasticsearch.ElasticsearchStorage.Builder 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 7 with Builder

use of zipkin2.elasticsearch.ElasticsearchStorage.Builder in project zipkin by openzipkin.

the class SelectSpansAndAnnotationsTest method processAnnotationRecord_address_skipWrongKey.

@Test
public void processAnnotationRecord_address_skipWrongKey() {
    Record4<Integer, Long, String, byte[]> annotationRecord = annotationRecord(0, null, "sr", new byte[] { 1 });
    Endpoint ep = Endpoint.newBuilder().serviceName("foo").build();
    V1Span.Builder builder = V1Span.newBuilder().traceId(1).id(1);
    SelectSpansAndAnnotations.processAnnotationRecord(annotationRecord, builder, ep);
    assertThat(builder.build().binaryAnnotations()).isEmpty();
}
Also used : Endpoint(zipkin2.Endpoint) V1Span(zipkin2.v1.V1Span) Test(org.junit.Test)

Example 8 with Builder

use of zipkin2.elasticsearch.ElasticsearchStorage.Builder in project zipkin by openzipkin.

the class SelectSpansAndAnnotationsTest method processAnnotationRecord_address.

@Test
public void processAnnotationRecord_address() {
    Record4<Integer, Long, String, byte[]> annotationRecord = annotationRecord(0, null, "ca", new byte[] { 1 });
    Endpoint ep = Endpoint.newBuilder().serviceName("foo").build();
    V1Span.Builder builder = V1Span.newBuilder().traceId(1).id(1);
    SelectSpansAndAnnotations.processAnnotationRecord(annotationRecord, builder, ep);
    assertThat(builder.build().binaryAnnotations().get(0)).isEqualTo(V1BinaryAnnotation.createAddress("ca", ep));
}
Also used : Endpoint(zipkin2.Endpoint) V1Span(zipkin2.v1.V1Span) Test(org.junit.Test)

Example 9 with Builder

use of zipkin2.elasticsearch.ElasticsearchStorage.Builder in project brave by openzipkin.

the class TracingStatementInterceptor method parseServerAddress.

/**
 * MySQL exposes the host connecting to, but not the port. This attempts to get the port from the
 * JDBC URL. Ex. 5555 from {@code jdbc:mysql://localhost:5555/database}, or 3306 if absent.
 */
static void parseServerAddress(MysqlConnection connection, Span span) {
    try {
        // strip "jdbc:"
        URI url = URI.create(connection.getURL().substring(5));
        int port = url.getPort() == -1 ? 3306 : url.getPort();
        String remoteServiceName = connection.getProperties().getProperty("zipkinServiceName");
        if (remoteServiceName == null || "".equals(remoteServiceName)) {
            String databaseName = getDatabaseName(connection);
            if (databaseName != null && !databaseName.isEmpty()) {
                remoteServiceName = "mysql-" + databaseName;
            } else {
                remoteServiceName = "mysql";
            }
        }
        Endpoint.Builder builder = Endpoint.newBuilder().serviceName(remoteServiceName).port(port);
        if (!builder.parseIp(getHost(connection)))
            return;
        span.remoteEndpoint(builder.build());
    } catch (Exception e) {
    // remote address is optional
    }
}
Also used : Endpoint(zipkin2.Endpoint) URI(java.net.URI) Endpoint(zipkin2.Endpoint) SQLException(java.sql.SQLException)

Example 10 with Builder

use of zipkin2.elasticsearch.ElasticsearchStorage.Builder in project brave by openzipkin.

the class TracingInterceptor method parseServerAddress.

/**
 * This is different than default because the request does not hold the address
 */
void parseServerAddress(Connection connection, Span span) {
    if (span.isNoop())
        return;
    InetSocketAddress remoteAddress = connection.route().socketAddress();
    Endpoint.Builder builder = Endpoint.newBuilder().serviceName(remoteServiceName);
    builder.parseIp(remoteAddress.getAddress());
    builder.port(remoteAddress.getPort());
    span.remoteEndpoint(builder.build());
}
Also used : Endpoint(zipkin2.Endpoint) InetSocketAddress(java.net.InetSocketAddress)

Aggregations

Endpoint (zipkin2.Endpoint)8 Test (org.junit.Test)4 URI (java.net.URI)3 SQLException (java.sql.SQLException)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 Test (org.junit.jupiter.api.Test)3 Call (zipkin2.Call)3 HttpRequestWriter (com.linecorp.armeria.common.HttpRequestWriter)2 InetAddress (java.net.InetAddress)2 NetworkInterface (java.net.NetworkInterface)2 Benchmark (org.openjdk.jmh.annotations.Benchmark)2 HttpCall (zipkin2.elasticsearch.internal.client.HttpCall)2 V1Span (zipkin2.v1.V1Span)2 ClientFactory (com.linecorp.armeria.client.ClientFactory)1 ClientFactoryBuilder (com.linecorp.armeria.client.ClientFactoryBuilder)1 ClientOptions (com.linecorp.armeria.client.ClientOptions)1 ClientOptionsBuilder (com.linecorp.armeria.client.ClientOptionsBuilder)1 WebClient (com.linecorp.armeria.client.WebClient)1 WebClientBuilder (com.linecorp.armeria.client.WebClientBuilder)1 ContentPreviewingClient (com.linecorp.armeria.client.logging.ContentPreviewingClient)1