core: move ChannelStats and TransportStats to io.grpc.internal.Channelz (#4008)

This commit is contained in:
zpencer 2018-01-25 23:24:49 -08:00 committed by GitHub
parent 4e067eb651
commit 199a5203c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 244 additions and 346 deletions

View File

@ -1,48 +0,0 @@
/*
* Copyright 2017, gRPC Authors All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.grpc;
import javax.annotation.concurrent.Immutable;
/**
* A data class to represent a channel's stats.
*/
// Not final so that InternalChannelStats can make this class visible outside of io.grpc
@Immutable
class ChannelStats {
public final String target;
public final ConnectivityState state;
public final long callsStarted;
public final long callsSucceeded;
public final long callsFailed;
public final long lastCallStartedMillis;
ChannelStats(
String target,
ConnectivityState state,
long callsStarted,
long callsSucceeded,
long callsFailed,
long lastCallStartedMillis) {
this.target = target;
this.state = state;
this.callsStarted = callsStarted;
this.callsSucceeded = callsSucceeded;
this.callsFailed = callsFailed;
this.lastCallStartedMillis = lastCallStartedMillis;
}
}

View File

@ -1,77 +0,0 @@
/*
* Copyright 2017, gRPC Authors All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.grpc;
/**
* An internal gRPC class. Do not use.
*/
@Internal
public final class InternalChannelStats extends ChannelStats {
public InternalChannelStats(
String name,
ConnectivityState state,
long callsStarted,
long callsSucceeded,
long callsFailed,
long lastCallStartedMillis) {
super(name, state, callsStarted, callsSucceeded, callsFailed, lastCallStartedMillis);
}
public static final class Builder {
private String target;
private ConnectivityState state;
private long callsStarted;
private long callsSucceeded;
private long callsFailed;
private long lastCallStartedMillis;
public Builder setTarget(String target) {
this.target = target;
return this;
}
public Builder setState(ConnectivityState state) {
this.state = state;
return this;
}
public Builder setCallsStarted(long callsStarted) {
this.callsStarted = callsStarted;
return this;
}
public Builder setCallsSucceeded(long callsSucceeded) {
this.callsSucceeded = callsSucceeded;
return this;
}
public Builder setCallsFailed(long callsFailed) {
this.callsFailed = callsFailed;
return this;
}
public Builder setLastCallStartedMillis(long lastCallStartedMillis) {
this.lastCallStartedMillis = lastCallStartedMillis;
return this;
}
public InternalChannelStats build() {
return new InternalChannelStats(
target, state, callsStarted, callsSucceeded, callsFailed, lastCallStartedMillis);
}
}
}

View File

@ -1,54 +0,0 @@
/*
* Copyright 2017, gRPC Authors All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.grpc;
/**
* Do not use.
*
* <p>A read only copy of stats from the transport tracer.
*/
@Internal
public final class InternalTransportStats extends TransportStats {
/**
* Creates an instance.
*/
public InternalTransportStats(
long streamsStarted,
long lastStreamCreatedTimeNanos,
long streamsSucceeded,
long streamsFailed,
long messagesSent,
long messagesReceived,
long keepAlivesSent,
long lastMessageSentTimeNanos,
long lastMessageReceivedTimeNanos,
long localFlowControlWindow,
long remoteFlowControlWindow) {
super(
streamsStarted,
lastStreamCreatedTimeNanos,
streamsSucceeded,
streamsFailed,
messagesSent,
messagesReceived,
keepAlivesSent,
lastMessageSentTimeNanos,
lastMessageReceivedTimeNanos,
localFlowControlWindow,
remoteFlowControlWindow);
}
}

View File

@ -1,65 +0,0 @@
/*
* Copyright 2017, gRPC Authors All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.grpc;
import javax.annotation.concurrent.Immutable;
/**
* A data class to represent transport stats.
*/
@Immutable
class TransportStats {
public final long streamsStarted;
public final long lastStreamCreatedTimeNanos;
public final long streamsSucceeded;
public final long streamsFailed;
public final long messagesSent;
public final long messagesReceived;
public final long keepAlivesSent;
public final long lastMessageSentTimeNanos;
public final long lastMessageReceivedTimeNanos;
public final long localFlowControlWindow;
public final long remoteFlowControlWindow;
/**
* Creates an instance.
*/
public TransportStats(
long streamsStarted,
long lastStreamCreatedTimeNanos,
long streamsSucceeded,
long streamsFailed,
long messagesSent,
long messagesReceived,
long keepAlivesSent,
long lastMessageSentTimeNanos,
long lastMessageReceivedTimeNanos,
long localFlowControlWindow,
long remoteFlowControlWindow) {
this.streamsStarted = streamsStarted;
this.lastStreamCreatedTimeNanos = lastStreamCreatedTimeNanos;
this.streamsSucceeded = streamsSucceeded;
this.streamsFailed = streamsFailed;
this.messagesSent = messagesSent;
this.messagesReceived = messagesReceived;
this.keepAlivesSent = keepAlivesSent;
this.lastMessageSentTimeNanos = lastMessageSentTimeNanos;
this.lastMessageReceivedTimeNanos = lastMessageReceivedTimeNanos;
this.localFlowControlWindow = localFlowControlWindow;
this.remoteFlowControlWindow = remoteFlowControlWindow;
}
}

View File

@ -26,11 +26,11 @@ import io.grpc.Compressor;
import io.grpc.Decompressor;
import io.grpc.DecompressorRegistry;
import io.grpc.Grpc;
import io.grpc.InternalTransportStats;
import io.grpc.Metadata;
import io.grpc.MethodDescriptor;
import io.grpc.ServerStreamTracer;
import io.grpc.Status;
import io.grpc.internal.Channelz.TransportStats;
import io.grpc.internal.ClientStream;
import io.grpc.internal.ClientStreamListener;
import io.grpc.internal.ConnectionClientTransport;
@ -225,9 +225,9 @@ final class InProcessTransport implements ServerTransport, ConnectionClientTrans
}
@Override
public ListenableFuture<InternalTransportStats> getStats() {
public ListenableFuture<TransportStats> getStats() {
// TODO(zpencer): add transport tracing to in-process server
SettableFuture<InternalTransportStats> ret = SettableFuture.create();
SettableFuture<TransportStats> ret = SettableFuture.create();
ret.set(null);
return ret;
}

View File

@ -16,8 +16,8 @@
package io.grpc.internal;
import io.grpc.InternalChannelStats;
import io.grpc.LoadBalancer;
import io.grpc.internal.Channelz.ChannelStats;
import javax.annotation.Nullable;
/**
@ -25,7 +25,7 @@ import javax.annotation.Nullable;
* io.grpc.LoadBalancer.Helper#createSubchannel}.
*/
abstract class AbstractSubchannel extends LoadBalancer.Subchannel
implements Instrumented<InternalChannelStats> {
implements Instrumented<ChannelStats> {
private final LogId logId = LogId.allocate(getClass().getName());
/**

View File

@ -17,7 +17,7 @@
package io.grpc.internal;
import com.google.common.annotations.VisibleForTesting;
import io.grpc.InternalChannelStats;
import io.grpc.internal.Channelz.ChannelStats;
/**
* A collection of call stats for channelz.
@ -46,7 +46,7 @@ final class CallTracer {
}
}
void updateBuilder(InternalChannelStats.Builder builder) {
void updateBuilder(ChannelStats.Builder builder) {
builder
.setCallsStarted(callsStarted.value())
.setCallsSucceeded(callsSucceeded.value())

View File

@ -0,0 +1,144 @@
/*
* Copyright 2018, gRPC Authors All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.grpc.internal;
import io.grpc.ConnectivityState;
import javax.annotation.concurrent.Immutable;
public final class Channelz {
/**
* A data class to represent a channel's stats.
*/
@Immutable
public static final class ChannelStats {
public final String target;
public final ConnectivityState state;
public final long callsStarted;
public final long callsSucceeded;
public final long callsFailed;
public final long lastCallStartedMillis;
/**
* Creates an instance.
*/
public ChannelStats(
String target,
ConnectivityState state,
long callsStarted,
long callsSucceeded,
long callsFailed,
long lastCallStartedMillis) {
this.target = target;
this.state = state;
this.callsStarted = callsStarted;
this.callsSucceeded = callsSucceeded;
this.callsFailed = callsFailed;
this.lastCallStartedMillis = lastCallStartedMillis;
}
public static final class Builder {
private String target;
private ConnectivityState state;
private long callsStarted;
private long callsSucceeded;
private long callsFailed;
private long lastCallStartedMillis;
public Builder setTarget(String target) {
this.target = target;
return this;
}
public Builder setState(ConnectivityState state) {
this.state = state;
return this;
}
public Builder setCallsStarted(long callsStarted) {
this.callsStarted = callsStarted;
return this;
}
public Builder setCallsSucceeded(long callsSucceeded) {
this.callsSucceeded = callsSucceeded;
return this;
}
public Builder setCallsFailed(long callsFailed) {
this.callsFailed = callsFailed;
return this;
}
public Builder setLastCallStartedMillis(long lastCallStartedMillis) {
this.lastCallStartedMillis = lastCallStartedMillis;
return this;
}
public ChannelStats build() {
return new ChannelStats(
target, state, callsStarted, callsSucceeded, callsFailed, lastCallStartedMillis);
}
}
}
/**
* A data class to represent transport stats.
*/
@Immutable
public static final class TransportStats {
public final long streamsStarted;
public final long lastStreamCreatedTimeNanos;
public final long streamsSucceeded;
public final long streamsFailed;
public final long messagesSent;
public final long messagesReceived;
public final long keepAlivesSent;
public final long lastMessageSentTimeNanos;
public final long lastMessageReceivedTimeNanos;
public final long localFlowControlWindow;
public final long remoteFlowControlWindow;
/**
* Creates an instance.
*/
public TransportStats(
long streamsStarted,
long lastStreamCreatedTimeNanos,
long streamsSucceeded,
long streamsFailed,
long messagesSent,
long messagesReceived,
long keepAlivesSent,
long lastMessageSentTimeNanos,
long lastMessageReceivedTimeNanos,
long localFlowControlWindow,
long remoteFlowControlWindow) {
this.streamsStarted = streamsStarted;
this.lastStreamCreatedTimeNanos = lastStreamCreatedTimeNanos;
this.streamsSucceeded = streamsSucceeded;
this.streamsFailed = streamsFailed;
this.messagesSent = messagesSent;
this.messagesReceived = messagesReceived;
this.keepAlivesSent = keepAlivesSent;
this.lastMessageSentTimeNanos = lastMessageSentTimeNanos;
this.lastMessageReceivedTimeNanos = lastMessageReceivedTimeNanos;
this.localFlowControlWindow = localFlowControlWindow;
this.remoteFlowControlWindow = remoteFlowControlWindow;
}
}
}

View File

@ -17,9 +17,9 @@
package io.grpc.internal;
import io.grpc.CallOptions;
import io.grpc.InternalTransportStats;
import io.grpc.Metadata;
import io.grpc.MethodDescriptor;
import io.grpc.internal.Channelz.TransportStats;
import java.util.concurrent.Executor;
import javax.annotation.concurrent.ThreadSafe;
@ -30,7 +30,7 @@ import javax.annotation.concurrent.ThreadSafe;
* are expected to execute quickly.
*/
@ThreadSafe
public interface ClientTransport extends Instrumented<InternalTransportStats> {
public interface ClientTransport extends Instrumented<TransportStats> {
/**
* Creates a new stream for sending messages to a remote end-point.

View File

@ -21,13 +21,13 @@ import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.SettableFuture;
import io.grpc.CallOptions;
import io.grpc.Context;
import io.grpc.InternalTransportStats;
import io.grpc.LoadBalancer.PickResult;
import io.grpc.LoadBalancer.PickSubchannelArgs;
import io.grpc.LoadBalancer.SubchannelPicker;
import io.grpc.Metadata;
import io.grpc.MethodDescriptor;
import io.grpc.Status;
import io.grpc.internal.Channelz.TransportStats;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@ -189,8 +189,8 @@ final class DelayedClientTransport implements ManagedClientTransport {
}
@Override
public ListenableFuture<InternalTransportStats> getStats() {
SettableFuture<InternalTransportStats> ret = SettableFuture.create();
public ListenableFuture<TransportStats> getStats() {
SettableFuture<TransportStats> ret = SettableFuture.create();
ret.set(null);
return ret;
}

View File

@ -21,10 +21,10 @@ import com.google.common.base.Preconditions;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.SettableFuture;
import io.grpc.CallOptions;
import io.grpc.InternalTransportStats;
import io.grpc.Metadata;
import io.grpc.MethodDescriptor;
import io.grpc.Status;
import io.grpc.internal.Channelz.TransportStats;
import java.util.concurrent.Executor;
/**
@ -55,8 +55,8 @@ class FailingClientTransport implements ClientTransport {
}
@Override
public ListenableFuture<InternalTransportStats> getStats() {
SettableFuture<InternalTransportStats> ret = SettableFuture.create();
public ListenableFuture<TransportStats> getStats() {
SettableFuture<TransportStats> ret = SettableFuture.create();
ret.set(null);
return ret;
}

View File

@ -19,10 +19,10 @@ package io.grpc.internal;
import com.google.common.util.concurrent.ListenableFuture;
import io.grpc.Attributes;
import io.grpc.CallOptions;
import io.grpc.InternalTransportStats;
import io.grpc.Metadata;
import io.grpc.MethodDescriptor;
import io.grpc.Status;
import io.grpc.internal.Channelz.TransportStats;
import java.util.concurrent.Executor;
abstract class ForwardingConnectionClientTransport implements ConnectionClientTransport {
@ -68,7 +68,7 @@ abstract class ForwardingConnectionClientTransport implements ConnectionClientTr
}
@Override
public ListenableFuture<InternalTransportStats> getStats() {
public ListenableFuture<TransportStats> getStats() {
return delegate().getStats();
}

View File

@ -31,12 +31,12 @@ import io.grpc.CallOptions;
import io.grpc.ClientStreamTracer;
import io.grpc.InternalMetadata;
import io.grpc.InternalMetadata.TrustedAsciiMarshaller;
import io.grpc.InternalTransportStats;
import io.grpc.LoadBalancer.PickResult;
import io.grpc.LoadBalancer.Subchannel;
import io.grpc.Metadata;
import io.grpc.MethodDescriptor;
import io.grpc.Status;
import io.grpc.internal.Channelz.TransportStats;
import io.grpc.internal.SharedResourceHolder.Resource;
import io.grpc.internal.StreamListener.MessageProducer;
import java.io.IOException;
@ -688,7 +688,7 @@ public final class GrpcUtil {
}
@Override
public ListenableFuture<InternalTransportStats> getStats() {
public ListenableFuture<TransportStats> getStats() {
return transport.getStats();
}
};

View File

@ -41,7 +41,6 @@ import io.grpc.ConnectivityStateInfo;
import io.grpc.Context;
import io.grpc.DecompressorRegistry;
import io.grpc.EquivalentAddressGroup;
import io.grpc.InternalChannelStats;
import io.grpc.LoadBalancer;
import io.grpc.LoadBalancer.PickResult;
import io.grpc.LoadBalancer.PickSubchannelArgs;
@ -51,6 +50,7 @@ import io.grpc.Metadata;
import io.grpc.MethodDescriptor;
import io.grpc.NameResolver;
import io.grpc.Status;
import io.grpc.internal.Channelz.ChannelStats;
import io.grpc.internal.ClientCallImpl.ClientTransportProvider;
import io.grpc.internal.RetriableStream.ChannelBufferMeter;
import java.lang.ref.Reference;
@ -81,8 +81,7 @@ import javax.annotation.concurrent.ThreadSafe;
/** A communication channel for making outgoing RPCs. */
@ThreadSafe
public final class ManagedChannelImpl
extends ManagedChannel implements Instrumented<InternalChannelStats> {
public final class ManagedChannelImpl extends ManagedChannel implements Instrumented<ChannelStats> {
static final Logger logger = Logger.getLogger(ManagedChannelImpl.class.getName());
// Matching this pattern means the target string is a URI target or at least intended to be one.
@ -276,9 +275,9 @@ public final class ManagedChannelImpl
};
@Override
public ListenableFuture<InternalChannelStats> getStats() {
SettableFuture<InternalChannelStats> ret = SettableFuture.create();
InternalChannelStats.Builder builder = new InternalChannelStats.Builder();
public ListenableFuture<ChannelStats> getStats() {
SettableFuture<ChannelStats> ret = SettableFuture.create();
ChannelStats.Builder builder = new Channelz.ChannelStats.Builder();
channelCallTracer.updateBuilder(builder);
builder.setTarget(target).setState(channelStateManager.getState());
ret.set(builder.build());
@ -1150,9 +1149,9 @@ public final class ManagedChannelImpl
}
@Override
public ListenableFuture<InternalChannelStats> getStats() {
SettableFuture<InternalChannelStats> ret = SettableFuture.create();
InternalChannelStats.Builder builder = new InternalChannelStats.Builder();
public ListenableFuture<ChannelStats> getStats() {
SettableFuture<ChannelStats> ret = SettableFuture.create();
ChannelStats.Builder builder = new Channelz.ChannelStats.Builder();
subchannelCallTracer.updateBuilder(builder);
builder.setTarget(target).setState(subchannel.getState());
ret.set(builder.build());

View File

@ -27,7 +27,6 @@ import io.grpc.ClientCall;
import io.grpc.ConnectivityStateInfo;
import io.grpc.Context;
import io.grpc.EquivalentAddressGroup;
import io.grpc.InternalChannelStats;
import io.grpc.LoadBalancer;
import io.grpc.LoadBalancer.PickResult;
import io.grpc.LoadBalancer.PickSubchannelArgs;
@ -37,6 +36,7 @@ import io.grpc.ManagedChannel;
import io.grpc.Metadata;
import io.grpc.MethodDescriptor;
import io.grpc.Status;
import io.grpc.internal.Channelz.ChannelStats;
import io.grpc.internal.ClientCallImpl.ClientTransportProvider;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
@ -51,8 +51,7 @@ import javax.annotation.concurrent.ThreadSafe;
* to its own RPC needs.
*/
@ThreadSafe
final class OobChannel
extends ManagedChannel implements Instrumented<InternalChannelStats> {
final class OobChannel extends ManagedChannel implements Instrumented<ChannelStats> {
private static final Logger log = Logger.getLogger(OobChannel.class.getName());
private InternalSubchannel subchannel;
@ -152,9 +151,9 @@ final class OobChannel
}
@Override
public ListenableFuture<InternalChannelStats> getStats() {
SettableFuture<InternalChannelStats> ret = SettableFuture.create();
InternalChannelStats.Builder builder = new InternalChannelStats.Builder();
public ListenableFuture<ChannelStats> getStats() {
SettableFuture<ChannelStats> ret = SettableFuture.create();
ChannelStats.Builder builder = new ChannelStats.Builder();
subchannelCallsTracer.updateBuilder(builder);
builder.setTarget(authority).setState(subchannel.getState());
ret.set(builder.build());
@ -254,9 +253,9 @@ final class OobChannel
}
@Override
public ListenableFuture<InternalChannelStats> getStats() {
SettableFuture<InternalChannelStats> ret = SettableFuture.create();
InternalChannelStats.Builder builder = new InternalChannelStats.Builder();
public ListenableFuture<ChannelStats> getStats() {
SettableFuture<ChannelStats> ret = SettableFuture.create();
ChannelStats.Builder builder = new ChannelStats.Builder();
channelCallsTracer.updateBuilder(builder);
builder.setTarget(authority).setState(subchannel.getState());
ret.set(builder.build());

View File

@ -16,12 +16,12 @@
package io.grpc.internal;
import io.grpc.InternalTransportStats;
import io.grpc.Status;
import io.grpc.internal.Channelz.TransportStats;
import java.util.concurrent.ScheduledExecutorService;
/** An inbound connection. */
public interface ServerTransport extends Instrumented<InternalTransportStats> {
public interface ServerTransport extends Instrumented<TransportStats> {
/**
* Initiates an orderly shutdown of the transport. Existing streams continue, but new streams will
* eventually begin failing. New streams "eventually" begin failing because shutdown may need to

View File

@ -18,7 +18,7 @@ package io.grpc.internal;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import io.grpc.InternalTransportStats;
import io.grpc.internal.Channelz.TransportStats;
import java.util.concurrent.TimeUnit;
/**
@ -59,12 +59,12 @@ public final class TransportTracer {
/**
* Returns a read only set of current stats.
*/
public InternalTransportStats getStats() {
public TransportStats getStats() {
long localFlowControlWindow =
flowControlWindowReader == null ? -1 : flowControlWindowReader.read().localBytes;
long remoteFlowControlWindow =
flowControlWindowReader == null ? -1 : flowControlWindowReader.read().remoteBytes;
return new InternalTransportStats(
return new TransportStats(
streamsStarted,
lastStreamCreatedTimeNanos,
streamsSucceeded,

View File

@ -60,7 +60,6 @@ import io.grpc.ConnectivityStateInfo;
import io.grpc.Context;
import io.grpc.EquivalentAddressGroup;
import io.grpc.IntegerMarshaller;
import io.grpc.InternalChannelStats;
import io.grpc.LoadBalancer;
import io.grpc.LoadBalancer.Helper;
import io.grpc.LoadBalancer.PickResult;
@ -75,6 +74,7 @@ import io.grpc.NameResolver;
import io.grpc.SecurityLevel;
import io.grpc.Status;
import io.grpc.StringMarshaller;
import io.grpc.internal.Channelz.ChannelStats;
import io.grpc.internal.ManagedChannelImpl.ManagedChannelReference;
import io.grpc.internal.TestUtils.MockClientTransportInfo;
import java.net.SocketAddress;
@ -1984,8 +1984,8 @@ public class ManagedChannelImplTest {
}
}
private static InternalChannelStats getStats(
Instrumented<InternalChannelStats> instrumented) throws Exception {
private static ChannelStats getStats(
Instrumented<ChannelStats> instrumented) throws Exception {
return instrumented.getStats().get();
}
}

View File

@ -35,9 +35,9 @@ import com.google.common.base.Charsets;
import com.google.common.io.ByteStreams;
import com.google.common.primitives.Bytes;
import io.grpc.Codec;
import io.grpc.InternalTransportStats;
import io.grpc.StatusRuntimeException;
import io.grpc.StreamTracer;
import io.grpc.internal.Channelz.TransportStats;
import io.grpc.internal.MessageDeframer.Listener;
import io.grpc.internal.MessageDeframer.SizeEnforcingInputStream;
import io.grpc.internal.testing.TestStreamTracer.TestBaseStreamTracer;
@ -483,7 +483,7 @@ public class MessageDeframerTest {
* @param sizes in the format {wire0, uncompressed0, wire1, uncompressed1, ...}
*/
private static void checkStats(
TestBaseStreamTracer tracer, InternalTransportStats transportStats, long... sizes) {
TestBaseStreamTracer tracer, TransportStats transportStats, long... sizes) {
assertEquals(0, sizes.length % 2);
int count = sizes.length / 2;
long expectedWireSize = 0;

View File

@ -51,7 +51,6 @@ import io.grpc.Context;
import io.grpc.Grpc;
import io.grpc.HandlerRegistry;
import io.grpc.IntegerMarshaller;
import io.grpc.InternalTransportStats;
import io.grpc.Metadata;
import io.grpc.MethodDescriptor;
import io.grpc.ServerCall;
@ -63,6 +62,7 @@ import io.grpc.ServerTransportFilter;
import io.grpc.ServiceDescriptor;
import io.grpc.Status;
import io.grpc.StringMarshaller;
import io.grpc.internal.Channelz.TransportStats;
import io.grpc.internal.ServerImpl.JumpToApplicationThreadServerStreamListener;
import io.grpc.internal.testing.SingleMessageProducer;
import io.grpc.internal.testing.TestServerStreamTracer;
@ -1274,8 +1274,8 @@ public class ServerImplTest {
}
@Override
public ListenableFuture<InternalTransportStats> getStats() {
SettableFuture<InternalTransportStats> ret = SettableFuture.create();
public ListenableFuture<TransportStats> getStats() {
SettableFuture<TransportStats> ret = SettableFuture.create();
ret.set(null);
return ret;
}

View File

@ -26,7 +26,7 @@ import io.grpc.MethodDescriptor;
import io.grpc.Status;
import io.grpc.Status.Code;
import io.grpc.cronet.CronetChannelBuilder.StreamBuilderFactory;
import io.grpc.InternalTransportStats;
import io.grpc.internal.Channelz.TransportStats;
import io.grpc.internal.ConnectionClientTransport;
import io.grpc.internal.GrpcUtil;
import io.grpc.internal.LogId;
@ -95,8 +95,8 @@ class CronetClientTransport implements ConnectionClientTransport {
}
@Override
public ListenableFuture<InternalTransportStats> getStats() {
SettableFuture<InternalTransportStats> f = SettableFuture.create();
public ListenableFuture<TransportStats> getStats() {
SettableFuture<TransportStats> f = SettableFuture.create();
f.set(null);
return f;
}

View File

@ -25,10 +25,10 @@ import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.SettableFuture;
import io.grpc.Attributes;
import io.grpc.CallOptions;
import io.grpc.InternalTransportStats;
import io.grpc.Metadata;
import io.grpc.MethodDescriptor;
import io.grpc.Status;
import io.grpc.internal.Channelz.TransportStats;
import io.grpc.internal.ClientStream;
import io.grpc.internal.ConnectionClientTransport;
import io.grpc.internal.FailingClientStream;
@ -311,8 +311,8 @@ class NettyClientTransport implements ConnectionClientTransport {
}
@Override
public ListenableFuture<InternalTransportStats> getStats() {
final SettableFuture<InternalTransportStats> result = SettableFuture.create();
public ListenableFuture<TransportStats> getStats() {
final SettableFuture<TransportStats> result = SettableFuture.create();
if (channel.eventLoop().inEventLoop()) {
// This is necessary, otherwise we will block forever if we get the future from inside
// the event loop.

View File

@ -21,9 +21,9 @@ import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.SettableFuture;
import io.grpc.InternalTransportStats;
import io.grpc.ServerStreamTracer;
import io.grpc.Status;
import io.grpc.internal.Channelz.TransportStats;
import io.grpc.internal.LogId;
import io.grpc.internal.ServerTransport;
import io.grpc.internal.ServerTransportListener;
@ -195,8 +195,8 @@ class NettyServerTransport implements ServerTransport {
}
@Override
public ListenableFuture<InternalTransportStats> getStats() {
final SettableFuture<InternalTransportStats> result = SettableFuture.create();
public ListenableFuture<TransportStats> getStats() {
final SettableFuture<TransportStats> result = SettableFuture.create();
if (channel.eventLoop().inEventLoop()) {
// This is necessary, otherwise we will block forever if we get the future from inside
// the event loop.

View File

@ -29,7 +29,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import io.grpc.InternalTransportStats;
import io.grpc.internal.Channelz.TransportStats;
import io.grpc.internal.FakeClock;
import io.grpc.internal.MessageFramer;
import io.grpc.internal.StatsTraceContext;
@ -459,7 +459,7 @@ public abstract class NettyHandlerTestBase<T extends Http2ConnectionHandler> {
@Test
public void transportTracer_windowSizeDefault() throws Exception {
manualSetUp();
InternalTransportStats transportStats = transportTracer.getStats();
TransportStats transportStats = transportTracer.getStats();
assertEquals(Http2CodecUtil.DEFAULT_WINDOW_SIZE, transportStats.remoteFlowControlWindow);
assertEquals(flowControlWindow, transportStats.localFlowControlWindow);
}
@ -468,7 +468,7 @@ public abstract class NettyHandlerTestBase<T extends Http2ConnectionHandler> {
public void transportTracer_windowSize() throws Exception {
flowControlWindow = 1024 * 1024;
manualSetUp();
InternalTransportStats transportStats = transportTracer.getStats();
TransportStats transportStats = transportTracer.getStats();
assertEquals(Http2CodecUtil.DEFAULT_WINDOW_SIZE, transportStats.remoteFlowControlWindow);
assertEquals(flowControlWindow, transportStats.localFlowControlWindow);
}
@ -476,13 +476,13 @@ public abstract class NettyHandlerTestBase<T extends Http2ConnectionHandler> {
@Test
public void transportTracer_windowUpdate_remote() throws Exception {
manualSetUp();
InternalTransportStats before = transportTracer.getStats();
TransportStats before = transportTracer.getStats();
assertEquals(Http2CodecUtil.DEFAULT_WINDOW_SIZE, before.remoteFlowControlWindow);
assertEquals(Http2CodecUtil.DEFAULT_WINDOW_SIZE, before.localFlowControlWindow);
ByteBuf serializedSettings = windowUpdate(0, 1000);
channelRead(serializedSettings);
InternalTransportStats after = transportTracer.getStats();
TransportStats after = transportTracer.getStats();
assertEquals(Http2CodecUtil.DEFAULT_WINDOW_SIZE + 1000,
after.remoteFlowControlWindow);
assertEquals(flowControlWindow, after.localFlowControlWindow);
@ -491,7 +491,7 @@ public abstract class NettyHandlerTestBase<T extends Http2ConnectionHandler> {
@Test
public void transportTracer_windowUpdate_local() throws Exception {
manualSetUp();
InternalTransportStats before = transportTracer.getStats();
TransportStats before = transportTracer.getStats();
assertEquals(Http2CodecUtil.DEFAULT_WINDOW_SIZE, before.remoteFlowControlWindow);
assertEquals(flowControlWindow, before.localFlowControlWindow);
@ -500,7 +500,7 @@ public abstract class NettyHandlerTestBase<T extends Http2ConnectionHandler> {
connection().local().flowController().incrementWindowSize(
connection().connectionStream(), 8 * Http2CodecUtil.DEFAULT_WINDOW_SIZE);
InternalTransportStats after = transportTracer.getStats();
TransportStats after = transportTracer.getStats();
assertEquals(Http2CodecUtil.DEFAULT_WINDOW_SIZE, after.remoteFlowControlWindow);
assertEquals(flowControlWindow + 8 * Http2CodecUtil.DEFAULT_WINDOW_SIZE,
connection().local().flowController().windowSize(connection().connectionStream()));

View File

@ -31,13 +31,13 @@ import com.squareup.okhttp.Request;
import com.squareup.okhttp.internal.http.StatusLine;
import io.grpc.Attributes;
import io.grpc.CallOptions;
import io.grpc.InternalTransportStats;
import io.grpc.Metadata;
import io.grpc.MethodDescriptor;
import io.grpc.MethodDescriptor.MethodType;
import io.grpc.Status;
import io.grpc.Status.Code;
import io.grpc.StatusException;
import io.grpc.internal.Channelz.TransportStats;
import io.grpc.internal.ConnectionClientTransport;
import io.grpc.internal.GrpcUtil;
import io.grpc.internal.Http2Ping;
@ -893,9 +893,9 @@ class OkHttpClientTransport implements ConnectionClientTransport {
}
@Override
public ListenableFuture<InternalTransportStats> getStats() {
public ListenableFuture<TransportStats> getStats() {
synchronized (lock) {
SettableFuture<InternalTransportStats> ret = SettableFuture.create();
SettableFuture<TransportStats> ret = SettableFuture.create();
ret.set(transportTracer.getStats());
return ret;
}

View File

@ -54,7 +54,6 @@ import com.google.common.util.concurrent.MoreExecutors;
import com.google.common.util.concurrent.SettableFuture;
import io.grpc.CallOptions;
import io.grpc.InternalStatus;
import io.grpc.InternalTransportStats;
import io.grpc.Metadata;
import io.grpc.MethodDescriptor;
import io.grpc.MethodDescriptor.MethodType;
@ -62,6 +61,7 @@ import io.grpc.Status;
import io.grpc.Status.Code;
import io.grpc.StatusException;
import io.grpc.internal.AbstractStream;
import io.grpc.internal.Channelz.TransportStats;
import io.grpc.internal.ClientStreamListener;
import io.grpc.internal.ClientTransport;
import io.grpc.internal.GrpcUtil;
@ -547,7 +547,7 @@ public class OkHttpClientTransportTest {
@Test
public void transportTracer_windowSizeDefault() throws Exception {
initTransport();
InternalTransportStats stats = clientTransport.getStats().get();
TransportStats stats = clientTransport.getStats().get();
assertEquals(Utils.DEFAULT_WINDOW_SIZE, stats.remoteFlowControlWindow);
// okhttp does not track local window sizes
assertEquals(-1, stats.localFlowControlWindow);
@ -556,13 +556,13 @@ public class OkHttpClientTransportTest {
@Test
public void transportTracer_windowSize_remote() throws Exception {
initTransport();
InternalTransportStats before = clientTransport.getStats().get();
TransportStats before = clientTransport.getStats().get();
assertEquals(Utils.DEFAULT_WINDOW_SIZE, before.remoteFlowControlWindow);
// okhttp does not track local window sizes
assertEquals(-1, before.localFlowControlWindow);
frameHandler().windowUpdate(0, 1000);
InternalTransportStats after = clientTransport.getStats().get();
TransportStats after = clientTransport.getStats().get();
assertEquals(Utils.DEFAULT_WINDOW_SIZE + 1000, after.remoteFlowControlWindow);
// okhttp does not track local window sizes
assertEquals(-1, after.localFlowControlWindow);

View File

@ -47,11 +47,11 @@ import io.grpc.Attributes;
import io.grpc.CallOptions;
import io.grpc.ClientStreamTracer;
import io.grpc.Grpc;
import io.grpc.InternalTransportStats;
import io.grpc.Metadata;
import io.grpc.MethodDescriptor;
import io.grpc.ServerStreamTracer;
import io.grpc.Status;
import io.grpc.internal.Channelz.TransportStats;
import io.grpc.internal.ClientStream;
import io.grpc.internal.ClientStreamListener;
import io.grpc.internal.ClientTransport;
@ -1406,10 +1406,10 @@ public abstract class AbstractTransportTest {
long serverFirstTimestampNanos;
long clientFirstTimestampNanos;
{
InternalTransportStats serverBefore = serverTransportListener.transport.getStats().get();
TransportStats serverBefore = serverTransportListener.transport.getStats().get();
assertEquals(0, serverBefore.streamsStarted);
assertEquals(0, serverBefore.lastStreamCreatedTimeNanos);
InternalTransportStats clientBefore = client.getStats().get();
TransportStats clientBefore = client.getStats().get();
assertEquals(0, clientBefore.streamsStarted);
assertEquals(0, clientBefore.lastStreamCreatedTimeNanos);
@ -1419,14 +1419,14 @@ public abstract class AbstractTransportTest {
StreamCreation serverStreamCreation = serverTransportListener
.takeStreamOrFail(TIMEOUT_MS, TimeUnit.MILLISECONDS);
InternalTransportStats serverAfter = serverTransportListener.transport.getStats().get();
TransportStats serverAfter = serverTransportListener.transport.getStats().get();
assertEquals(1, serverAfter.streamsStarted);
serverFirstTimestampNanos = serverAfter.lastStreamCreatedTimeNanos;
assertEquals(
currentTimeMillis(),
TimeUnit.NANOSECONDS.toMillis(serverAfter.lastStreamCreatedTimeNanos));
InternalTransportStats clientAfter = client.getStats().get();
TransportStats clientAfter = client.getStats().get();
assertEquals(1, clientAfter.streamsStarted);
clientFirstTimestampNanos = clientAfter.lastStreamCreatedTimeNanos;
assertEquals(
@ -1442,9 +1442,9 @@ public abstract class AbstractTransportTest {
// start second stream
{
InternalTransportStats serverBefore = serverTransportListener.transport.getStats().get();
TransportStats serverBefore = serverTransportListener.transport.getStats().get();
assertEquals(1, serverBefore.streamsStarted);
InternalTransportStats clientBefore = client.getStats().get();
TransportStats clientBefore = client.getStats().get();
assertEquals(1, clientBefore.streamsStarted);
ClientStream clientStream = client.newStream(methodDescriptor, new Metadata(), callOptions);
@ -1453,7 +1453,7 @@ public abstract class AbstractTransportTest {
StreamCreation serverStreamCreation = serverTransportListener
.takeStreamOrFail(TIMEOUT_MS, TimeUnit.MILLISECONDS);
InternalTransportStats serverAfter = serverTransportListener.transport.getStats().get();
TransportStats serverAfter = serverTransportListener.transport.getStats().get();
assertEquals(2, serverAfter.streamsStarted);
assertEquals(
TimeUnit.MILLISECONDS.toNanos(elapsedMillis),
@ -1462,7 +1462,7 @@ public abstract class AbstractTransportTest {
TimeUnit.NANOSECONDS.toMillis(serverAfter.lastStreamCreatedTimeNanos);
assertEquals(currentTimeMillis(), serverSecondTimestamp);
InternalTransportStats clientAfter = client.getStats().get();
TransportStats clientAfter = client.getStats().get();
assertEquals(2, clientAfter.streamsStarted);
assertEquals(
TimeUnit.MILLISECONDS.toNanos(elapsedMillis),
@ -1493,10 +1493,10 @@ public abstract class AbstractTransportTest {
return;
}
InternalTransportStats serverBefore = serverTransportListener.transport.getStats().get();
TransportStats serverBefore = serverTransportListener.transport.getStats().get();
assertEquals(0, serverBefore.streamsSucceeded);
assertEquals(0, serverBefore.streamsFailed);
InternalTransportStats clientBefore = client.getStats().get();
TransportStats clientBefore = client.getStats().get();
assertEquals(0, clientBefore.streamsSucceeded);
assertEquals(0, clientBefore.streamsFailed);
@ -1507,10 +1507,10 @@ public abstract class AbstractTransportTest {
assertNotNull(clientStreamListener.trailers.get(TIMEOUT_MS, TimeUnit.MILLISECONDS));
InternalTransportStats serverAfter = serverTransportListener.transport.getStats().get();
TransportStats serverAfter = serverTransportListener.transport.getStats().get();
assertEquals(1, serverAfter.streamsSucceeded);
assertEquals(0, serverAfter.streamsFailed);
InternalTransportStats clientAfter = client.getStats().get();
TransportStats clientAfter = client.getStats().get();
assertEquals(1, clientAfter.streamsSucceeded);
assertEquals(0, clientAfter.streamsFailed);
}
@ -1532,10 +1532,10 @@ public abstract class AbstractTransportTest {
return;
}
InternalTransportStats serverBefore = serverTransportListener.transport.getStats().get();
TransportStats serverBefore = serverTransportListener.transport.getStats().get();
assertEquals(0, serverBefore.streamsFailed);
assertEquals(0, serverBefore.streamsSucceeded);
InternalTransportStats clientBefore = client.getStats().get();
TransportStats clientBefore = client.getStats().get();
assertEquals(0, clientBefore.streamsFailed);
assertEquals(0, clientBefore.streamsSucceeded);
@ -1545,10 +1545,10 @@ public abstract class AbstractTransportTest {
assertNotNull(clientStreamListener.trailers.get(TIMEOUT_MS, TimeUnit.MILLISECONDS));
InternalTransportStats serverAfter = serverTransportListener.transport.getStats().get();
TransportStats serverAfter = serverTransportListener.transport.getStats().get();
assertEquals(1, serverAfter.streamsFailed);
assertEquals(0, serverAfter.streamsSucceeded);
InternalTransportStats clientAfter = client.getStats().get();
TransportStats clientAfter = client.getStats().get();
assertEquals(1, clientAfter.streamsFailed);
assertEquals(0, clientAfter.streamsSucceeded);
@ -1571,10 +1571,10 @@ public abstract class AbstractTransportTest {
return;
}
InternalTransportStats serverBefore = serverTransportListener.transport.getStats().get();
TransportStats serverBefore = serverTransportListener.transport.getStats().get();
assertEquals(0, serverBefore.streamsFailed);
assertEquals(0, serverBefore.streamsSucceeded);
InternalTransportStats clientBefore = client.getStats().get();
TransportStats clientBefore = client.getStats().get();
assertEquals(0, clientBefore.streamsFailed);
assertEquals(0, clientBefore.streamsSucceeded);
@ -1582,10 +1582,10 @@ public abstract class AbstractTransportTest {
// do not validate stats until close() has been called on server
assertNotNull(serverStreamCreation.listener.status.get(TIMEOUT_MS, TimeUnit.MILLISECONDS));
InternalTransportStats serverAfter = serverTransportListener.transport.getStats().get();
TransportStats serverAfter = serverTransportListener.transport.getStats().get();
assertEquals(1, serverAfter.streamsFailed);
assertEquals(0, serverAfter.streamsSucceeded);
InternalTransportStats clientAfter = client.getStats().get();
TransportStats clientAfter = client.getStats().get();
assertEquals(1, clientAfter.streamsFailed);
assertEquals(0, clientAfter.streamsSucceeded);
}
@ -1608,10 +1608,10 @@ public abstract class AbstractTransportTest {
return;
}
InternalTransportStats serverBefore = serverTransportListener.transport.getStats().get();
TransportStats serverBefore = serverTransportListener.transport.getStats().get();
assertEquals(0, serverBefore.messagesReceived);
assertEquals(0, serverBefore.lastMessageReceivedTimeNanos);
InternalTransportStats clientBefore = client.getStats().get();
TransportStats clientBefore = client.getStats().get();
assertEquals(0, clientBefore.messagesSent);
assertEquals(0, clientBefore.lastMessageSentTimeNanos);
@ -1621,12 +1621,12 @@ public abstract class AbstractTransportTest {
clientStream.halfClose();
verifyMessageCountAndClose(serverStreamListener.messageQueue, 1);
InternalTransportStats serverAfter = serverTransportListener.transport.getStats().get();
TransportStats serverAfter = serverTransportListener.transport.getStats().get();
assertEquals(1, serverAfter.messagesReceived);
long serverTimestamp =
TimeUnit.NANOSECONDS.toMillis(serverAfter.lastMessageReceivedTimeNanos);
assertEquals(currentTimeMillis(), serverTimestamp);
InternalTransportStats clientAfter = client.getStats().get();
TransportStats clientAfter = client.getStats().get();
assertEquals(1, clientAfter.messagesSent);
long clientTimestamp =
TimeUnit.NANOSECONDS.toMillis(clientAfter.lastMessageSentTimeNanos);
@ -1652,10 +1652,10 @@ public abstract class AbstractTransportTest {
return;
}
InternalTransportStats serverBefore = serverTransportListener.transport.getStats().get();
TransportStats serverBefore = serverTransportListener.transport.getStats().get();
assertEquals(0, serverBefore.messagesSent);
assertEquals(0, serverBefore.lastMessageSentTimeNanos);
InternalTransportStats clientBefore = client.getStats().get();
TransportStats clientBefore = client.getStats().get();
assertEquals(0, clientBefore.messagesReceived);
assertEquals(0, clientBefore.lastMessageReceivedTimeNanos);
@ -1665,11 +1665,11 @@ public abstract class AbstractTransportTest {
serverStream.flush();
verifyMessageCountAndClose(clientStreamListener.messageQueue, 1);
InternalTransportStats serverAfter = serverTransportListener.transport.getStats().get();
TransportStats serverAfter = serverTransportListener.transport.getStats().get();
assertEquals(1, serverAfter.messagesSent);
long serverTimestmap = TimeUnit.NANOSECONDS.toMillis(serverAfter.lastMessageSentTimeNanos);
assertEquals(currentTimeMillis(), serverTimestmap);
InternalTransportStats clientAfter = client.getStats().get();
TransportStats clientAfter = client.getStats().get();
assertEquals(1, clientAfter.messagesReceived);
long clientTimestmap =
TimeUnit.NANOSECONDS.toMillis(clientAfter.lastMessageReceivedTimeNanos);