Search in sources :

Example 16 with Builder

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

the class BulkRequestBenchmarks method buildAndWriteRequest_tenSpans.

@Benchmark
public HttpRequest buildAndWriteRequest_tenSpans() {
    BulkCallBuilder builder = new BulkCallBuilder(es, V6_0, "index-span");
    for (int i = 0; i < 10; i++) {
        builder.index(spanIndex, "span", CLIENT_SPAN, BulkIndexWriter.SPAN);
    }
    HttpCall.RequestSupplier supplier = builder.build().request;
    HttpRequestWriter request = HttpRequest.streaming(supplier.headers());
    supplier.writeBody(request::tryWrite);
    return request;
}
Also used : HttpCall(zipkin2.elasticsearch.internal.client.HttpCall) HttpRequestWriter(com.linecorp.armeria.common.HttpRequestWriter) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 17 with Builder

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

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

the class ElasticsearchExtension method computeStorageBuilder.

Builder computeStorageBuilder() {
    WebClientBuilder builder = WebClient.builder(baseUrl()).factory(ClientFactory.builder().useHttp2Preface(false).build());
    builder.decorator((delegate, ctx, req) -> {
        final HttpResponse response = delegate.execute(ctx, req);
        return HttpResponse.from(response.aggregate().thenApply(r -> {
            // ES will return a 'warning' response header when using deprecated api, detect this and
            // fail early so we can do something about it.
            // Example usage: https://github.com/elastic/elasticsearch/blob/3049e55f093487bb582a7e49ad624961415ba31c/x-pack/plugin/security/src/internalClusterTest/java/org/elasticsearch/integration/IndexPrivilegeIntegTests.java#L559
            final String warningHeader = r.headers().get("warning");
            if (warningHeader != null) {
                if (IGNORE_THESE_WARNINGS.stream().noneMatch(p -> p.matcher(warningHeader).find())) {
                    throw new IllegalArgumentException("Detected usage of deprecated API for request " + req.toString() + ":\n" + warningHeader);
                }
            }
            // Convert AggregatedHttpResponse back to HttpResponse.
            return r.toHttpResponse();
        }));
    });
    // com.linecorp.armeria.client.logging
    if (Boolean.parseBoolean(System.getenv("ES_DEBUG"))) {
        ClientOptionsBuilder options = ClientOptions.builder();
        LoggingClientBuilder loggingBuilder = LoggingClient.builder().requestLogLevel(LogLevel.INFO).successfulResponseLogLevel(LogLevel.INFO);
        options.decorator(loggingBuilder.newDecorator());
        options.decorator(ContentPreviewingClient.newDecorator(Integer.MAX_VALUE));
        builder.options(options.build());
    }
    WebClient client = builder.build();
    return ElasticsearchStorage.newBuilder(new ElasticsearchStorage.LazyHttpClient() {

        @Override
        public WebClient get() {
            return client;
        }

        @Override
        public void close() {
            client.endpointGroup().close();
        }

        @Override
        public String toString() {
            return client.uri().toString();
        }
    }).index("zipkin-test").flushOnWrites(true);
}
Also used : Wait(org.testcontainers.containers.wait.strategy.Wait) WebClientBuilder(com.linecorp.armeria.client.WebClientBuilder) Builder(zipkin2.elasticsearch.ElasticsearchStorage.Builder) ClientFactory(com.linecorp.armeria.client.ClientFactory) HttpResponse(com.linecorp.armeria.common.HttpResponse) LogLevel(com.linecorp.armeria.common.logging.LogLevel) Logger(org.slf4j.Logger) ContentPreviewingClient(com.linecorp.armeria.client.logging.ContentPreviewingClient) TestAbortedException(org.opentest4j.TestAbortedException) LoggerFactory(org.slf4j.LoggerFactory) ClientOptions(com.linecorp.armeria.client.ClientOptions) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) LoggingClient(com.linecorp.armeria.client.logging.LoggingClient) TestInfo(org.junit.jupiter.api.TestInfo) ElasticsearchStorage(zipkin2.elasticsearch.ElasticsearchStorage) LoggingClientBuilder(com.linecorp.armeria.client.logging.LoggingClientBuilder) IGNORE_THESE_WARNINGS(zipkin2.elasticsearch.integration.IgnoredDeprecationWarnings.IGNORE_THESE_WARNINGS) ClientOptionsBuilder(com.linecorp.armeria.client.ClientOptionsBuilder) BeforeAllCallback(org.junit.jupiter.api.extension.BeforeAllCallback) Slf4jLogConsumer(org.testcontainers.containers.output.Slf4jLogConsumer) AfterAllCallback(org.junit.jupiter.api.extension.AfterAllCallback) WebClient(com.linecorp.armeria.client.WebClient) GenericContainer(org.testcontainers.containers.GenericContainer) DockerImageName.parse(org.testcontainers.utility.DockerImageName.parse) WebClientBuilder(com.linecorp.armeria.client.WebClientBuilder) ElasticsearchStorage(zipkin2.elasticsearch.ElasticsearchStorage) HttpResponse(com.linecorp.armeria.common.HttpResponse) ClientOptionsBuilder(com.linecorp.armeria.client.ClientOptionsBuilder) WebClient(com.linecorp.armeria.client.WebClient) LoggingClientBuilder(com.linecorp.armeria.client.logging.LoggingClientBuilder)

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