Skip to content

Commit 899c81e

Browse files
Update endpoints payload
1 parent 45e6107 commit 899c81e

File tree

8 files changed

+51
-31
lines changed

8 files changed

+51
-31
lines changed

dd-java-agent/instrumentation/spring-webmvc-3.1/src/main/java/datadog/trace/instrumentation/springweb/RequestMappingInfoIterator.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class RequestMappingInfoIterator implements Iterator<Endpoint> {
2020
private final Map<RequestMappingInfo, HandlerMethod> mappings;
2121
private final Queue<Endpoint> queue = new LinkedList<>();
2222
private Iterator<Map.Entry<RequestMappingInfo, HandlerMethod>> iterator;
23+
private boolean first = true;
2324

2425
public RequestMappingInfoIterator(final Map<RequestMappingInfo, HandlerMethod> mappings) {
2526
this.mappings = mappings;
@@ -64,7 +65,7 @@ private void fetchNext() {
6465
for (final String path : nextInfo.getPatternsCondition().getPatterns()) {
6566
final List<String> methods = Method.parseMethods(nextInfo.getMethodsCondition().getMethods());
6667
for (final String method : methods) {
67-
final Endpoint endpoint =
68+
Endpoint endpoint =
6869
new Endpoint()
6970
.type(Endpoint.Type.REST)
7071
.operation(Endpoint.Operation.HTTP_REQUEST)
@@ -77,6 +78,10 @@ private void fetchNext() {
7778
metadata.put("handler", nextHandler.toString());
7879
endpoint.metadata(metadata);
7980
}
81+
if (first) {
82+
endpoint.first(true);
83+
first = false;
84+
}
8085
queue.add(endpoint);
8186
}
8287
}

dd-java-agent/instrumentation/spring-webmvc-5.3/src/main/java/datadog/trace/instrumentation/springweb/RequestMappingInfoWithPathPatternsIterator.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class RequestMappingInfoWithPathPatternsIterator implements Iterator<Endp
2323
private final Map<RequestMappingInfo, HandlerMethod> mappings;
2424
private final Queue<Endpoint> queue = new LinkedList<>();
2525
private Iterator<Map.Entry<RequestMappingInfo, HandlerMethod>> iterator;
26+
private boolean first = true;
2627

2728
public RequestMappingInfoWithPathPatternsIterator(
2829
final Map<RequestMappingInfo, HandlerMethod> mappings) {
@@ -81,6 +82,10 @@ private void fetchNext() {
8182
metadata.put("handler", nextHandler.toString());
8283
endpoint.metadata(metadata);
8384
}
85+
if (first) {
86+
endpoint.first(true);
87+
first = false;
88+
}
8489
queue.add(endpoint);
8590
}
8691
}

dd-java-agent/testing/src/main/groovy/datadog/trace/agent/test/base/HttpServerTest.groovy

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ abstract class HttpServerTest<SERVER> extends WithHttpServer<SERVER> {
462462
SECURE_SUCCESS("secure/success", 200, null),
463463

464464
SESSION_ID("session", 200, null),
465-
WEBSOCKET("websocket", 101, null)
465+
WEBSOCKET("websocket", 101, null),
466466

467467
ENDPOINT_DISCOVERY('discovery', 200, 'OK')
468468

@@ -2117,11 +2117,16 @@ abstract class HttpServerTest<SERVER> extends WithHttpServer<SERVER> {
21172117
final discovered = endpoints.findAll { it.path == ServerEndpoint.ENDPOINT_DISCOVERY.path }
21182118

21192119
then:
2120+
!endpoints.isEmpty()
2121+
endpoints.eachWithIndex { Endpoint entry, int i ->
2122+
assert entry.first == (i == 0)
2123+
}
2124+
21202125
!discovered.isEmpty()
2121-
discovered.each {
2122-
assert it.path == ServerEndpoint.ENDPOINT_DISCOVERY.path
2123-
assert it.type == Endpoint.Type.REST
2124-
assert it.operation == Endpoint.Operation.HTTP_REQUEST
2126+
discovered.eachWithIndex { endpoint, index ->
2127+
assert endpoint.path == ServerEndpoint.ENDPOINT_DISCOVERY.path
2128+
assert endpoint.type == Endpoint.Type.REST
2129+
assert endpoint.operation == Endpoint.Operation.HTTP_REQUEST
21252130
}
21262131
assertEndpointDiscovery(discovered)
21272132
}

internal-api/src/main/java/datadog/trace/api/telemetry/Endpoint.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import java.util.Set;
1212

1313
public class Endpoint {
14+
private boolean fist;
1415
private String type;
1516
private String method;
1617
private String path;
@@ -21,6 +22,15 @@ public class Endpoint {
2122
private List<String> authentication;
2223
private Map<String, String> metadata;
2324

25+
public boolean isFirst() {
26+
return fist;
27+
}
28+
29+
public Endpoint first(boolean first) {
30+
this.fist = first;
31+
return this;
32+
}
33+
2434
public String getType() {
2535
return type;
2636
}

telemetry/src/main/java/datadog/telemetry/TelemetryRequest.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,19 @@ public void writeEndpoints() {
234234
try {
235235
log.debug("Writing endpoints");
236236
requestBody.beginEndpoints();
237-
while (eventSource.hasEndpoint() && isWithinSizeLimits()) {
238-
Endpoint event = eventSource.nextEndpoint();
237+
boolean first = false;
238+
while (eventSource.hasEndpoint()) {
239+
final Endpoint event = eventSource.nextEndpoint();
240+
if (event.isFirst()) {
241+
first = true;
242+
}
239243
requestBody.writeEndpoint(event);
240244
eventSink.addEndpointEvent(event);
245+
if (!isWithinSizeLimits()) {
246+
break;
247+
}
241248
}
242-
requestBody.endEndpoints();
249+
requestBody.endEndpoints(first);
243250
} catch (IOException e) {
244251
throw new TelemetryRequestBody.SerializationException("asm-endpoints", e);
245252
}

telemetry/src/main/java/datadog/telemetry/TelemetryRequestBody.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ public void endProducts() throws IOException {
305305
}
306306

307307
public void beginEndpoints() throws IOException {
308-
beginMessageIfBatch(RequestType.ASM_ENDPOINTS);
308+
beginMessageIfBatch(RequestType.APP_ENDPOINTS);
309309
bodyWriter.name("endpoints");
310310
bodyWriter.beginArray();
311311
}
@@ -334,9 +334,10 @@ public void writeEndpoint(final Endpoint endpoint) throws IOException {
334334
bodyWriter.endObject();
335335
}
336336

337-
public void endEndpoints() throws IOException {
337+
public void endEndpoints(final boolean first) throws IOException {
338338
bodyWriter.endArray();
339-
endMessageIfBatch(RequestType.ASM_ENDPOINTS);
339+
bodyWriter.name("is_first").value(first);
340+
endMessageIfBatch(RequestType.APP_ENDPOINTS);
340341
}
341342

342343
public void writeInstallSignature(String installId, String installType, String installTime)

telemetry/src/main/java/datadog/telemetry/api/RequestType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public enum RequestType {
1313
LOGS("logs"),
1414
DISTRIBUTIONS("distributions"),
1515
MESSAGE_BATCH("message-batch"),
16-
ASM_ENDPOINTS("asm-endpoints");
16+
APP_ENDPOINTS("app-endpoints");
1717

1818
private final String value;
1919

telemetry/src/test/groovy/datadog/telemetry/TelemetryServiceSpecification.groovy

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ import datadog.trace.api.telemetry.ProductChange
1717
import datadog.trace.test.util.DDSpecification
1818
import datadog.trace.util.Strings
1919

20-
import static datadog.trace.api.telemetry.Endpoint.Type.REST
21-
2220
class TelemetryServiceSpecification extends DDSpecification {
2321
def confKeyValue = ConfigSetting.of("confkey", "confvalue", ConfigOrigin.DEFAULT)
2422
def configuration = [confkey: confKeyValue]
@@ -28,7 +26,7 @@ class TelemetryServiceSpecification extends DDSpecification {
2826
def distribution = new DistributionSeries().namespace("tracers").metric("distro").points([1, 2, 3]).tags(["tag1", "tag2"]).common(false)
2927
def logMessage = new LogMessage().message("log-message").tags("tag1:tag2").level(LogMessageLevel.DEBUG).stackTrace("stack-trace").tracerTime(32423).count(1)
3028
def productChange = new ProductChange().productType(ProductChange.ProductType.APPSEC).enabled(true)
31-
def endpoint = new Endpoint().type('REST').method("GET").operation('http.request').path("/test")
29+
def endpoint = new Endpoint().first(true).type('REST').method("GET").operation('http.request').path("/test")
3230

3331
def 'happy path without data'() {
3432
setup:
@@ -99,7 +97,7 @@ class TelemetryServiceSpecification extends DDSpecification {
9997
.assertNextMessage(RequestType.DISTRIBUTIONS).hasPayload().namespace("tracers").distributionSeries([distribution])
10098
.assertNextMessage(RequestType.LOGS).hasPayload().logs([logMessage])
10199
.assertNextMessage(RequestType.APP_PRODUCT_CHANGE).hasPayload().productChange(productChange)
102-
.assertNextMessage(RequestType.ASM_ENDPOINTS).hasPayload().endpoint(endpoint)
100+
.assertNextMessage(RequestType.APP_ENDPOINTS).hasPayload().endpoint(endpoint)
103101
.assertNoMoreMessages()
104102
testHttpClient.assertNoMoreRequests()
105103

@@ -163,7 +161,7 @@ class TelemetryServiceSpecification extends DDSpecification {
163161
.assertNextMessage(RequestType.DISTRIBUTIONS).hasPayload().namespace("tracers").distributionSeries([distribution])
164162
.assertNextMessage(RequestType.LOGS).hasPayload().logs([logMessage])
165163
.assertNextMessage(RequestType.APP_PRODUCT_CHANGE).hasPayload().productChange(productChange)
166-
.assertNextMessage(RequestType.ASM_ENDPOINTS).hasPayload().endpoint(endpoint)
164+
.assertNextMessage(RequestType.APP_ENDPOINTS).hasPayload().endpoint(endpoint)
167165
.assertNoMoreMessages()
168166
testHttpClient.assertNoMoreRequests()
169167
}
@@ -251,7 +249,7 @@ class TelemetryServiceSpecification extends DDSpecification {
251249
.assertNextMessage(RequestType.DISTRIBUTIONS).hasPayload().namespace("tracers").distributionSeries([distribution])
252250
.assertNextMessage(RequestType.LOGS).hasPayload().logs([logMessage])
253251
.assertNextMessage(RequestType.APP_PRODUCT_CHANGE).hasPayload().productChange(productChange)
254-
.assertNextMessage(RequestType.ASM_ENDPOINTS).hasPayload().endpoint(endpoint)
252+
.assertNextMessage(RequestType.APP_ENDPOINTS).hasPayload().endpoint(endpoint)
255253
.assertNoMoreMessages()
256254
testHttpClient.assertNoMoreRequests()
257255

@@ -355,18 +353,7 @@ class TelemetryServiceSpecification extends DDSpecification {
355353
.assertNextMessage(RequestType.DISTRIBUTIONS).hasPayload().namespace("tracers").distributionSeries([distribution])
356354
.assertNextMessage(RequestType.LOGS).hasPayload().logs([logMessage])
357355
.assertNextMessage(RequestType.APP_PRODUCT_CHANGE).hasPayload().productChange(productChange)
358-
.assertNextMessage(RequestType.ASM_ENDPOINTS).hasPayload().endpoint() // no endpoints fit in this request
359-
.assertNoMoreMessages()
360-
361-
when: 'sending third part of data'
362-
testHttpClient.expectRequest(TelemetryClient.Result.SUCCESS)
363-
!telemetryService.sendTelemetryEvents()
364-
365-
then:
366-
testHttpClient.assertRequestBody(RequestType.MESSAGE_BATCH)
367-
.assertBatch(2)
368-
.assertFirstMessage(RequestType.APP_HEARTBEAT).hasNoPayload()
369-
.assertNextMessage(RequestType.ASM_ENDPOINTS).hasPayload().endpoint(endpoint)
356+
.assertNextMessage(RequestType.APP_ENDPOINTS).hasPayload().endpoint(endpoint)
370357
.assertNoMoreMessages()
371358
testHttpClient.assertNoMoreRequests()
372359
}

0 commit comments

Comments
 (0)