Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class DDAgentFeaturesDiscovery implements DroppingPolicy {
public static final String V03_ENDPOINT = "v0.3/traces";
public static final String V04_ENDPOINT = "v0.4/traces";
public static final String V05_ENDPOINT = "v0.5/traces";
public static final String V1_ENDPOINT = "v1.0/traces";

public static final String V06_METRICS_ENDPOINT = "v0.6/stats";
public static final String V07_CONFIG_ENDPOINT = "v0.7/config";
Expand Down Expand Up @@ -107,15 +108,17 @@ public DDAgentFeaturesDiscovery(
OkHttpClient client,
Monitoring monitoring,
HttpUrl agentUrl,
boolean enableV05Traces,
String traceAgentProtocolVersion,
boolean metricsEnabled) {
this.client = client;
this.agentBaseUrl = agentUrl;
this.metricsEnabled = metricsEnabled;
this.traceEndpoints =
enableV05Traces
? new String[] {V05_ENDPOINT, V04_ENDPOINT, V03_ENDPOINT}
: new String[] {V04_ENDPOINT, V03_ENDPOINT};
"1.0".equals(traceAgentProtocolVersion)
? new String[] {V1_ENDPOINT, V05_ENDPOINT, V04_ENDPOINT, V03_ENDPOINT}
: ("0.5".equals(traceAgentProtocolVersion)
? new String[] {V05_ENDPOINT, V04_ENDPOINT, V03_ENDPOINT}
: new String[] {V04_ENDPOINT, V03_ENDPOINT});
this.discoveryTimer = monitoring.newTimer("trace.agent.discovery.time");
this.discoveryState = new State();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public DDAgentFeaturesDiscovery featuresDiscovery(Config config) {
agentHttpClient,
monitoring,
agentUrl,
config.isTraceAgentV05Enabled(),
config.getTraceAgentProtocolVersion(),
config.isTracerMetricsEnabled());

if (paused) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import static datadog.communication.ddagent.DDAgentFeaturesDiscovery.V04_ENDPOIN
import static datadog.communication.ddagent.DDAgentFeaturesDiscovery.V05_ENDPOINT
import static datadog.communication.ddagent.DDAgentFeaturesDiscovery.V06_METRICS_ENDPOINT
import static datadog.communication.ddagent.DDAgentFeaturesDiscovery.V07_CONFIG_ENDPOINT
import static datadog.communication.ddagent.DDAgentFeaturesDiscovery.V1_ENDPOINT
import static datadog.communication.http.OkHttpUtils.DATADOG_CONTAINER_ID
import static datadog.communication.http.OkHttpUtils.DATADOG_CONTAINER_TAGS_HASH

Expand Down Expand Up @@ -51,7 +52,7 @@ class DDAgentFeaturesDiscoveryTest extends DDSpecification {
def "test parse /info response"() {
setup:
OkHttpClient client = Mock(OkHttpClient)
DDAgentFeaturesDiscovery features = new DDAgentFeaturesDiscovery(client, monitoring, agentUrl, v05Enabled, true)
DDAgentFeaturesDiscovery features = new DDAgentFeaturesDiscovery(client, monitoring, agentUrl, protocol, true)

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

where:
v05Enabled | expectedTraceEndpoint
false | V04_ENDPOINT
true | V05_ENDPOINT
protocol | expectedTraceEndpoint
"0.4" | V04_ENDPOINT
"0.5" | V05_ENDPOINT
"1.0" | V1_ENDPOINT
"xxx" | V04_ENDPOINT
}

def "Should change discovery state atomically after discovery happened"() {
setup:
OkHttpClient client = Mock(OkHttpClient)
DDAgentFeaturesDiscovery features = new DDAgentFeaturesDiscovery(client, monitoring, agentUrl, true, true)
DDAgentFeaturesDiscovery features = new DDAgentFeaturesDiscovery(client, monitoring, agentUrl, "0.5", true)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

when: "agent version is unparseable"
features.discover()
Expand All @@ -548,7 +551,7 @@ class DDAgentFeaturesDiscoveryTest extends DDSpecification {
def "should send container id as header on the info request and parse the hash in the response"() {
setup:
OkHttpClient client = Mock(OkHttpClient)
DDAgentFeaturesDiscovery features = new DDAgentFeaturesDiscovery(client, monitoring, agentUrl, true, true)
DDAgentFeaturesDiscovery features = new DDAgentFeaturesDiscovery(client, monitoring, agentUrl, "0.5", true)
def oldContainerId = ContainerInfo.get().getContainerId()
def oldContainerTagsHash = ContainerInfo.get().getContainerTagsHash()
ContainerInfo.get().setContainerId("test")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class SharedCommunicationsObjectsSpecification extends DDSpecification {
sco.featuresDiscovery(config)

then:
1 * config.traceAgentV05Enabled >> false
1 * config.traceAgentProtocolVersion >> '0.4'
1 * config.tracerMetricsEnabled >> false
sco.featuresDiscovery != null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"/v0.4/services",
"/v0.5/traces",
"/v0.6/stats",
"/v1.0/traces",
"/profiling/v1/input",
"/v0.1/pipeline_stats",
"/evp_proxy/v1/",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public Call clone() {

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

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,10 @@ abstract class InstrumentationSpecification extends DDSpecification implements A
// emit traces to the APM Test-Agent for Cross-Tracer Testing Trace Checks
HttpUrl agentUrl = HttpUrl.get("http://" + agentHost + ":" + DEFAULT_TRACE_AGENT_PORT)
OkHttpClient client = buildHttpClient(true, null, null, TimeUnit.SECONDS.toMillis(DEFAULT_AGENT_TIMEOUT))
DDAgentFeaturesDiscovery featureDiscovery = new DDAgentFeaturesDiscovery(client, Monitoring.DISABLED, agentUrl, Config.get().isTraceAgentV05Enabled(), Config.get().isTracerMetricsEnabled())
TEST_AGENT_API = new DDAgentApi(client, agentUrl, featureDiscovery, Monitoring.DISABLED, Config.get().isTracerMetricsEnabled())

Config cfg = Config.get()
DDAgentFeaturesDiscovery featureDiscovery = new DDAgentFeaturesDiscovery(client, Monitoring.DISABLED, agentUrl, cfg.getTraceAgentProtocolVersion(), cfg.isTracerMetricsEnabled())
TEST_AGENT_API = new DDAgentApi(client, agentUrl, featureDiscovery, Monitoring.DISABLED, cfg.isTracerMetricsEnabled())
TEST_AGENT_WRITER = DDAgentWriter.builder().agentApi(TEST_AGENT_API).build()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class MockFeaturesDiscovery extends DDAgentFeaturesDiscovery {
private final boolean supportsDataStreams;

public MockFeaturesDiscovery(boolean supportsDataStreams) {
super(null, Monitoring.DISABLED, null, true, true);
super(null, Monitoring.DISABLED, null, "0.5", true);
this.supportsDataStreams = supportsDataStreams;
}

Expand Down
19 changes: 15 additions & 4 deletions dd-java-agent/src/test/java/datadog/test/SimpleAgentMock.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,23 @@ public SimpleAgentMock() {
new Dispatcher() {
@Override
public MockResponse dispatch(final RecordedRequest request) {
if ("/v0.4/traces".equals(request.getPath())) {
String path = request.getPath();
if (path != null) {
byte[] body = request.getBody().readByteArray();

DecodedMessage message = Decoder.decodeV04(body);
for (DecodedTrace trace : message.getTraces()) {
spans.addAll(trace.getSpans());
DecodedMessage message = null;
if (path.startsWith("/v1.0/traces")) {
message = Decoder.decodeV1(body);
} else if (path.startsWith("/v0.5/traces")) {
message = Decoder.decodeV05(body);
} else if (path.startsWith("/v0.4/traces")) {
message = Decoder.decodeV04(body);
}

if (message != null) {
for (DecodedTrace trace : message.getTraces()) {
spans.addAll(trace.getSpans());
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ abstract class AbstractSmokeTest extends ProcessManager {
def body = request.getBody()
if (body.length && decode) {
try {
DecodedMessage message = Decoder.decode(body)
DecodedMessage message = Decoder.decodeV05(body)
assert message.getTraces().size() == count
def traces = message.traces
decode(traces)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ public final class ConfigDefaults {
static final List<String> DEFAULT_TRACE_BAGGAGE_TAG_KEYS =
Arrays.asList("user.id", "session.id", "account.id");
static final boolean DEFAULT_JMX_FETCH_ENABLED = true;
static final boolean DEFAULT_TRACE_AGENT_V05_ENABLED = false;

// forced to use 1.0 for testing only, rollback to "0.4" before merging to master;
static final String DEFAULT_TRACE_AGENT_PROTOCOL_VERSION = "1.0";

static final boolean DEFAULT_CLIENT_IP_ENABLED = false;

Expand Down
11 changes: 11 additions & 0 deletions dd-trace-api/src/main/java/datadog/trace/api/DDTraceId.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package datadog.trace.api;

import datadog.trace.api.internal.util.LongStringUtils;
import java.nio.ByteBuffer;

/**
* Class encapsulating the id used for TraceIds.
Expand Down Expand Up @@ -102,4 +103,14 @@ public static DDTraceId fromHex(String s) throws NumberFormatException {
* <code>0</code> for 64-bit {@link DDTraceId} only.
*/
public abstract long toHighOrderLong();

/**
* @return High-order and low-order bits as bytes array.
*/
public byte[] to128BitBytes() {
ByteBuffer buffer = ByteBuffer.allocate(16);
buffer.putLong(toHighOrderLong());
buffer.putLong(toLong());
return buffer.array();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ public final class TracerConfig {

public static final String ENABLE_TRACE_AGENT_V05 = "trace.agent.v0.5.enabled";

public static final String TRACE_AGENT_PROTOCOL_VERSION = "trace.agent.protocol.version";

public static final String CLIENT_IP_ENABLED = "trace.client-ip.enabled";

public static final String TRACE_128_BIT_TRACEID_GENERATION_ENABLED =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ static class FixedAgentFeaturesDiscovery extends DDAgentFeaturesDiscovery {

public FixedAgentFeaturesDiscovery(Set<String> peerTags, Set<String> spanKinds) {
// create a fixed discovery with metrics enabled
super(null, Monitoring.DISABLED, null, false, true);
super(null, Monitoring.DISABLED, null, "0.4", true);
this.peerTags = peerTags;
this.spanKinds = spanKinds;
}
Expand Down
Loading
Loading