mirror of https://github.com/grpc/grpc-java.git
core,netty,okhttp: make toString more consistent for channelz (#4434)
Use MoreObjects.toStringHelper and use only the log id's long value, because the class name is already present in the toStringHelper.
This commit is contained in:
parent
b83312fb7b
commit
247a76ed93
|
|
@ -20,6 +20,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
|||
import static io.grpc.internal.GrpcUtil.TIMEOUT_KEY;
|
||||
import static java.lang.Math.max;
|
||||
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import com.google.common.util.concurrent.SettableFuture;
|
||||
import io.grpc.Attributes;
|
||||
|
|
@ -210,7 +211,10 @@ final class InProcessTransport implements ServerTransport, ConnectionClientTrans
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getLogId() + "(" + name + ")";
|
||||
return MoreObjects.toStringHelper(this)
|
||||
.add("logId", logId.getId())
|
||||
.add("name", name)
|
||||
.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import static io.grpc.ConnectivityState.SHUTDOWN;
|
|||
import static io.grpc.ConnectivityState.TRANSIENT_FAILURE;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.base.Stopwatch;
|
||||
import com.google.common.base.Supplier;
|
||||
|
|
@ -390,6 +391,20 @@ final class InternalSubchannel implements Instrumented<ChannelStats> {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
// addressGroupCopy being a little stale is fine, just avoid calling toString with the lock
|
||||
// since there may be many addresses.
|
||||
Object addressGroupCopy;
|
||||
synchronized (lock) {
|
||||
addressGroupCopy = addressGroup;
|
||||
}
|
||||
return MoreObjects.toStringHelper(this)
|
||||
.add("logId", logId.getId())
|
||||
.add("addressGroup", addressGroupCopy)
|
||||
.toString();
|
||||
}
|
||||
|
||||
@GuardedBy("lock")
|
||||
private void handleTermination() {
|
||||
channelExecutor.executeLater(new Runnable() {
|
||||
|
|
|
|||
|
|
@ -1322,7 +1322,7 @@ final class ManagedChannelImpl extends ManagedChannel implements Instrumented<Ch
|
|||
@Override
|
||||
public String toString() {
|
||||
return MoreObjects.toStringHelper(this)
|
||||
.add("logId", logId)
|
||||
.add("logId", logId.getId())
|
||||
.add("target", target)
|
||||
.toString();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ package io.grpc.internal;
|
|||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import com.google.common.util.concurrent.SettableFuture;
|
||||
|
|
@ -274,6 +275,14 @@ final class OobChannel extends ManagedChannel implements Instrumented<ChannelSta
|
|||
return logId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return MoreObjects.toStringHelper(this)
|
||||
.add("logId", logId.getId())
|
||||
.add("authority", authority)
|
||||
.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetConnectBackoff() {
|
||||
subchannel.resetConnectBackoff();
|
||||
|
|
|
|||
|
|
@ -586,7 +586,7 @@ public final class ServerImpl extends io.grpc.Server implements Instrumented<Ser
|
|||
@Override
|
||||
public String toString() {
|
||||
return MoreObjects.toStringHelper(this)
|
||||
.add("logId", logId)
|
||||
.add("logId", logId.getId())
|
||||
.add("transportServer", transportServer)
|
||||
.toString();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import static io.grpc.internal.GrpcUtil.KEEPALIVE_TIME_NANOS_DISABLED;
|
|||
import static io.netty.channel.ChannelOption.SO_KEEPALIVE;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import com.google.common.util.concurrent.SettableFuture;
|
||||
|
|
@ -298,7 +299,11 @@ class NettyClientTransport implements ConnectionClientTransport {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getLogId() + "(" + address + ")";
|
||||
return MoreObjects.toStringHelper(this)
|
||||
.add("logId", logId.getId())
|
||||
.add("address", address)
|
||||
.add("channel", channel)
|
||||
.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -308,7 +308,7 @@ class NettyServer implements InternalServer, WithLogId {
|
|||
@Override
|
||||
public String toString() {
|
||||
return MoreObjects.toStringHelper(this)
|
||||
.add("logId", logId)
|
||||
.add("logId", logId.getId())
|
||||
.add("address", address)
|
||||
.toString();
|
||||
}
|
||||
|
|
@ -392,5 +392,13 @@ class NettyServer implements InternalServer, WithLogId {
|
|||
public LogId getLogId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return MoreObjects.toStringHelper(this)
|
||||
.add("logId", id.getId())
|
||||
.add("channel", ch)
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
package io.grpc.netty;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
|
@ -234,6 +235,15 @@ class NettyServerTransport implements ServerTransport {
|
|||
channel.remoteAddress(),
|
||||
Utils.getSocketOptions(ch),
|
||||
grpcHandler == null ? null : grpcHandler.getSecurityInfo());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return MoreObjects.toStringHelper(this)
|
||||
.add("logId", logId.getId())
|
||||
.add("channel", channel)
|
||||
.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import static com.google.common.base.Preconditions.checkState;
|
|||
import static io.grpc.internal.GrpcUtil.TIMER_SERVICE;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.base.Stopwatch;
|
||||
import com.google.common.base.Supplier;
|
||||
|
|
@ -618,7 +619,10 @@ class OkHttpClientTransport implements ConnectionClientTransport {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getLogId() + "(" + address + ")";
|
||||
return MoreObjects.toStringHelper(this)
|
||||
.add("logId", logId.getId())
|
||||
.add("address", address)
|
||||
.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Reference in New Issue