Skip to content

Commit 930b2a6

Browse files
amarzialidevflow.devflow-routing-intake
andauthored
Handle the case the info response does not contains endpoints / empty (#10838)
Handle the case the info response does not contains endpoints / empty suggestions Merge branch 'master' into andrea.marziali/info-npe Merge branch 'master' into andrea.marziali/info-npe Co-authored-by: devflow.devflow-routing-intake <devflow.devflow-routing-intake@kubernetes.us1.ddbuild.io>
1 parent c8e410d commit 930b2a6

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,14 @@ private void processInfoResponseHeaders(Response response) {
231231
private boolean processInfoResponse(State newState, String response) {
232232
try {
233233
Map<String, Object> map = RESPONSE_ADAPTER.fromJson(response);
234+
final Object endpointObj = map.get("endpoints");
235+
if (!(endpointObj instanceof List)) {
236+
log.debug("Bad response received from the agent. Ignoring it.");
237+
return false;
238+
}
234239
discoverStatsDPort(map);
235240
newState.version = (String) map.get("version");
236-
Set<String> endpoints = new HashSet<>((List<String>) map.get("endpoints"));
241+
Set<String> endpoints = new HashSet<>((List<String>) endpointObj);
237242

238243
String foundMetricsEndpoint = null;
239244
if (metricsEnabled) {

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,28 @@ class DDAgentFeaturesDiscoveryTest extends DDSpecification {
187187
0 * _
188188
}
189189

190+
def "test fallback when /info empty"() {
191+
setup:
192+
OkHttpClient client = Mock(OkHttpClient)
193+
DDAgentFeaturesDiscovery features = new DDAgentFeaturesDiscovery(client, monitoring, agentUrl, false, true)
194+
195+
when: "/info is empty"
196+
features.discover()
197+
198+
then:
199+
1 * client.newCall({ Request request -> request.url().toString() == "http://localhost:8125/info" }) >> { Request request -> infoResponse(request, "{}") }
200+
0 * client.newCall({ Request request -> request.url().toString() == "http://localhost:8125/v0.6/stats" }) >> { Request request -> clientError(request) }
201+
0 * client.newCall({ Request request -> request.url().toString() == "http://localhost:8125/v0.5/traces" }) >> { Request request -> success(request) }
202+
1 * client.newCall({ Request request -> request.url().toString() == "http://localhost:8125/v0.4/traces" }) >> { Request request -> success(request) }
203+
0 * client.newCall({ Request request -> request.url().toString() == "http://localhost:8125/v0.3/traces" }) >> { Request request -> success(request) }
204+
features.getMetricsEndpoint() == null
205+
!features.supportsMetrics()
206+
features.getTraceEndpoint() == V04_ENDPOINT
207+
!features.supportsLongRunning()
208+
features.state() == PROBE_STATE
209+
0 * _
210+
}
211+
190212
def "test fallback when /info not found"() {
191213
setup:
192214
OkHttpClient client = Mock(OkHttpClient)

0 commit comments

Comments
 (0)