Update to OkHttp 4 and use daemon threads in dispatcher. (#3946)
This commit is contained in:
parent
737a5e2b26
commit
74fb36b6cb
|
|
@ -16,6 +16,7 @@ val DEPENDENCY_BOMS = listOf(
|
||||||
"com.google.guava:guava-bom:31.0.1-jre",
|
"com.google.guava:guava-bom:31.0.1-jre",
|
||||||
"com.google.protobuf:protobuf-bom:3.18.1",
|
"com.google.protobuf:protobuf-bom:3.18.1",
|
||||||
"com.linecorp.armeria:armeria-bom:1.13.3",
|
"com.linecorp.armeria:armeria-bom:1.13.3",
|
||||||
|
"com.squareup.okhttp3:okhttp-bom:4.9.3",
|
||||||
"io.grpc:grpc-bom:1.41.0",
|
"io.grpc:grpc-bom:1.41.0",
|
||||||
"io.zipkin.brave:brave-bom:5.13.3",
|
"io.zipkin.brave:brave-bom:5.13.3",
|
||||||
"io.zipkin.reporter2:zipkin-reporter-bom:2.16.3",
|
"io.zipkin.reporter2:zipkin-reporter-bom:2.16.3",
|
||||||
|
|
@ -73,11 +74,6 @@ val DEPENDENCIES = listOf(
|
||||||
"com.google.code.findbugs:jsr305:3.0.2",
|
"com.google.code.findbugs:jsr305:3.0.2",
|
||||||
"com.google.guava:guava-beta-checker:1.0",
|
"com.google.guava:guava-beta-checker:1.0",
|
||||||
"com.lmax:disruptor:3.4.4",
|
"com.lmax:disruptor:3.4.4",
|
||||||
// using old version of okhttp to avoid pulling in kotlin stdlib
|
|
||||||
// not using (old) okhttp bom because that is pulling in old guava version
|
|
||||||
// and overriding the guava bom
|
|
||||||
"com.squareup.okhttp3:okhttp:3.14.9",
|
|
||||||
"com.squareup.okhttp3:okhttp-tls:3.14.9",
|
|
||||||
"com.sun.net.httpserver:http:20070405",
|
"com.sun.net.httpserver:http:20070405",
|
||||||
"com.tngtech.archunit:archunit-junit5:0.21.0",
|
"com.tngtech.archunit:archunit-junit5:0.21.0",
|
||||||
"com.uber.nullaway:nullaway:0.9.2",
|
"com.uber.nullaway:nullaway:0.9.2",
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import io.opentelemetry.api.metrics.MeterProvider;
|
||||||
import io.opentelemetry.exporter.otlp.internal.Marshaler;
|
import io.opentelemetry.exporter.otlp.internal.Marshaler;
|
||||||
import io.opentelemetry.exporter.otlp.internal.RetryPolicy;
|
import io.opentelemetry.exporter.otlp.internal.RetryPolicy;
|
||||||
import io.opentelemetry.exporter.otlp.internal.TlsUtil;
|
import io.opentelemetry.exporter.otlp.internal.TlsUtil;
|
||||||
|
import io.opentelemetry.exporter.otlp.internal.okhttp.OkHttpUtil;
|
||||||
import io.opentelemetry.exporter.otlp.internal.okhttp.RetryInterceptor;
|
import io.opentelemetry.exporter.otlp.internal.okhttp.RetryInterceptor;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
|
|
@ -121,7 +122,8 @@ public final class OkHttpGrpcExporterBuilder<T extends Marshaler>
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GrpcExporter<T> build() {
|
public GrpcExporter<T> build() {
|
||||||
OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder();
|
OkHttpClient.Builder clientBuilder =
|
||||||
|
new OkHttpClient.Builder().dispatcher(OkHttpUtil.newDispatcher());
|
||||||
|
|
||||||
Headers.Builder headers = this.headers != null ? this.headers : new Headers.Builder();
|
Headers.Builder headers = this.headers != null ? this.headers : new Headers.Builder();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,9 @@ public final class OkHttpExporterBuilder<T extends Marshaler> {
|
||||||
|
|
||||||
public OkHttpExporter<T> build() {
|
public OkHttpExporter<T> build() {
|
||||||
OkHttpClient.Builder clientBuilder =
|
OkHttpClient.Builder clientBuilder =
|
||||||
new OkHttpClient.Builder().callTimeout(Duration.ofNanos(timeoutNanos));
|
new OkHttpClient.Builder()
|
||||||
|
.dispatcher(OkHttpUtil.newDispatcher())
|
||||||
|
.callTimeout(Duration.ofNanos(timeoutNanos));
|
||||||
|
|
||||||
if (trustedCertificatesPem != null) {
|
if (trustedCertificatesPem != null) {
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
/*
|
||||||
|
* Copyright The OpenTelemetry Authors
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.opentelemetry.exporter.otlp.internal.okhttp;
|
||||||
|
|
||||||
|
import io.opentelemetry.sdk.internal.DaemonThreadFactory;
|
||||||
|
import java.util.concurrent.SynchronousQueue;
|
||||||
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import okhttp3.Dispatcher;
|
||||||
|
|
||||||
|
/** Utilities for OkHttp. */
|
||||||
|
public final class OkHttpUtil {
|
||||||
|
|
||||||
|
/** Returns a {@link Dispatcher} using daemon threads, otherwise matching the OkHttp default. */
|
||||||
|
public static Dispatcher newDispatcher() {
|
||||||
|
return new Dispatcher(
|
||||||
|
new ThreadPoolExecutor(
|
||||||
|
0,
|
||||||
|
Integer.MAX_VALUE,
|
||||||
|
60,
|
||||||
|
TimeUnit.SECONDS,
|
||||||
|
new SynchronousQueue<>(),
|
||||||
|
new DaemonThreadFactory("okhttp-dispatch")));
|
||||||
|
}
|
||||||
|
|
||||||
|
private OkHttpUtil() {}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue