WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package datadog.communication.ddagent;

public class AgentVersion {

/**
* Checks if the given version string represents a version that is at least the specified major,
* minor, and patch version.
*
* @param version the version string to check (e.g., "7.65.0")
* @param minMajor minimum major version
* @param minMinor minimum minor version
* @param minPatch minimum patch version
* @return true if version is at least the specified minimum, false otherwise (including when
* version is null or unparseable)
*/
public static boolean isVersionAtLeast(String version, int minMajor, int minMinor, int minPatch) {
if (version == null || version.isEmpty()) {
return false;
}

try {
// Parse version string in format "major.minor.patch" (e.g., "7.65.0")
int majorDot = version.indexOf('.');
if (majorDot == -1) {
return false;
}

int major = Integer.parseInt(version.substring(0, majorDot));

if (major > minMajor) {
return true;
} else if (major < minMajor) {
return false;
}

// major == minMajor
int minorDot = version.indexOf('.', majorDot + 1);
if (minorDot == -1) {
return false;
}

int minor = Integer.parseInt(version.substring(majorDot + 1, minorDot));
if (minor > minMinor) {
return true;
} else if (minor < minMinor) {
return false;
}

// major == minMajor && minor == minMinor
// Find end of patch version (may have suffix like "-rc.1")
int patchEnd = minorDot + 1;
while (patchEnd < version.length() && Character.isDigit(version.charAt(patchEnd))) {
patchEnd++;
}

int patch = Integer.parseInt(version.substring(minorDot + 1, patchEnd));
return patch >= minPatch;
} catch (NumberFormatException | IndexOutOfBoundsException e) {
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ private static class State {
String dataStreamsEndpoint;
boolean supportsLongRunning;
boolean supportsDropping;
boolean supportsClientSideStats;
String state;
String configEndpoint;
String debuggerLogEndpoint;
Expand Down Expand Up @@ -306,6 +307,8 @@ private boolean processInfoResponse(State newState, String response) {
Boolean.TRUE.equals(map.getOrDefault("long_running_spans", false));

if (metricsEnabled) {
newState.supportsClientSideStats =
AgentVersion.isVersionAtLeast(newState.version, 7, 65, 0);
Object canDrop = map.get("client_drop_p0s");
newState.supportsDropping =
null != canDrop
Expand Down Expand Up @@ -358,7 +361,8 @@ private static void discoverStatsDPort(final Map<String, Object> info) {
public boolean supportsMetrics() {
return metricsEnabled
&& null != discoveryState.metricsEndpoint
&& discoveryState.supportsDropping;
&& discoveryState.supportsDropping
&& discoveryState.supportsClientSideStats;
}

public boolean supportsDebugger() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,67 @@ 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)

when: "agent version is below 7.65"
features.discover()

then:
1 * client.newCall(_) >> { Request request ->
def response = """
{
"version": "${version}",
"endpoints": ["/v0.5/traces", "/v0.6/stats"],
"client_drop_p0s": true,
"config": {}
}
"""
infoResponse(request, response)
}
features.getMetricsEndpoint() == V6_METRICS_ENDPOINT
features.supportsDropping() == true
features.supportsMetrics() == expected

where:
version | expected
"7.64.0" | false
"7.64.9" | false
"7.64.9-rc.1" | false
"7.65.0" | true
"7.65.1" | true
"7.70.0" | true
"8.0.0" | true
}

def "test metrics disabled for agent with unparseable version"() {
setup:
OkHttpClient client = Mock(OkHttpClient)
DDAgentFeaturesDiscovery features = new DDAgentFeaturesDiscovery(client, monitoring, agentUrl, true, true)

when: "agent version is unparseable"
features.discover()

then:
1 * client.newCall(_) >> { Request request ->
def response = """
{
"version": "${version}",
"endpoints": ["/v0.5/traces", "/v0.6/stats"],
"client_drop_p0s": true,
"config": {}
}
"""
infoResponse(request, response)
}
!features.supportsMetrics()

where:
version << ["invalid", "7", "7.65", "", null]
}

def "should send container id as header on the info request and parse the hash in the response"() {
setup:
OkHttpClient client = Mock(OkHttpClient)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.99.0",
"version": "7.65.0",
"git_commit": "fab047e10",
"build_date": "2020-12-04 15:57:06.74187 +0200 EET m=+0.029001792",
"endpoints": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class MetricsReliabilityTest extends DDCoreSpecification {
httpServer {
handlers {
get("/info") {
final def res = '{"endpoints":[' + (state.agentMetricsAvailable ? '"/v0.6/stats", ' : '') + '"/v0.4/traces"], "client_drop_p0s" : true}'
final def res = '{"version":"7.65.0","endpoints":[' + (state.agentMetricsAvailable ? '"/v0.6/stats", ' : '') + '"/v0.4/traces"], "client_drop_p0s" : true}'
state.hash = Strings.sha256(res)
response.send(res)
state.latch.countDown()
Expand Down
Loading