|
1 | 1 | package datadog.communication.ddagent; |
2 | 2 |
|
3 | | -import static datadog.communication.http.OkHttpUtils.DATADOG_CONTAINER_ID; |
4 | 3 | import static datadog.communication.http.OkHttpUtils.DATADOG_CONTAINER_TAGS_HASH; |
| 4 | +import static datadog.communication.http.OkHttpUtils.msgpackRequestBodyOf; |
| 5 | +import static datadog.communication.http.OkHttpUtils.prepareRequest; |
5 | 6 | import static datadog.communication.serialization.msgpack.MsgPackWriter.FIXARRAY; |
| 7 | +import static java.util.Collections.emptyMap; |
6 | 8 | import static java.util.Collections.emptySet; |
7 | 9 | import static java.util.Collections.singletonList; |
8 | 10 | import static java.util.Collections.unmodifiableSet; |
|
11 | 13 | import com.squareup.moshi.Moshi; |
12 | 14 | import com.squareup.moshi.Types; |
13 | 15 | import datadog.common.container.ContainerInfo; |
14 | | -import datadog.communication.http.OkHttpUtils; |
15 | 16 | import datadog.metrics.api.Monitoring; |
16 | 17 | import datadog.metrics.api.Recording; |
17 | 18 | import datadog.metrics.impl.statsd.DDAgentStatsDClientManager; |
@@ -151,13 +152,9 @@ private void doDiscovery(State newState) { |
151 | 152 | // 3. fallback if the endpoint couldn't be found or the response couldn't be parsed |
152 | 153 | try (Recording recording = discoveryTimer.start()) { |
153 | 154 | boolean fallback = true; |
154 | | - final Request.Builder requestBuilder = |
155 | | - new Request.Builder().url(agentBaseUrl.resolve("info").url()); |
156 | | - final String containerId = ContainerInfo.get().getContainerId(); |
157 | | - if (containerId != null) { |
158 | | - requestBuilder.header(DATADOG_CONTAINER_ID, containerId); |
159 | | - } |
160 | | - try (Response response = client.newCall(requestBuilder.build()).execute()) { |
| 155 | + final Request request = |
| 156 | + prepareRequest(agentBaseUrl.resolve("info"), emptyMap()).get().build(); |
| 157 | + try (Response response = client.newCall(request).execute()) { |
161 | 158 | if (response.isSuccessful()) { |
162 | 159 | processInfoResponseHeaders(response); |
163 | 160 | fallback = !processInfoResponse(newState, response.body().string()); |
@@ -202,11 +199,8 @@ private String probeTracesEndpoint(State newState, String[] endpoints) { |
202 | 199 | try (Response response = |
203 | 200 | client |
204 | 201 | .newCall( |
205 | | - new Request.Builder() |
206 | | - .put( |
207 | | - OkHttpUtils.msgpackRequestBodyOf( |
208 | | - singletonList(ByteBuffer.wrap(PROBE_MESSAGE)))) |
209 | | - .url(agentBaseUrl.resolve(candidate)) |
| 202 | + prepareRequest(agentBaseUrl.resolve(candidate), emptyMap()) |
| 203 | + .put(msgpackRequestBodyOf(singletonList(ByteBuffer.wrap(PROBE_MESSAGE)))) |
210 | 204 | .build()) |
211 | 205 | .execute()) { |
212 | 206 | if (response.code() != 404) { |
|
0 commit comments