Prevent DNS lookup by gRPC instrumentation (#224)

This commit is contained in:
Trask Stalnaker 2020-03-10 14:53:04 -07:00 committed by GitHub
parent e54ab56b3a
commit 0ae9ed8a48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 12 additions and 14 deletions

View File

@ -110,7 +110,7 @@ public class GrpcClientBuilderInstrumentation extends Instrumenter.Default {
@Advice.Return final ManagedChannelBuilder builder) {
final ContextStore<ManagedChannelBuilder, InetSocketAddress> contextStore =
InstrumentationContext.get(ManagedChannelBuilder.class, InetSocketAddress.class);
contextStore.put(builder, new InetSocketAddress(address, port));
contextStore.put(builder, InetSocketAddress.createUnresolved(address, port));
}
}
}

View File

@ -55,7 +55,7 @@ public class TracingClientInterceptor implements ClientInterceptor {
final Span span = TRACER.spanBuilder(methodName).setSpanKind(CLIENT).startSpan();
try (final Scope scope = TRACER.withSpan(span)) {
DECORATE.afterStart(span);
GrpcHelper.prepareSpan(span, methodName, peerAddress);
GrpcHelper.prepareSpan(span, methodName, peerAddress, false);
final ClientCall<ReqT, RespT> result;
try {

View File

@ -21,7 +21,10 @@ import java.net.InetSocketAddress;
public class GrpcHelper {
public static void prepareSpan(
final Span span, final String methodName, final InetSocketAddress peerAddress) {
final Span span,
final String methodName,
final InetSocketAddress peerAddress,
final boolean server) {
String serviceName =
"(unknown)"; // Spec says it's mandatory, so populate even if we couldn't determine it.
final int slash = methodName.indexOf('/');
@ -35,8 +38,11 @@ public class GrpcHelper {
span.setAttribute(MoreTags.RPC_SERVICE, serviceName);
if (peerAddress != null) {
span.setAttribute(MoreTags.NET_PEER_PORT, peerAddress.getPort());
span.setAttribute(MoreTags.NET_PEER_IP, peerAddress.getAddress().getHostAddress());
span.setAttribute(MoreTags.NET_PEER_NAME, peerAddress.getAddress().getHostName());
if (server) {
span.setAttribute(MoreTags.NET_PEER_IP, peerAddress.getAddress().getHostAddress());
} else {
span.setAttribute(MoreTags.NET_PEER_NAME, peerAddress.getHostName());
}
} else {
// The spec says these fields must be populated, so put some values in even if we don't have
// an address recorded.

View File

@ -64,7 +64,7 @@ public class TracingServerInterceptor implements ServerInterceptor {
final SocketAddress addr = call.getAttributes().get(Grpc.TRANSPORT_ATTR_REMOTE_ADDR);
final InetSocketAddress iAddr =
addr instanceof InetSocketAddress ? (InetSocketAddress) addr : null;
GrpcHelper.prepareSpan(span, methodName, iAddr);
GrpcHelper.prepareSpan(span, methodName, iAddr, true);
DECORATE.afterStart(span);

View File

@ -120,7 +120,6 @@ class GrpcStreamingTest extends AgentTestRunner {
"$MoreTags.RPC_SERVICE" "Greeter"
"$Tags.COMPONENT" "grpc-client"
"$MoreTags.NET_PEER_NAME" "localhost"
"$MoreTags.NET_PEER_IP" "127.0.0.1"
"$MoreTags.NET_PEER_PORT" port
"status.code" "OK"
}
@ -144,7 +143,6 @@ class GrpcStreamingTest extends AgentTestRunner {
"$MoreTags.SPAN_TYPE" SpanTypes.RPC
"$MoreTags.RPC_SERVICE" "Greeter"
"$Tags.COMPONENT" "grpc-server"
"$MoreTags.NET_PEER_NAME" "localhost"
"$MoreTags.NET_PEER_IP" "127.0.0.1"
"$MoreTags.NET_PEER_PORT" Long
"status.code" "OK"

View File

@ -85,7 +85,6 @@ class GrpcTest extends AgentTestRunner {
"$MoreTags.RPC_SERVICE" "Greeter"
"$Tags.COMPONENT" "grpc-client"
"$MoreTags.NET_PEER_NAME" "localhost"
"$MoreTags.NET_PEER_IP" "127.0.0.1"
"$MoreTags.NET_PEER_PORT" port
"status.code" "OK"
}
@ -106,7 +105,6 @@ class GrpcTest extends AgentTestRunner {
"$MoreTags.SPAN_TYPE" SpanTypes.RPC
"$MoreTags.RPC_SERVICE" "Greeter"
"$Tags.COMPONENT" "grpc-server"
"$MoreTags.NET_PEER_NAME" "localhost"
"$MoreTags.NET_PEER_IP" "127.0.0.1"
"$MoreTags.NET_PEER_PORT" Long
"status.code" "OK"
@ -166,7 +164,6 @@ class GrpcTest extends AgentTestRunner {
"status.code" "${status.code.name()}"
"status.description" description
"$MoreTags.NET_PEER_NAME" "localhost"
"$MoreTags.NET_PEER_IP" "127.0.0.1"
"$MoreTags.NET_PEER_PORT" port
}
}
@ -188,7 +185,6 @@ class GrpcTest extends AgentTestRunner {
"$MoreTags.RPC_SERVICE" "Greeter"
"status.code" "${status.code.name()}"
"status.description" description
"$MoreTags.NET_PEER_NAME" "localhost"
"$MoreTags.NET_PEER_IP" "127.0.0.1"
"$MoreTags.NET_PEER_PORT" Long
if (status.cause != null) {
@ -255,7 +251,6 @@ class GrpcTest extends AgentTestRunner {
"$Tags.COMPONENT" "grpc-client"
"status.code" "UNKNOWN"
"$MoreTags.NET_PEER_NAME" "localhost"
"$MoreTags.NET_PEER_IP" "127.0.0.1"
"$MoreTags.NET_PEER_PORT" Long
}
}
@ -275,7 +270,6 @@ class GrpcTest extends AgentTestRunner {
"$MoreTags.SPAN_TYPE" SpanTypes.RPC
"$Tags.COMPONENT" "grpc-server"
"$MoreTags.RPC_SERVICE" "Greeter"
"$MoreTags.NET_PEER_NAME" "localhost"
"$MoreTags.NET_PEER_IP" "127.0.0.1"
"$MoreTags.NET_PEER_PORT" Long
errorTags error.class, error.message