mirror of https://github.com/grpc/grpc-java.git
inprocess: Support tracing message sizes guarded by flag (#11629)
This commit is contained in:
parent
62f409810d
commit
b65cbf5081
|
|
@ -96,6 +96,9 @@ public abstract class AbstractTransportTest {
|
|||
|
||||
private static final int TIMEOUT_MS = 5000;
|
||||
|
||||
protected static final String GRPC_EXPERIMENTAL_SUPPORT_TRACING_MESSAGE_SIZES =
|
||||
"GRPC_EXPERIMENTAL_SUPPORT_TRACING_MESSAGE_SIZES";
|
||||
|
||||
private static final Attributes.Key<String> ADDITIONAL_TRANSPORT_ATTR_KEY =
|
||||
Attributes.Key.create("additional-attr");
|
||||
|
||||
|
|
@ -238,6 +241,13 @@ public abstract class AbstractTransportTest {
|
|||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if env var is set.
|
||||
*/
|
||||
protected static boolean isEnabledSupportTracingMessageSizes() {
|
||||
return GrpcUtil.getFlag(GRPC_EXPERIMENTAL_SUPPORT_TRACING_MESSAGE_SIZES, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current time, for tests that rely on the clock.
|
||||
*/
|
||||
|
|
@ -850,16 +860,21 @@ public abstract class AbstractTransportTest {
|
|||
message.close();
|
||||
assertThat(clientStreamTracer1.nextOutboundEvent())
|
||||
.matches("outboundMessageSent\\(0, -?[0-9]+, -?[0-9]+\\)");
|
||||
if (isEnabledSupportTracingMessageSizes()) {
|
||||
assertThat(clientStreamTracer1.getOutboundWireSize()).isGreaterThan(0L);
|
||||
assertThat(clientStreamTracer1.getOutboundUncompressedSize()).isGreaterThan(0L);
|
||||
}
|
||||
|
||||
assertThat(serverStreamTracer1.nextInboundEvent()).isEqualTo("inboundMessage(0)");
|
||||
assertNull("no additional message expected", serverStreamListener.messageQueue.poll());
|
||||
|
||||
clientStream.halfClose();
|
||||
assertTrue(serverStreamListener.awaitHalfClosed(TIMEOUT_MS, TimeUnit.MILLISECONDS));
|
||||
|
||||
if (isEnabledSupportTracingMessageSizes()) {
|
||||
assertThat(serverStreamTracer1.getInboundWireSize()).isGreaterThan(0L);
|
||||
assertThat(serverStreamTracer1.getInboundUncompressedSize()).isGreaterThan(0L);
|
||||
}
|
||||
assertThat(serverStreamTracer1.nextInboundEvent())
|
||||
.matches("inboundMessageRead\\(0, -?[0-9]+, -?[0-9]+\\)");
|
||||
|
||||
|
|
@ -890,15 +905,19 @@ public abstract class AbstractTransportTest {
|
|||
assertNotNull("message expected", message);
|
||||
assertThat(serverStreamTracer1.nextOutboundEvent())
|
||||
.matches("outboundMessageSent\\(0, -?[0-9]+, -?[0-9]+\\)");
|
||||
if (isEnabledSupportTracingMessageSizes()) {
|
||||
assertThat(serverStreamTracer1.getOutboundWireSize()).isGreaterThan(0L);
|
||||
assertThat(serverStreamTracer1.getOutboundUncompressedSize()).isGreaterThan(0L);
|
||||
}
|
||||
assertTrue(clientStreamTracer1.getInboundHeaders());
|
||||
assertThat(clientStreamTracer1.nextInboundEvent()).isEqualTo("inboundMessage(0)");
|
||||
assertEquals("Hi. Who are you?", methodDescriptor.parseResponse(message));
|
||||
assertThat(clientStreamTracer1.nextInboundEvent())
|
||||
.matches("inboundMessageRead\\(0, -?[0-9]+, -?[0-9]+\\)");
|
||||
if (isEnabledSupportTracingMessageSizes()) {
|
||||
assertThat(clientStreamTracer1.getInboundWireSize()).isGreaterThan(0L);
|
||||
assertThat(clientStreamTracer1.getInboundUncompressedSize()).isGreaterThan(0L);
|
||||
}
|
||||
|
||||
message.close();
|
||||
assertNull("no additional message expected", clientStreamListener.messageQueue.poll());
|
||||
|
|
@ -1258,10 +1277,12 @@ public abstract class AbstractTransportTest {
|
|||
serverStream.close(Status.OK, new Metadata());
|
||||
assertTrue(clientStreamTracer1.getOutboundHeaders());
|
||||
assertTrue(clientStreamTracer1.getInboundHeaders());
|
||||
if (isEnabledSupportTracingMessageSizes()) {
|
||||
assertThat(clientStreamTracer1.getInboundWireSize()).isGreaterThan(0L);
|
||||
assertThat(clientStreamTracer1.getInboundUncompressedSize()).isGreaterThan(0L);
|
||||
assertThat(serverStreamTracer1.getOutboundWireSize()).isGreaterThan(0L);
|
||||
assertThat(serverStreamTracer1.getOutboundUncompressedSize()).isGreaterThan(0L);
|
||||
}
|
||||
assertNull(clientStreamTracer1.getInboundTrailers());
|
||||
assertSame(status, clientStreamTracer1.getStatus());
|
||||
// There is a race between client cancelling and server closing. The final status seen by the
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ package io.grpc.inprocess;
|
|||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static io.grpc.inprocess.InProcessTransport.isEnabledSupportTracingMessageSizes;
|
||||
|
||||
import com.google.errorprone.annotations.DoNotCall;
|
||||
import io.grpc.ChannelCredentials;
|
||||
|
|
@ -118,6 +119,9 @@ public final class InProcessChannelBuilder extends
|
|||
managedChannelImplBuilder.setStatsRecordStartedRpcs(false);
|
||||
managedChannelImplBuilder.setStatsRecordFinishedRpcs(false);
|
||||
managedChannelImplBuilder.setStatsRecordRetryMetrics(false);
|
||||
if (!isEnabledSupportTracingMessageSizes) {
|
||||
managedChannelImplBuilder.disableRetry();
|
||||
}
|
||||
}
|
||||
|
||||
@Internal
|
||||
|
|
|
|||
|
|
@ -82,6 +82,8 @@ import javax.annotation.concurrent.ThreadSafe;
|
|||
@ThreadSafe
|
||||
final class InProcessTransport implements ServerTransport, ConnectionClientTransport {
|
||||
private static final Logger log = Logger.getLogger(InProcessTransport.class.getName());
|
||||
static boolean isEnabledSupportTracingMessageSizes =
|
||||
GrpcUtil.getFlag("GRPC_EXPERIMENTAL_SUPPORT_TRACING_MESSAGE_SIZES", false);
|
||||
|
||||
private final InternalLogId logId;
|
||||
private final SocketAddress address;
|
||||
|
|
@ -485,7 +487,8 @@ final class InProcessTransport implements ServerTransport, ConnectionClientTrans
|
|||
|
||||
@Override
|
||||
public void writeMessage(InputStream message) {
|
||||
long messageLength;
|
||||
long messageLength = 0;
|
||||
if (isEnabledSupportTracingMessageSizes) {
|
||||
try {
|
||||
if (assumedMessageSize != -1) {
|
||||
messageLength = assumedMessageSize;
|
||||
|
|
@ -501,6 +504,8 @@ final class InProcessTransport implements ServerTransport, ConnectionClientTrans
|
|||
} catch (Exception e) {
|
||||
throw new RuntimeException("Error processing the message length", e);
|
||||
}
|
||||
}
|
||||
|
||||
synchronized (this) {
|
||||
if (closed) {
|
||||
return;
|
||||
|
|
@ -509,11 +514,13 @@ final class InProcessTransport implements ServerTransport, ConnectionClientTrans
|
|||
statsTraceCtx.outboundMessageSent(outboundSeqNo, -1, -1);
|
||||
clientStream.statsTraceCtx.inboundMessage(outboundSeqNo);
|
||||
clientStream.statsTraceCtx.inboundMessageRead(outboundSeqNo, -1, -1);
|
||||
if (isEnabledSupportTracingMessageSizes) {
|
||||
statsTraceCtx.outboundUncompressedSize(messageLength);
|
||||
statsTraceCtx.outboundWireSize(messageLength);
|
||||
// messageLength should be same at receiver's end as no actual wire is involved.
|
||||
clientStream.statsTraceCtx.inboundUncompressedSize(messageLength);
|
||||
clientStream.statsTraceCtx.inboundWireSize(messageLength);
|
||||
}
|
||||
outboundSeqNo++;
|
||||
StreamListener.MessageProducer producer = new SingleMessageProducer(message);
|
||||
if (clientRequested > 0) {
|
||||
|
|
@ -523,7 +530,6 @@ final class InProcessTransport implements ServerTransport, ConnectionClientTrans
|
|||
clientReceiveQueue.add(producer);
|
||||
}
|
||||
}
|
||||
|
||||
syncContext.drain();
|
||||
}
|
||||
|
||||
|
|
@ -777,7 +783,8 @@ final class InProcessTransport implements ServerTransport, ConnectionClientTrans
|
|||
|
||||
@Override
|
||||
public void writeMessage(InputStream message) {
|
||||
long messageLength;
|
||||
long messageLength = 0;
|
||||
if (isEnabledSupportTracingMessageSizes) {
|
||||
try {
|
||||
if (assumedMessageSize != -1) {
|
||||
messageLength = assumedMessageSize;
|
||||
|
|
@ -793,6 +800,7 @@ final class InProcessTransport implements ServerTransport, ConnectionClientTrans
|
|||
} catch (Exception e) {
|
||||
throw new RuntimeException("Error processing the message length", e);
|
||||
}
|
||||
}
|
||||
synchronized (this) {
|
||||
if (closed) {
|
||||
return;
|
||||
|
|
@ -801,11 +809,13 @@ final class InProcessTransport implements ServerTransport, ConnectionClientTrans
|
|||
statsTraceCtx.outboundMessageSent(outboundSeqNo, -1, -1);
|
||||
serverStream.statsTraceCtx.inboundMessage(outboundSeqNo);
|
||||
serverStream.statsTraceCtx.inboundMessageRead(outboundSeqNo, -1, -1);
|
||||
if (isEnabledSupportTracingMessageSizes) {
|
||||
statsTraceCtx.outboundUncompressedSize(messageLength);
|
||||
statsTraceCtx.outboundWireSize(messageLength);
|
||||
// messageLength should be same at receiver's end as no actual wire is involved.
|
||||
serverStream.statsTraceCtx.inboundUncompressedSize(messageLength);
|
||||
serverStream.statsTraceCtx.inboundWireSize(messageLength);
|
||||
}
|
||||
outboundSeqNo++;
|
||||
StreamListener.MessageProducer producer = new SingleMessageProducer(message);
|
||||
if (serverRequested > 0) {
|
||||
|
|
|
|||
|
|
@ -234,9 +234,11 @@ public class InProcessTransportTest extends AbstractTransportTest {
|
|||
|
||||
private void assertAssumedMessageSize(
|
||||
TestStreamTracer streamTracerSender, TestStreamTracer streamTracerReceiver) {
|
||||
if (isEnabledSupportTracingMessageSizes()) {
|
||||
Assert.assertEquals(TEST_MESSAGE_LENGTH, streamTracerSender.getOutboundWireSize());
|
||||
Assert.assertEquals(TEST_MESSAGE_LENGTH, streamTracerSender.getOutboundUncompressedSize());
|
||||
Assert.assertEquals(TEST_MESSAGE_LENGTH, streamTracerReceiver.getInboundWireSize());
|
||||
Assert.assertEquals(TEST_MESSAGE_LENGTH, streamTracerReceiver.getInboundUncompressedSize());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue