Skip to content

Commit fb856c0

Browse files
Protocol v1: draft implementation
1 parent 9983d0e commit fb856c0

36 files changed

Lines changed: 3038 additions & 80 deletions

File tree

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public class DDAgentFeaturesDiscovery implements DroppingPolicy {
5050
public static final String V03_ENDPOINT = "v0.3/traces";
5151
public static final String V04_ENDPOINT = "v0.4/traces";
5252
public static final String V05_ENDPOINT = "v0.5/traces";
53+
public static final String V1_ENDPOINT = "v1.0/traces";
5354

5455
public static final String V06_METRICS_ENDPOINT = "v0.6/stats";
5556
public static final String V07_CONFIG_ENDPOINT = "v0.7/config";
@@ -107,15 +108,17 @@ public DDAgentFeaturesDiscovery(
107108
OkHttpClient client,
108109
Monitoring monitoring,
109110
HttpUrl agentUrl,
110-
boolean enableV05Traces,
111+
String traceAgentProtocolVersion,
111112
boolean metricsEnabled) {
112113
this.client = client;
113114
this.agentBaseUrl = agentUrl;
114115
this.metricsEnabled = metricsEnabled;
115116
this.traceEndpoints =
116-
enableV05Traces
117-
? new String[] {V05_ENDPOINT, V04_ENDPOINT, V03_ENDPOINT}
118-
: new String[] {V04_ENDPOINT, V03_ENDPOINT};
117+
"1.0".equals(traceAgentProtocolVersion)
118+
? new String[] {V1_ENDPOINT, V05_ENDPOINT, V04_ENDPOINT, V03_ENDPOINT}
119+
: ("0.5".equals(traceAgentProtocolVersion)
120+
? new String[] {V05_ENDPOINT, V04_ENDPOINT, V03_ENDPOINT}
121+
: new String[] {V04_ENDPOINT, V03_ENDPOINT});
119122
this.discoveryTimer = monitoring.newTimer("trace.agent.discovery.time");
120123
this.discoveryState = new State();
121124
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public DDAgentFeaturesDiscovery featuresDiscovery(Config config) {
173173
agentHttpClient,
174174
monitoring,
175175
agentUrl,
176-
config.isTraceAgentV05Enabled(),
176+
config.getTraceAgentProtocolVersion(),
177177
config.isTracerMetricsEnabled());
178178

179179
if (paused) {

communication/src/test/groovy/datadog/communication/ddagent/DDAgentFeaturesDiscoveryTest.groovy

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import static datadog.communication.ddagent.DDAgentFeaturesDiscovery.V04_ENDPOIN
55
import static datadog.communication.ddagent.DDAgentFeaturesDiscovery.V05_ENDPOINT
66
import static datadog.communication.ddagent.DDAgentFeaturesDiscovery.V06_METRICS_ENDPOINT
77
import static datadog.communication.ddagent.DDAgentFeaturesDiscovery.V07_CONFIG_ENDPOINT
8+
import static datadog.communication.ddagent.DDAgentFeaturesDiscovery.V1_ENDPOINT
89
import static datadog.communication.http.OkHttpUtils.DATADOG_CONTAINER_ID
910
import static datadog.communication.http.OkHttpUtils.DATADOG_CONTAINER_TAGS_HASH
1011

@@ -51,7 +52,7 @@ class DDAgentFeaturesDiscoveryTest extends DDSpecification {
5152
def "test parse /info response"() {
5253
setup:
5354
OkHttpClient client = Mock(OkHttpClient)
54-
DDAgentFeaturesDiscovery features = new DDAgentFeaturesDiscovery(client, monitoring, agentUrl, v05Enabled, true)
55+
DDAgentFeaturesDiscovery features = new DDAgentFeaturesDiscovery(client, monitoring, agentUrl, protocol, true)
5556

5657
when: "/info available"
5758
features.discover()
@@ -77,15 +78,17 @@ class DDAgentFeaturesDiscoveryTest extends DDSpecification {
7778
0 * _
7879

7980
where:
80-
v05Enabled | expectedTraceEndpoint
81-
false | V04_ENDPOINT
82-
true | V05_ENDPOINT
81+
protocol | expectedTraceEndpoint
82+
"0.4" | V04_ENDPOINT
83+
"0.5" | V05_ENDPOINT
84+
"1.0" | V1_ENDPOINT
85+
"xxx" | V04_ENDPOINT
8386
}
8487

8588
def "Should change discovery state atomically after discovery happened"() {
8689
setup:
8790
OkHttpClient client = Mock(OkHttpClient)
88-
DDAgentFeaturesDiscovery features = new DDAgentFeaturesDiscovery(client, monitoring, agentUrl, true, true)
91+
DDAgentFeaturesDiscovery features = new DDAgentFeaturesDiscovery(client, monitoring, agentUrl, "0.5", true)
8992

9093
when: "/info available"
9194
features.discover()
@@ -111,7 +114,7 @@ class DDAgentFeaturesDiscoveryTest extends DDSpecification {
111114
def "test parse /info response with discoverIfOutdated"() {
112115
setup:
113116
OkHttpClient client = Mock(OkHttpClient)
114-
DDAgentFeaturesDiscovery features = new DDAgentFeaturesDiscovery(client, monitoring, agentUrl, true, true)
117+
DDAgentFeaturesDiscovery features = new DDAgentFeaturesDiscovery(client, monitoring, agentUrl, "0.5", true)
115118

116119
when: "/info available"
117120
features.discoverIfOutdated()
@@ -139,7 +142,7 @@ class DDAgentFeaturesDiscoveryTest extends DDSpecification {
139142
def "test parse /info response with client dropping"() {
140143
setup:
141144
OkHttpClient client = Mock(OkHttpClient)
142-
DDAgentFeaturesDiscovery features = new DDAgentFeaturesDiscovery(client, monitoring, agentUrl, true, true)
145+
DDAgentFeaturesDiscovery features = new DDAgentFeaturesDiscovery(client, monitoring, agentUrl, "0.5", true)
143146

144147
when: "/info available"
145148
features.discover()
@@ -157,7 +160,7 @@ class DDAgentFeaturesDiscoveryTest extends DDSpecification {
157160
def "test parse /info response with data streams unavailable"() {
158161
setup:
159162
OkHttpClient client = Mock(OkHttpClient)
160-
DDAgentFeaturesDiscovery features = new DDAgentFeaturesDiscovery(client, monitoring, agentUrl, true, true)
163+
DDAgentFeaturesDiscovery features = new DDAgentFeaturesDiscovery(client, monitoring, agentUrl, "0.5", true)
161164

162165
when: "/info available"
163166
features.discover()
@@ -176,7 +179,7 @@ class DDAgentFeaturesDiscoveryTest extends DDSpecification {
176179
def "test parse /info response with long running spans available"() {
177180
setup:
178181
OkHttpClient client = Mock(OkHttpClient)
179-
DDAgentFeaturesDiscovery features = new DDAgentFeaturesDiscovery(client, monitoring, agentUrl, true, true)
182+
DDAgentFeaturesDiscovery features = new DDAgentFeaturesDiscovery(client, monitoring, agentUrl, "0.5", true)
180183

181184
when: "/info available"
182185
features.discover()
@@ -190,7 +193,7 @@ class DDAgentFeaturesDiscoveryTest extends DDSpecification {
190193
def "test fallback when /info not found"() {
191194
setup:
192195
OkHttpClient client = Mock(OkHttpClient)
193-
DDAgentFeaturesDiscovery features = new DDAgentFeaturesDiscovery(client, monitoring, agentUrl, true, true)
196+
DDAgentFeaturesDiscovery features = new DDAgentFeaturesDiscovery(client, monitoring, agentUrl, "0.5", true)
194197

195198
when: "/info unavailable"
196199
features.discover()
@@ -212,7 +215,7 @@ class DDAgentFeaturesDiscoveryTest extends DDSpecification {
212215
def "test fallback when /info not found and agent returns ok"() {
213216
setup:
214217
OkHttpClient client = Mock(OkHttpClient)
215-
DDAgentFeaturesDiscovery features = new DDAgentFeaturesDiscovery(client, monitoring, agentUrl, true, true)
218+
DDAgentFeaturesDiscovery features = new DDAgentFeaturesDiscovery(client, monitoring, agentUrl, "0.5", true)
216219

217220
when: "/info unavailable"
218221
features.discover()
@@ -232,7 +235,7 @@ class DDAgentFeaturesDiscoveryTest extends DDSpecification {
232235
def "test fallback when /info not found and v0.5 disabled"() {
233236
setup:
234237
OkHttpClient client = Mock(OkHttpClient)
235-
DDAgentFeaturesDiscovery features = new DDAgentFeaturesDiscovery(client, monitoring, agentUrl, false, true)
238+
DDAgentFeaturesDiscovery features = new DDAgentFeaturesDiscovery(client, monitoring, agentUrl, "0.4", true)
236239

237240
when: "/info unavailable"
238241
features.discover()
@@ -253,7 +256,7 @@ class DDAgentFeaturesDiscoveryTest extends DDSpecification {
253256
def "test fallback when /info not found and v0.5 unavailable agent side"() {
254257
setup:
255258
OkHttpClient client = Mock(OkHttpClient)
256-
DDAgentFeaturesDiscovery features = new DDAgentFeaturesDiscovery(client, monitoring, agentUrl, true, true)
259+
DDAgentFeaturesDiscovery features = new DDAgentFeaturesDiscovery(client, monitoring, agentUrl, "0.5", true)
257260

258261
when: "/info unavailable"
259262
features.discover()
@@ -274,7 +277,7 @@ class DDAgentFeaturesDiscoveryTest extends DDSpecification {
274277
def "test fallback on very old agent"() {
275278
setup:
276279
OkHttpClient client = Mock(OkHttpClient)
277-
DDAgentFeaturesDiscovery features = new DDAgentFeaturesDiscovery(client, monitoring, agentUrl, true, true)
280+
DDAgentFeaturesDiscovery features = new DDAgentFeaturesDiscovery(client, monitoring, agentUrl, "0.5", true)
278281

279282
when: "/info unavailable"
280283
features.discover()
@@ -296,7 +299,7 @@ class DDAgentFeaturesDiscoveryTest extends DDSpecification {
296299
def "disabling metrics disables metrics and dropping"() {
297300
setup:
298301
OkHttpClient client = Mock(OkHttpClient)
299-
DDAgentFeaturesDiscovery features = new DDAgentFeaturesDiscovery(client, monitoring, agentUrl, true, false)
302+
DDAgentFeaturesDiscovery features = new DDAgentFeaturesDiscovery(client, monitoring, agentUrl, "0.5", false)
300303

301304
when: "/info unavailable"
302305
features.discover()
@@ -332,7 +335,7 @@ class DDAgentFeaturesDiscoveryTest extends DDSpecification {
332335
def "discovery of metrics endpoint after agent upgrade enables dropping and metrics"() {
333336
setup:
334337
OkHttpClient client = Mock(OkHttpClient)
335-
DDAgentFeaturesDiscovery features = new DDAgentFeaturesDiscovery(client, monitoring, agentUrl, false, true)
338+
DDAgentFeaturesDiscovery features = new DDAgentFeaturesDiscovery(client, monitoring, agentUrl, "0.4", true)
336339

337340
when: "/info unavailable"
338341
features.discover()
@@ -360,7 +363,7 @@ class DDAgentFeaturesDiscoveryTest extends DDSpecification {
360363
def "disappearance of info endpoint after agent downgrade disables metrics and dropping"() {
361364
setup:
362365
OkHttpClient client = Mock(OkHttpClient)
363-
DDAgentFeaturesDiscovery features = new DDAgentFeaturesDiscovery(client, monitoring, agentUrl, false, true)
366+
DDAgentFeaturesDiscovery features = new DDAgentFeaturesDiscovery(client, monitoring, agentUrl, "0.4", true)
364367

365368
when: "/info available"
366369
features.discover()
@@ -389,7 +392,7 @@ class DDAgentFeaturesDiscoveryTest extends DDSpecification {
389392
def "disappearance of metrics endpoint after agent downgrade disables metrics and dropping"() {
390393
setup:
391394
OkHttpClient client = Mock(OkHttpClient)
392-
DDAgentFeaturesDiscovery features = new DDAgentFeaturesDiscovery(client, monitoring, agentUrl, false, true)
395+
DDAgentFeaturesDiscovery features = new DDAgentFeaturesDiscovery(client, monitoring, agentUrl, "0.4", true)
393396

394397
when: "/info available"
395398
features.discover()
@@ -419,7 +422,7 @@ class DDAgentFeaturesDiscoveryTest extends DDSpecification {
419422
def "test parse /info response with telemetry proxy"() {
420423
setup:
421424
OkHttpClient client = Mock(OkHttpClient)
422-
DDAgentFeaturesDiscovery features = new DDAgentFeaturesDiscovery(client, monitoring, agentUrl, true, true)
425+
DDAgentFeaturesDiscovery features = new DDAgentFeaturesDiscovery(client, monitoring, agentUrl, "0.5", true)
423426

424427
when: "/info available"
425428
features.discover()
@@ -436,7 +439,7 @@ class DDAgentFeaturesDiscoveryTest extends DDSpecification {
436439
def "test parse /info response with old EVP proxy"() {
437440
setup:
438441
OkHttpClient client = Mock(OkHttpClient)
439-
DDAgentFeaturesDiscovery features = new DDAgentFeaturesDiscovery(client, monitoring, agentUrl, true, true)
442+
DDAgentFeaturesDiscovery features = new DDAgentFeaturesDiscovery(client, monitoring, agentUrl, "0.5", true)
440443

441444
when: "/info available"
442445
features.discover()
@@ -455,7 +458,7 @@ class DDAgentFeaturesDiscoveryTest extends DDSpecification {
455458
def "test parse /info response with peer tag back propagation"() {
456459
setup:
457460
OkHttpClient client = Mock(OkHttpClient)
458-
DDAgentFeaturesDiscovery features = new DDAgentFeaturesDiscovery(client, monitoring, agentUrl, true, true)
461+
DDAgentFeaturesDiscovery features = new DDAgentFeaturesDiscovery(client, monitoring, agentUrl, "0.5", true)
459462

460463
when: "/info available"
461464
features.discover()
@@ -488,7 +491,7 @@ class DDAgentFeaturesDiscoveryTest extends DDSpecification {
488491
def "test metrics disabled for agent version below 7.65"() {
489492
setup:
490493
OkHttpClient client = Mock(OkHttpClient)
491-
DDAgentFeaturesDiscovery features = new DDAgentFeaturesDiscovery(client, monitoring, agentUrl, true, true)
494+
DDAgentFeaturesDiscovery features = new DDAgentFeaturesDiscovery(client, monitoring, agentUrl, "0.5", true)
492495

493496
when: "agent version is below 7.65"
494497
features.discover()
@@ -522,7 +525,7 @@ class DDAgentFeaturesDiscoveryTest extends DDSpecification {
522525
def "test metrics disabled for agent with unparseable version"() {
523526
setup:
524527
OkHttpClient client = Mock(OkHttpClient)
525-
DDAgentFeaturesDiscovery features = new DDAgentFeaturesDiscovery(client, monitoring, agentUrl, true, true)
528+
DDAgentFeaturesDiscovery features = new DDAgentFeaturesDiscovery(client, monitoring, agentUrl, "0.5", true)
526529

527530
when: "agent version is unparseable"
528531
features.discover()
@@ -548,7 +551,7 @@ class DDAgentFeaturesDiscoveryTest extends DDSpecification {
548551
def "should send container id as header on the info request and parse the hash in the response"() {
549552
setup:
550553
OkHttpClient client = Mock(OkHttpClient)
551-
DDAgentFeaturesDiscovery features = new DDAgentFeaturesDiscovery(client, monitoring, agentUrl, true, true)
554+
DDAgentFeaturesDiscovery features = new DDAgentFeaturesDiscovery(client, monitoring, agentUrl, "0.5", true)
552555
def oldContainerId = ContainerInfo.get().getContainerId()
553556
def oldContainerTagsHash = ContainerInfo.get().getContainerTagsHash()
554557
ContainerInfo.get().setContainerId("test")

communication/src/test/groovy/datadog/communication/ddagent/SharedCommunicationsObjectsSpecification.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class SharedCommunicationsObjectsSpecification extends DDSpecification {
3131
sco.featuresDiscovery(config)
3232

3333
then:
34-
1 * config.traceAgentV05Enabled >> false
34+
1 * config.traceAgentProtocolVersion >> '0.4'
3535
1 * config.tracerMetricsEnabled >> false
3636
sco.featuresDiscovery != null
3737

communication/src/test/resources/agent-features/agent-info.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"/v0.4/services",
1010
"/v0.5/traces",
1111
"/v0.6/stats",
12+
"/v1.0/traces",
1213
"/profiling/v1/input",
1314
"/v0.1/pipeline_stats",
1415
"/evp_proxy/v1/",

dd-java-agent/appsec/src/jmh/java/datadog/appsec/benchmark/AppSecBenchmark.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public Call clone() {
187187

188188
static class StubDDAgentFeaturesDiscovery extends DDAgentFeaturesDiscovery {
189189
public StubDDAgentFeaturesDiscovery(OkHttpClient client) {
190-
super(client, Monitoring.DISABLED, HttpUrl.get("http://localhost:8080/"), false, false);
190+
super(client, Monitoring.DISABLED, HttpUrl.get("http://localhost:8080/"), "0.4", false);
191191
}
192192

193193
@Override

dd-java-agent/instrumentation-testing/src/main/groovy/datadog/trace/agent/test/InstrumentationSpecification.groovy

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,10 @@ abstract class InstrumentationSpecification extends DDSpecification implements A
387387
// emit traces to the APM Test-Agent for Cross-Tracer Testing Trace Checks
388388
HttpUrl agentUrl = HttpUrl.get("http://" + agentHost + ":" + DEFAULT_TRACE_AGENT_PORT)
389389
OkHttpClient client = buildHttpClient(true, null, null, TimeUnit.SECONDS.toMillis(DEFAULT_AGENT_TIMEOUT))
390-
DDAgentFeaturesDiscovery featureDiscovery = new DDAgentFeaturesDiscovery(client, Monitoring.DISABLED, agentUrl, Config.get().isTraceAgentV05Enabled(), Config.get().isTracerMetricsEnabled())
391-
TEST_AGENT_API = new DDAgentApi(client, agentUrl, featureDiscovery, Monitoring.DISABLED, Config.get().isTracerMetricsEnabled())
390+
391+
Config cfg = Config.get()
392+
DDAgentFeaturesDiscovery featureDiscovery = new DDAgentFeaturesDiscovery(client, Monitoring.DISABLED, agentUrl, cfg.getTraceAgentProtocolVersion(), cfg.isTracerMetricsEnabled())
393+
TEST_AGENT_API = new DDAgentApi(client, agentUrl, featureDiscovery, Monitoring.DISABLED, cfg.isTracerMetricsEnabled())
392394
TEST_AGENT_WRITER = DDAgentWriter.builder().agentApi(TEST_AGENT_API).build()
393395
}
394396

dd-java-agent/instrumentation-testing/src/main/groovy/datadog/trace/agent/test/datastreams/MockFeaturesDiscovery.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class MockFeaturesDiscovery extends DDAgentFeaturesDiscovery {
88
private final boolean supportsDataStreams;
99

1010
public MockFeaturesDiscovery(boolean supportsDataStreams) {
11-
super(null, Monitoring.DISABLED, null, true, true);
11+
super(null, Monitoring.DISABLED, null, "0.5", true);
1212
this.supportsDataStreams = supportsDataStreams;
1313
}
1414

dd-trace-api/src/main/java/datadog/trace/api/ConfigDefaults.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ public final class ConfigDefaults {
8989
static final List<String> DEFAULT_TRACE_BAGGAGE_TAG_KEYS =
9090
Arrays.asList("user.id", "session.id", "account.id");
9191
static final boolean DEFAULT_JMX_FETCH_ENABLED = true;
92-
static final boolean DEFAULT_TRACE_AGENT_V05_ENABLED = false;
92+
93+
static final String DEFAULT_TRACE_AGENT_PROTOCOL_VERSION = "0.4";
9394

9495
static final boolean DEFAULT_CLIENT_IP_ENABLED = false;
9596

dd-trace-api/src/main/java/datadog/trace/api/DDTraceId.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package datadog.trace.api;
22

33
import datadog.trace.api.internal.util.LongStringUtils;
4+
import java.nio.ByteBuffer;
45

56
/**
67
* Class encapsulating the id used for TraceIds.
@@ -102,4 +103,14 @@ public static DDTraceId fromHex(String s) throws NumberFormatException {
102103
* <code>0</code> for 64-bit {@link DDTraceId} only.
103104
*/
104105
public abstract long toHighOrderLong();
106+
107+
/**
108+
* @return High-order and low-order bits as bytes array.
109+
*/
110+
public byte[] to128BitBytes() {
111+
ByteBuffer buffer = ByteBuffer.allocate(16);
112+
buffer.putLong(toHighOrderLong());
113+
buffer.putLong(toLong());
114+
return buffer.array();
115+
}
105116
}

0 commit comments

Comments
 (0)