|
4 | 4 |
|
5 | 5 | import com.datadog.debugger.util.DebuggerMetrics; |
6 | 6 | import datadog.common.container.ContainerInfo; |
| 7 | +import datadog.communication.http.OkHttpUtils; |
7 | 8 | import datadog.trace.api.Config; |
8 | 9 | import datadog.trace.relocate.api.RatelimitedLogger; |
9 | 10 | import datadog.trace.util.AgentThreadFactory; |
10 | 11 | import java.io.IOException; |
11 | 12 | import java.time.Duration; |
12 | | -import java.util.Collections; |
13 | 13 | import java.util.concurrent.ExecutorService; |
14 | 14 | import java.util.concurrent.Phaser; |
15 | 15 | import java.util.concurrent.SynchronousQueue; |
|
19 | 19 | import okhttp3.Call; |
20 | 20 | import okhttp3.Callback; |
21 | 21 | import okhttp3.ConnectionPool; |
22 | | -import okhttp3.ConnectionSpec; |
23 | 22 | import okhttp3.Dispatcher; |
24 | 23 | import okhttp3.HttpUrl; |
25 | 24 | import okhttp3.MediaType; |
@@ -88,26 +87,21 @@ public BatchUploader(Config config) { |
88 | 87 | // Reusing connections causes non daemon threads to be created which causes agent to prevent app |
89 | 88 | // from exiting. See https://github.com/square/okhttp/issues/4029 for some details. |
90 | 89 | ConnectionPool connectionPool = new ConnectionPool(MAX_RUNNING_REQUESTS, 1, TimeUnit.SECONDS); |
91 | | - // Use same timeout everywhere for simplicity |
| 90 | + |
92 | 91 | Duration requestTimeout = Duration.ofSeconds(config.getDebuggerUploadTimeout()); |
93 | | - OkHttpClient.Builder clientBuilder = |
94 | | - new OkHttpClient.Builder() |
95 | | - .connectTimeout(requestTimeout) |
96 | | - .writeTimeout(requestTimeout) |
97 | | - .readTimeout(requestTimeout) |
98 | | - .callTimeout(requestTimeout) |
99 | | - .dispatcher(new Dispatcher(okHttpExecutorService)) |
100 | | - .connectionPool(connectionPool); |
101 | | - |
102 | | - if ("http".equals(urlBase.scheme())) { |
103 | | - // force clear text when using http to avoid failures for JVMs without TLS |
104 | | - // see: https://github.com/DataDog/dd-trace-java/pull/1582 |
105 | | - clientBuilder.connectionSpecs(Collections.singletonList(ConnectionSpec.CLEARTEXT)); |
106 | | - } |
107 | | - client = clientBuilder.build(); |
108 | | - client.dispatcher().setMaxRequests(MAX_RUNNING_REQUESTS); |
109 | | - // We are mainly talking to the same(ish) host so we need to raise this limit |
110 | | - client.dispatcher().setMaxRequestsPerHost(MAX_RUNNING_REQUESTS); |
| 92 | + client = |
| 93 | + OkHttpUtils.buildHttpClient( |
| 94 | + config, |
| 95 | + new Dispatcher(okHttpExecutorService), |
| 96 | + urlBase, |
| 97 | + true, /* retry */ |
| 98 | + MAX_RUNNING_REQUESTS, |
| 99 | + null, /* proxyHost */ |
| 100 | + null, /* proxyPort */ |
| 101 | + null, /* proxyUsername */ |
| 102 | + null, /* proxyPassword */ |
| 103 | + requestTimeout.toMillis()); |
| 104 | + |
111 | 105 | debuggerMetrics = DebuggerMetrics.getInstance(config); |
112 | 106 | } |
113 | 107 |
|
|
0 commit comments