diff --git a/communication/src/main/java/datadog/communication/ddagent/DDAgentFeaturesDiscovery.java b/communication/src/main/java/datadog/communication/ddagent/DDAgentFeaturesDiscovery.java index 02f4bd4e297..755094cc2e4 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 instanceof List)) { + 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)