From 1a5364b77d0f670f60bfb42cc8534fd6aa4ee105 Mon Sep 17 00:00:00 2001 From: Andrea Marziali Date: Fri, 13 Mar 2026 11:52:14 +0100 Subject: [PATCH 1/2] Handle the case the info response does not contains endpoints / empty --- .../ddagent/DDAgentFeaturesDiscovery.java | 7 +++++- .../DDAgentFeaturesDiscoveryTest.groovy | 22 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/communication/src/main/java/datadog/communication/ddagent/DDAgentFeaturesDiscovery.java b/communication/src/main/java/datadog/communication/ddagent/DDAgentFeaturesDiscovery.java index 02f4bd4e297..63c18509ac7 100644 --- a/communication/src/main/java/datadog/communication/ddagent/DDAgentFeaturesDiscovery.java +++ b/communication/src/main/java/datadog/communication/ddagent/DDAgentFeaturesDiscovery.java @@ -231,9 +231,14 @@ private void processInfoResponseHeaders(Response response) { private boolean processInfoResponse(State newState, String response) { try { Map map = RESPONSE_ADAPTER.fromJson(response); + final Object endpointObj = map.get("endpoints"); + if (endpointObj == null) { + log.debug("Bad response received from the agent. Ignoring it."); + return false; + } discoverStatsDPort(map); newState.version = (String) map.get("version"); - Set endpoints = new HashSet<>((List) map.get("endpoints")); + Set endpoints = new HashSet<>((List) endpointObj); String foundMetricsEndpoint = null; if (metricsEnabled) { diff --git a/communication/src/test/groovy/datadog/communication/ddagent/DDAgentFeaturesDiscoveryTest.groovy b/communication/src/test/groovy/datadog/communication/ddagent/DDAgentFeaturesDiscoveryTest.groovy index 21015d3c763..505595e55e7 100644 --- a/communication/src/test/groovy/datadog/communication/ddagent/DDAgentFeaturesDiscoveryTest.groovy +++ b/communication/src/test/groovy/datadog/communication/ddagent/DDAgentFeaturesDiscoveryTest.groovy @@ -187,6 +187,28 @@ class DDAgentFeaturesDiscoveryTest extends DDSpecification { 0 * _ } + def "test fallback when /info empty"() { + setup: + OkHttpClient client = Mock(OkHttpClient) + DDAgentFeaturesDiscovery features = new DDAgentFeaturesDiscovery(client, monitoring, agentUrl, false, true) + + when: "/info is empty" + features.discover() + + then: + 1 * client.newCall({ Request request -> request.url().toString() == "http://localhost:8125/info" }) >> { Request request -> infoResponse(request, "{}") } + 0 * client.newCall({ Request request -> request.url().toString() == "http://localhost:8125/v0.6/stats" }) >> { Request request -> clientError(request) } + 0 * client.newCall({ Request request -> request.url().toString() == "http://localhost:8125/v0.5/traces" }) >> { Request request -> success(request) } + 1 * client.newCall({ Request request -> request.url().toString() == "http://localhost:8125/v0.4/traces" }) >> { Request request -> success(request) } + 0 * client.newCall({ Request request -> request.url().toString() == "http://localhost:8125/v0.3/traces" }) >> { Request request -> success(request) } + features.getMetricsEndpoint() == null + !features.supportsMetrics() + features.getTraceEndpoint() == V04_ENDPOINT + !features.supportsLongRunning() + features.state() == PROBE_STATE + 0 * _ + } + def "test fallback when /info not found"() { setup: OkHttpClient client = Mock(OkHttpClient) From 6cdd956a78dc02046d8809eb859486b8c1fd2da3 Mon Sep 17 00:00:00 2001 From: Andrea Marziali Date: Fri, 13 Mar 2026 14:39:27 +0100 Subject: [PATCH 2/2] suggestions --- .../datadog/communication/ddagent/DDAgentFeaturesDiscovery.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/communication/src/main/java/datadog/communication/ddagent/DDAgentFeaturesDiscovery.java b/communication/src/main/java/datadog/communication/ddagent/DDAgentFeaturesDiscovery.java index 63c18509ac7..755094cc2e4 100644 --- a/communication/src/main/java/datadog/communication/ddagent/DDAgentFeaturesDiscovery.java +++ b/communication/src/main/java/datadog/communication/ddagent/DDAgentFeaturesDiscovery.java @@ -232,7 +232,7 @@ private boolean processInfoResponse(State newState, String response) { try { Map map = RESPONSE_ADAPTER.fromJson(response); final Object endpointObj = map.get("endpoints"); - if (endpointObj == null) { + if (!(endpointObj instanceof List)) { log.debug("Bad response received from the agent. Ignoring it."); return false; }