Avoid constructing URI (#7293)

Resolves #6568 (Reactor Netty optimization was already implemented in
#6600)
This commit is contained in:
Trask Stalnaker 2022-11-24 01:14:10 -08:00 committed by GitHub
parent 52cfafc44a
commit f9c2c80ef7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 7 deletions

View File

@ -8,7 +8,6 @@ package io.opentelemetry.instrumentation.grpc.v1_6;
import io.grpc.Metadata; import io.grpc.Metadata;
import io.grpc.MethodDescriptor; import io.grpc.MethodDescriptor;
import java.net.SocketAddress; import java.net.SocketAddress;
import java.net.URI;
import javax.annotation.Nullable; import javax.annotation.Nullable;
public final class GrpcRequest { public final class GrpcRequest {
@ -36,12 +35,16 @@ public final class GrpcRequest {
if (authority == null) { if (authority == null) {
return; return;
} }
int index = authority.indexOf(':');
if (index == -1) {
logicalHost = authority;
} else {
logicalHost = authority.substring(0, index);
try { try {
URI uri = new URI(null, authority, null, null, null); logicalPort = Integer.parseInt(authority.substring(index + 1));
logicalHost = uri.getHost(); } catch (NumberFormatException e) {
logicalPort = uri.getPort(); // ignore
} catch (Throwable e) { }
// do nothing
} }
} }