Skip to content

Commit 8a31509

Browse files
committed
wip
1 parent 274d144 commit 8a31509

File tree

4 files changed

+210
-39
lines changed

4 files changed

+210
-39
lines changed

communication/src/main/java/datadog/communication/ddagent/DDAgentFeaturesDiscovery.java

Lines changed: 205 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,198 @@ private static class State {
9797
String telemetryProxyEndpoint;
9898
Set<String> peerTags = emptySet();
9999
long lastTimeDiscovered;
100+
101+
public String getTraceEndpoint() {
102+
return traceEndpoint;
103+
}
104+
105+
public String getMetricsEndpoint() {
106+
return metricsEndpoint;
107+
}
108+
109+
public String getDataStreamsEndpoint() {
110+
return dataStreamsEndpoint;
111+
}
112+
113+
public boolean isSupportsLongRunning() {
114+
return supportsLongRunning;
115+
}
116+
117+
public boolean isSupportsDropping() {
118+
return supportsDropping;
119+
}
120+
121+
public String getState() {
122+
return state;
123+
}
124+
125+
public String getConfigEndpoint() {
126+
return configEndpoint;
127+
}
128+
129+
public String getDebuggerLogEndpoint() {
130+
return debuggerLogEndpoint;
131+
}
132+
133+
public String getDebuggerSnapshotEndpoint() {
134+
return debuggerSnapshotEndpoint;
135+
}
136+
137+
public String getDebuggerDiagnosticsEndpoint() {
138+
return debuggerDiagnosticsEndpoint;
139+
}
140+
141+
public String getEvpProxyEndpoint() {
142+
return evpProxyEndpoint;
143+
}
144+
145+
public String getVersion() {
146+
return version;
147+
}
148+
149+
public String getTelemetryProxyEndpoint() {
150+
return telemetryProxyEndpoint;
151+
}
152+
153+
public Set<String> getPeerTags() {
154+
return peerTags;
155+
}
156+
157+
public long getLastTimeDiscovered() {
158+
return lastTimeDiscovered;
159+
}
160+
161+
void allowIO() {}
162+
}
163+
164+
private class UndiscoveredState extends State {
165+
private boolean ioAllowed;
166+
167+
public UndiscoveredState(boolean ioAllowed) {
168+
this.ioAllowed = ioAllowed;
169+
}
170+
171+
@Override
172+
void allowIO() {
173+
this.ioAllowed = true;
174+
}
175+
176+
private void doDiscovery() {
177+
if (ioAllowed) {
178+
DDAgentFeaturesDiscovery.this.discoverIfOutdated();
179+
}
180+
}
181+
182+
@Override
183+
public String getTraceEndpoint() {
184+
doDiscovery();
185+
return DDAgentFeaturesDiscovery.this.discoveryState.getTraceEndpoint();
186+
}
187+
188+
@Override
189+
public String getMetricsEndpoint() {
190+
doDiscovery();
191+
return DDAgentFeaturesDiscovery.this.discoveryState.getMetricsEndpoint();
192+
}
193+
194+
@Override
195+
public String getDataStreamsEndpoint() {
196+
doDiscovery();
197+
return DDAgentFeaturesDiscovery.this.discoveryState.getDataStreamsEndpoint();
198+
}
199+
200+
@Override
201+
public boolean isSupportsLongRunning() {
202+
doDiscovery();
203+
return DDAgentFeaturesDiscovery.this.discoveryState.isSupportsLongRunning();
204+
}
205+
206+
@Override
207+
public boolean isSupportsDropping() {
208+
doDiscovery();
209+
return DDAgentFeaturesDiscovery.this.discoveryState.isSupportsDropping();
210+
}
211+
212+
@Override
213+
public String getState() {
214+
doDiscovery();
215+
return DDAgentFeaturesDiscovery.this.discoveryState.getState();
216+
}
217+
218+
@Override
219+
public String getConfigEndpoint() {
220+
doDiscovery();
221+
return DDAgentFeaturesDiscovery.this.discoveryState.getConfigEndpoint();
222+
}
223+
224+
@Override
225+
public String getDebuggerLogEndpoint() {
226+
doDiscovery();
227+
return DDAgentFeaturesDiscovery.this.discoveryState.getDebuggerLogEndpoint();
228+
}
229+
230+
@Override
231+
public String getDebuggerSnapshotEndpoint() {
232+
doDiscovery();
233+
return DDAgentFeaturesDiscovery.this.discoveryState.getDebuggerSnapshotEndpoint();
234+
}
235+
236+
@Override
237+
public String getDebuggerDiagnosticsEndpoint() {
238+
doDiscovery();
239+
return DDAgentFeaturesDiscovery.this.discoveryState.getDebuggerDiagnosticsEndpoint();
240+
}
241+
242+
@Override
243+
public String getEvpProxyEndpoint() {
244+
doDiscovery();
245+
return DDAgentFeaturesDiscovery.this.discoveryState.getEvpProxyEndpoint();
246+
}
247+
248+
@Override
249+
public String getVersion() {
250+
doDiscovery();
251+
return DDAgentFeaturesDiscovery.this.discoveryState.getVersion();
252+
}
253+
254+
@Override
255+
public String getTelemetryProxyEndpoint() {
256+
doDiscovery();
257+
return DDAgentFeaturesDiscovery.this.discoveryState.getTelemetryProxyEndpoint();
258+
}
259+
260+
@Override
261+
public Set<String> getPeerTags() {
262+
doDiscovery();
263+
return DDAgentFeaturesDiscovery.this.discoveryState.getPeerTags();
264+
}
265+
266+
@Override
267+
public long getLastTimeDiscovered() {
268+
doDiscovery();
269+
return DDAgentFeaturesDiscovery.this.discoveryState.getLastTimeDiscovered();
270+
}
100271
}
101272

102273
private volatile State discoveryState;
103274

104-
public DDAgentFeaturesDiscovery(
275+
// kept for testing
276+
protected DDAgentFeaturesDiscovery(
105277
OkHttpClient client,
106278
Monitoring monitoring,
107279
HttpUrl agentUrl,
108280
boolean enableV05Traces,
109281
boolean metricsEnabled) {
282+
this(client, monitoring, agentUrl, enableV05Traces, metricsEnabled, true);
283+
}
284+
285+
public DDAgentFeaturesDiscovery(
286+
OkHttpClient client,
287+
Monitoring monitoring,
288+
HttpUrl agentUrl,
289+
boolean enableV05Traces,
290+
boolean metricsEnabled,
291+
boolean ioAllowed) {
110292
this.client = client;
111293
this.agentBaseUrl = agentUrl;
112294
this.metricsEnabled = metricsEnabled;
@@ -115,7 +297,7 @@ public DDAgentFeaturesDiscovery(
115297
? new String[] {V5_ENDPOINT, V4_ENDPOINT, V3_ENDPOINT}
116298
: new String[] {V4_ENDPOINT, V3_ENDPOINT};
117299
this.discoveryTimer = monitoring.newTimer("trace.agent.discovery.time");
118-
this.discoveryState = new State();
300+
this.discoveryState = new UndiscoveredState(ioAllowed);
119301
}
120302

121303
/** Run feature discovery, unconditionally. */
@@ -145,6 +327,7 @@ private synchronized void discoverIfOutdated(final long maxElapsedMs) {
145327
}
146328

147329
private void doDiscovery(State newState) {
330+
discoveryState.allowIO();
148331
// 1. try to fetch info about the agent, if the endpoint is there
149332
// 2. try to parse the response, if it can be parsed, finish
150333
// 3. fallback if the endpoint couldn't be found or the response couldn't be parsed
@@ -356,93 +539,93 @@ private static void discoverStatsDPort(final Map<String, Object> info) {
356539
}
357540

358541
public boolean supportsMetrics() {
359-
return metricsEnabled && null != discoveryState.metricsEndpoint;
542+
return metricsEnabled && null != discoveryState.getMetricsEndpoint();
360543
}
361544

362545
public boolean supportsDebugger() {
363-
return discoveryState.debuggerLogEndpoint != null;
546+
return discoveryState.getDebuggerLogEndpoint() != null;
364547
}
365548

366549
public String getDebuggerSnapshotEndpoint() {
367-
return discoveryState.debuggerSnapshotEndpoint;
550+
return discoveryState.getDebuggerSnapshotEndpoint();
368551
}
369552

370553
public String getDebuggerLogEndpoint() {
371-
return discoveryState.debuggerLogEndpoint;
554+
return discoveryState.getDebuggerLogEndpoint();
372555
}
373556

374557
public boolean supportsDebuggerDiagnostics() {
375-
return discoveryState.debuggerDiagnosticsEndpoint != null;
558+
return discoveryState.getDebuggerDiagnosticsEndpoint() != null;
376559
}
377560

378561
public boolean supportsDropping() {
379-
return discoveryState.supportsDropping;
562+
return discoveryState.isSupportsDropping();
380563
}
381564

382565
public boolean supportsLongRunning() {
383-
return discoveryState.supportsLongRunning;
566+
return discoveryState.isSupportsLongRunning();
384567
}
385568

386569
public Set<String> peerTags() {
387-
return discoveryState.peerTags;
570+
return discoveryState.getPeerTags();
388571
}
389572

390573
public String getMetricsEndpoint() {
391-
return discoveryState.metricsEndpoint;
574+
return discoveryState.getMetricsEndpoint();
392575
}
393576

394577
public String getTraceEndpoint() {
395-
return discoveryState.traceEndpoint;
578+
return discoveryState.getTraceEndpoint();
396579
}
397580

398581
public String getDataStreamsEndpoint() {
399-
return discoveryState.dataStreamsEndpoint;
582+
return discoveryState.getDataStreamsEndpoint();
400583
}
401584

402585
public String getEvpProxyEndpoint() {
403-
return discoveryState.evpProxyEndpoint;
586+
return discoveryState.getEvpProxyEndpoint();
404587
}
405588

406589
public HttpUrl buildUrl(String endpoint) {
407590
return agentBaseUrl.resolve(endpoint);
408591
}
409592

410593
public boolean supportsDataStreams() {
411-
return discoveryState.dataStreamsEndpoint != null;
594+
return discoveryState.getDataStreamsEndpoint() != null;
412595
}
413596

414597
public boolean supportsEvpProxy() {
415-
return discoveryState.evpProxyEndpoint != null;
598+
return discoveryState.getEvpProxyEndpoint() != null;
416599
}
417600

418601
public boolean supportsContentEncodingHeadersWithEvpProxy() {
419602
// content encoding headers are supported in /v4 and above
420-
final String evpProxyEndpoint = discoveryState.evpProxyEndpoint;
603+
final String evpProxyEndpoint = discoveryState.getEvpProxyEndpoint();
421604
return evpProxyEndpoint != null && V4_EVP_PROXY_ENDPOINT.compareTo(evpProxyEndpoint) <= 0;
422605
}
423606

424607
public String getConfigEndpoint() {
425-
return discoveryState.configEndpoint;
608+
return discoveryState.getConfigEndpoint();
426609
}
427610

428611
public String getVersion() {
429-
return discoveryState.version;
612+
return discoveryState.getVersion();
430613
}
431614

432615
private void errorQueryingEndpoint(String endpoint, Throwable t) {
433616
log.debug(LogCollector.EXCLUDE_TELEMETRY, "Error querying {} at {}", endpoint, agentBaseUrl, t);
434617
}
435618

436619
public String state() {
437-
return discoveryState.state;
620+
return discoveryState.getState();
438621
}
439622

440623
@Override
441624
public boolean active() {
442-
return supportsMetrics() && discoveryState.supportsDropping;
625+
return supportsMetrics() && discoveryState.isSupportsLongRunning();
443626
}
444627

445628
public boolean supportsTelemetryProxy() {
446-
return discoveryState.telemetryProxyEndpoint != null;
629+
return discoveryState.getTelemetryProxyEndpoint() != null;
447630
}
448631
}

communication/src/main/java/datadog/communication/ddagent/SharedCommunicationObjects.java

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package datadog.communication.ddagent;
22

33
import static datadog.communication.ddagent.TracerVersion.TRACER_VERSION;
4-
import static datadog.trace.util.AgentThreadFactory.AGENT_THREAD_GROUP;
54

65
import datadog.common.container.ContainerInfo;
76
import datadog.common.socket.SocketUtils;
@@ -10,7 +9,6 @@
109
import datadog.remoteconfig.ConfigurationPoller;
1110
import datadog.remoteconfig.DefaultConfigurationPoller;
1211
import datadog.trace.api.Config;
13-
import datadog.trace.util.AgentTaskScheduler;
1412
import java.security.Security;
1513
import java.util.ArrayList;
1614
import java.util.List;
@@ -78,7 +76,7 @@ public void resume() {
7876
paused = false;
7977
// attempt discovery first to avoid potential race condition on IBM Java8
8078
if (null != featuresDiscovery) {
81-
featuresDiscovery.discoverIfOutdated();
79+
// featuresDiscovery.discoverIfOutdated();
8280
} else {
8381
Security.getProviders(); // fallback to preloading provider extensions
8482
}
@@ -150,18 +148,8 @@ public DDAgentFeaturesDiscovery featuresDiscovery(Config config) {
150148
monitoring,
151149
agentUrl,
152150
config.isTraceAgentV05Enabled(),
153-
config.isTracerMetricsEnabled());
154-
155-
if (paused) {
156-
// defer remote discovery until remote I/O is allowed
157-
} else {
158-
if (AGENT_THREAD_GROUP.equals(Thread.currentThread().getThreadGroup())) {
159-
ret.discover(); // safe to run on same thread
160-
} else {
161-
// avoid performing blocking I/O operation on application thread
162-
AgentTaskScheduler.get().execute(ret::discoverIfOutdated);
163-
}
164-
}
151+
config.isTracerMetricsEnabled(),
152+
!paused);
165153
featuresDiscovery = ret;
166154
}
167155
}

dd-trace-core/src/main/java/datadog/trace/common/writer/DDAgentWriter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public DDAgentWriter build() {
143143
if (null == featureDiscovery) {
144144
featureDiscovery =
145145
new DDAgentFeaturesDiscovery(
146-
client, monitoring, agentUrl, traceAgentV05Enabled, metricsReportingEnabled);
146+
client, monitoring, agentUrl, traceAgentV05Enabled, metricsReportingEnabled, true);
147147
}
148148
if (null == agentApi) {
149149
agentApi =

utils/config-utils/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
plugins {
22
`java-library`
3-
id("supported-config-generator")
3+
// id("supported-config-generator")
44
}
55

66
apply(from = "$rootDir/gradle/java.gradle")

0 commit comments

Comments
 (0)