Skip to content

Commit 24bfb35

Browse files
authored
Fix trace validation bug (#617)
1 parent aabc787 commit 24bfb35

File tree

2 files changed

+12
-31
lines changed

2 files changed

+12
-31
lines changed

testing/validator/src/main/java/com/amazon/aoc/services/XRayService.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,16 @@ public List<Trace> listTraceByIds(List<String> traceIdList) {
5050
}
5151

5252
// Search for traces generated within the last 60 second.
53-
public List<TraceSummary> searchTraces() {
53+
public List<TraceSummary> searchClientCallTraces(String serviceName) {
5454
Date currentDate = new Date();
5555
Date pastDate = new DateTime(currentDate).minusSeconds(SEARCH_PERIOD).toDate();
5656
GetTraceSummariesResult traceSummaryResult =
5757
awsxRay.getTraceSummaries(
58-
new GetTraceSummariesRequest().withStartTime(pastDate).withEndTime(currentDate));
58+
new GetTraceSummariesRequest()
59+
.withStartTime(pastDate)
60+
.withEndTime(currentDate)
61+
.withFilterExpression("annotation.aws_local_service = " + serviceName)
62+
.withFilterExpression("annotation.aws_local_service = \"local-root-client-call\""));
5963
return traceSummaryResult.getTraceSummaries();
6064
}
6165
}

testing/validator/src/main/java/com/amazon/aoc/validators/TraceValidator.java

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import com.amazonaws.services.xray.model.Segment;
3232
import com.amazonaws.services.xray.model.Trace;
3333
import com.amazonaws.services.xray.model.TraceSummary;
34-
import com.amazonaws.services.xray.model.ValueWithServiceIds;
3534
import com.fasterxml.jackson.core.JsonProcessingException;
3635
import com.fasterxml.jackson.databind.ObjectMapper;
3736
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
@@ -133,35 +132,13 @@ public void validate() throws Exception {
133132
private Map<String, Object> getRetrievedTrace(List<String> traceIdList) throws Exception {
134133
List<Trace> retrieveTraceList = null;
135134
// Special Case for the /client-call. The API call doesn't return the trace ID of the local root
136-
// client span,
137-
// so find traces generated within the last 60 second and search for the InternalOperation
138-
// Keyword.
135+
// client span, so find the trace by filtering traces generated within the last 60 second
136+
// with the serviceName and the local_root_client_call keyword.
139137
if (XRayService.DEFAULT_TRACE_ID.equals(traceIdList.get(0))) {
140-
List<TraceSummary> retrieveTraceLists = xrayService.searchTraces();
141-
for (TraceSummary summary : retrieveTraceLists) {
142-
try {
143-
boolean isClientCall = false;
144-
// A summary represents a trace. The trace for the local-root-client-call will have two
145-
// segments, each with their own aws_local_service key in the annotation section.
146-
// Therefore,
147-
// getAnnotations.get("aws_local_service") will return a list with two values, one from
148-
// each segment. Search in the list to find whether local-root-client-call exists.
149-
for (ValueWithServiceIds service : summary.getAnnotations().get("aws_local_service")) {
150-
if (service.getAnnotationValue().getStringValue().equals("local-root-client-call")) {
151-
isClientCall = true;
152-
break;
153-
}
154-
}
155-
156-
if (isClientCall) {
157-
List<String> traceIdLists = Collections.singletonList(summary.getId());
158-
retrieveTraceList = xrayService.listTraceByIds(traceIdLists);
159-
break;
160-
}
161-
} catch (Exception e) {
162-
// Keep iterating until the right trace is found
163-
}
164-
}
138+
List<TraceSummary> retrieveTraceLists =
139+
xrayService.searchClientCallTraces(context.getServiceName());
140+
List<String> traceIdLists = Collections.singletonList(retrieveTraceLists.get(0).getId());
141+
retrieveTraceList = xrayService.listTraceByIds(traceIdLists);
165142
} else {
166143
retrieveTraceList = xrayService.listTraceByIds(traceIdList);
167144
}

0 commit comments

Comments
 (0)