Skip to content

Commit

Permalink
[7.x] [Test] Allow trace.id in default thread context (#76089) (#76138)
Browse files Browse the repository at this point in the history
A new trace.id header is added by #74210. It is handled almost the same
way as x-opaque-id. Specifically, it gets passed into default thread
context. This means the existing assertion should expect it in addition
to x-opaque-id.
  • Loading branch information
elasticsearchmachine authored Aug 5, 2021
1 parent e484e67 commit dd2e5a4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public List<FullHttpResponse> get(SocketAddress remoteAddress, String... uris) t
final HttpRequest httpRequest = new DefaultFullHttpRequest(HTTP_1_1, HttpMethod.GET, uris[i]);
httpRequest.headers().add(HOST, "localhost");
httpRequest.headers().add("X-Opaque-ID", String.valueOf(i));
httpRequest.headers().add("traceparent", "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01");
requests.add(httpRequest);
}
return sendRequests(remoteAddress, requests);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.elasticsearch.tasks.Task;

import java.util.Arrays;
import org.elasticsearch.core.Set;

public enum Transports {
;
Expand Down Expand Up @@ -52,7 +53,9 @@ public static boolean assertNotTransportThread(String reason) {

public static boolean assertDefaultThreadContext(ThreadContext threadContext) {
assert threadContext.getRequestHeadersOnly().isEmpty() ||
threadContext.getRequestHeadersOnly().size() == 1 && threadContext.getRequestHeadersOnly().containsKey(Task.X_OPAQUE_ID) :
threadContext.getRequestHeadersOnly().keySet().equals(Set.of(Task.X_OPAQUE_ID)) ||
threadContext.getRequestHeadersOnly().keySet().equals(Set.of(Task.TRACE_ID)) ||
threadContext.getRequestHeadersOnly().keySet().equals(Set.of(Task.X_OPAQUE_ID, Task.TRACE_ID)) :
"expected empty context but was " + threadContext.getRequestHeadersOnly() + " on " + Thread.currentThread().getName();
return true;
}
Expand Down

0 comments on commit dd2e5a4

Please sign in to comment.