Search in sources :

Example 1 with ClientOptionsBuilder

use of com.linecorp.armeria.client.ClientOptionsBuilder in project zipkin by openzipkin.

the class ZipkinElasticsearchStorageConfiguration method esTracing.

@Bean
@Qualifier(QUALIFIER)
@ConditionalOnSelfTracing
Consumer<ClientOptionsBuilder> esTracing(Optional<HttpTracing> maybeHttpTracing) {
    if (!maybeHttpTracing.isPresent()) {
        // Alternatively, check why we would ever get here if ConditionalOnSelfTracing matches
        return client -> {
        };
    }
    HttpTracing httpTracing = maybeHttpTracing.get().clientOf("elasticsearch");
    SpanCustomizer spanCustomizer = CurrentSpanCustomizer.create(httpTracing.tracing());
    return client -> {
        client.decorator((delegate, ctx, req) -> {
            // We only need the name if it's available and can unsafely access the partially filled log.
            RequestLog log = ctx.log().partial();
            if (log.isAvailable(RequestLogProperty.NAME)) {
                String name = log.name();
                if (name != null) {
                    // override the span name if set
                    spanCustomizer.name(name);
                }
            }
            return delegate.execute(ctx, req);
        });
        // the tracing decorator is added last so that it encloses the attempt to overwrite the name.
        client.decorator(BraveClient.newDecorator(httpTracing));
    };
}
Also used : CurrentSpanCustomizer(brave.CurrentSpanCustomizer) SessionProtocol(com.linecorp.armeria.common.SessionProtocol) ConditionalOnSelfTracing(zipkin2.server.internal.ConditionalOnSelfTracing) SpanCustomizer(brave.SpanCustomizer) ScheduledFuture(java.util.concurrent.ScheduledFuture) BraveClient(com.linecorp.armeria.client.brave.BraveClient) RequestLog(com.linecorp.armeria.common.logging.RequestLog) Supplier(java.util.function.Supplier) ElasticsearchStorage(zipkin2.elasticsearch.ElasticsearchStorage) NamedThreadFactory(io.micrometer.core.instrument.util.NamedThreadFactory) Value(org.springframework.beans.factory.annotation.Value) ConditionContext(org.springframework.context.annotation.ConditionContext) RequestLogProperty(com.linecorp.armeria.common.logging.RequestLogProperty) EnableConfigurationProperties(org.springframework.boot.context.properties.EnableConfigurationProperties) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Qualifier(org.springframework.beans.factory.annotation.Qualifier) StorageComponent(zipkin2.storage.StorageComponent) ConditionalOnProperty(org.springframework.boot.autoconfigure.condition.ConditionalOnProperty) ClientFactoryBuilder(com.linecorp.armeria.client.ClientFactoryBuilder) HttpTracing(brave.http.HttpTracing) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Ssl(zipkin2.server.internal.elasticsearch.ZipkinElasticsearchStorageProperties.Ssl) ClientFactory(com.linecorp.armeria.client.ClientFactory) TrustManagerFactory(javax.net.ssl.TrustManagerFactory) Condition(org.springframework.context.annotation.Condition) KeyManagerFactory(javax.net.ssl.KeyManagerFactory) EndpointGroup(com.linecorp.armeria.client.endpoint.EndpointGroup) IOException(java.io.IOException) Executors(java.util.concurrent.Executors) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Configuration(org.springframework.context.annotation.Configuration) List(java.util.List) ClientOptionsBuilder(com.linecorp.armeria.client.ClientOptionsBuilder) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Optional(java.util.Optional) Bean(org.springframework.context.annotation.Bean) Conditional(org.springframework.context.annotation.Conditional) AnnotatedTypeMetadata(org.springframework.core.type.AnnotatedTypeMetadata) HttpTracing(brave.http.HttpTracing) RequestLog(com.linecorp.armeria.common.logging.RequestLog) CurrentSpanCustomizer(brave.CurrentSpanCustomizer) SpanCustomizer(brave.SpanCustomizer) ConditionalOnSelfTracing(zipkin2.server.internal.ConditionalOnSelfTracing) Qualifier(org.springframework.beans.factory.annotation.Qualifier) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 2 with ClientOptionsBuilder

use of com.linecorp.armeria.client.ClientOptionsBuilder 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

ClientFactory (com.linecorp.armeria.client.ClientFactory)2 ClientOptionsBuilder (com.linecorp.armeria.client.ClientOptionsBuilder)2 ElasticsearchStorage (zipkin2.elasticsearch.ElasticsearchStorage)2 CurrentSpanCustomizer (brave.CurrentSpanCustomizer)1 SpanCustomizer (brave.SpanCustomizer)1 HttpTracing (brave.http.HttpTracing)1 ClientFactoryBuilder (com.linecorp.armeria.client.ClientFactoryBuilder)1 ClientOptions (com.linecorp.armeria.client.ClientOptions)1 WebClient (com.linecorp.armeria.client.WebClient)1 WebClientBuilder (com.linecorp.armeria.client.WebClientBuilder)1 BraveClient (com.linecorp.armeria.client.brave.BraveClient)1 EndpointGroup (com.linecorp.armeria.client.endpoint.EndpointGroup)1 ContentPreviewingClient (com.linecorp.armeria.client.logging.ContentPreviewingClient)1 LoggingClient (com.linecorp.armeria.client.logging.LoggingClient)1 LoggingClientBuilder (com.linecorp.armeria.client.logging.LoggingClientBuilder)1 HttpResponse (com.linecorp.armeria.common.HttpResponse)1 SessionProtocol (com.linecorp.armeria.common.SessionProtocol)1 LogLevel (com.linecorp.armeria.common.logging.LogLevel)1 RequestLog (com.linecorp.armeria.common.logging.RequestLog)1 RequestLogProperty (com.linecorp.armeria.common.logging.RequestLogProperty)1