Search in sources :

Example 1 with TagValue

use of com.google.instrumentation.stats.TagValue in project grpc-java by grpc.

the class AbstractInteropTest method checkTags.

private static void checkTags(MetricsRecord record, boolean server, String methodName, Status.Code status) {
    TagValue methodNameTag = record.tags.get(server ? RpcConstants.RPC_SERVER_METHOD : RpcConstants.RPC_CLIENT_METHOD);
    assertNotNull("method name tagged", methodNameTag);
    assertEquals("method names match", methodName, methodNameTag.toString());
    TagValue statusTag = record.tags.get(RpcConstants.RPC_STATUS);
    assertNotNull("status tagged", statusTag);
    assertEquals(status.toString(), statusTag.toString());
}
Also used : TagValue(com.google.instrumentation.stats.TagValue)

Example 2 with TagValue

use of com.google.instrumentation.stats.TagValue in project grpc-java by grpc.

the class ServerCallImplTest method checkStats.

private void checkStats(Status.Code statusCode) {
    StatsTestUtils.MetricsRecord record = statsCtxFactory.pollRecord();
    assertNotNull(record);
    TagValue statusTag = record.tags.get(RpcConstants.RPC_STATUS);
    assertNotNull(statusTag);
    assertEquals(statusCode.toString(), statusTag.toString());
    assertNull(record.getMetric(RpcConstants.RPC_CLIENT_REQUEST_BYTES));
    assertNull(record.getMetric(RpcConstants.RPC_CLIENT_RESPONSE_BYTES));
    assertNull(record.getMetric(RpcConstants.RPC_CLIENT_UNCOMPRESSED_REQUEST_BYTES));
    assertNull(record.getMetric(RpcConstants.RPC_CLIENT_UNCOMPRESSED_RESPONSE_BYTES));
    // The test doesn't invoke MessageFramer and MessageDeframer which keep the sizes.
    // Thus the sizes reported to stats would be zero.
    assertEquals(0, record.getMetricAsLongOrFail(RpcConstants.RPC_SERVER_REQUEST_BYTES));
    assertEquals(0, record.getMetricAsLongOrFail(RpcConstants.RPC_SERVER_RESPONSE_BYTES));
    assertEquals(0, record.getMetricAsLongOrFail(RpcConstants.RPC_SERVER_UNCOMPRESSED_REQUEST_BYTES));
    assertEquals(0, record.getMetricAsLongOrFail(RpcConstants.RPC_SERVER_UNCOMPRESSED_RESPONSE_BYTES));
}
Also used : StatsTestUtils(io.grpc.internal.testing.StatsTestUtils) TagValue(com.google.instrumentation.stats.TagValue)

Example 3 with TagValue

use of com.google.instrumentation.stats.TagValue in project grpc-java by grpc.

the class StatsTraceContextTest method tagPropagation.

/**
   * Tags that are propagated by the {@link StatsContextFactory} are properly propagated via
   * the headers.
   */
@Test
public void tagPropagation() {
    String methodName = MethodDescriptor.generateFullMethodName("Service1", "method3");
    // EXTRA_TAG is propagated by the FakeStatsContextFactory. Note that not all tags are
    // propagated.  The StatsContextFactory decides which tags are to propagated.  gRPC facilitates
    // the propagation by putting them in the headers.
    StatsContext parentCtx = statsCtxFactory.getDefault().with(StatsTestUtils.EXTRA_TAG, TagValue.create("extra-tag-value-897"));
    StatsTraceContext clientCtx = StatsTraceContext.newClientContextForTesting(methodName, statsCtxFactory, parentCtx, fakeClock.getStopwatchSupplier());
    Metadata headers = new Metadata();
    clientCtx.propagateToHeaders(headers);
    // The server gets the propagated tag from the headers, and puts it on the server-side
    // StatsContext.
    StatsTraceContext serverCtx = StatsTraceContext.newServerContext(methodName, statsCtxFactory, headers, fakeClock.getStopwatchSupplier());
    serverCtx.callEnded(Status.OK);
    clientCtx.callEnded(Status.OK);
    StatsTestUtils.MetricsRecord serverRecord = statsCtxFactory.pollRecord();
    assertNotNull(serverRecord);
    assertNoClientContent(serverRecord);
    TagValue serverMethodTag = serverRecord.tags.get(RpcConstants.RPC_SERVER_METHOD);
    assertEquals(methodName, serverMethodTag.toString());
    TagValue serverStatusTag = serverRecord.tags.get(RpcConstants.RPC_STATUS);
    assertEquals(Status.Code.OK.toString(), serverStatusTag.toString());
    assertNull(serverRecord.getMetric(RpcConstants.RPC_SERVER_ERROR_COUNT));
    TagValue serverPropagatedTag = serverRecord.tags.get(StatsTestUtils.EXTRA_TAG);
    assertEquals("extra-tag-value-897", serverPropagatedTag.toString());
    StatsTestUtils.MetricsRecord clientRecord = statsCtxFactory.pollRecord();
    assertNotNull(clientRecord);
    assertNoServerContent(clientRecord);
    TagValue clientMethodTag = clientRecord.tags.get(RpcConstants.RPC_CLIENT_METHOD);
    assertEquals(methodName, clientMethodTag.toString());
    TagValue clientStatusTag = clientRecord.tags.get(RpcConstants.RPC_STATUS);
    assertEquals(Status.Code.OK.toString(), clientStatusTag.toString());
    assertNull(clientRecord.getMetric(RpcConstants.RPC_CLIENT_ERROR_COUNT));
    TagValue clientPropagatedTag = clientRecord.tags.get(StatsTestUtils.EXTRA_TAG);
    assertEquals("extra-tag-value-897", clientPropagatedTag.toString());
}
Also used : StatsTestUtils(io.grpc.internal.testing.StatsTestUtils) StatsContext(com.google.instrumentation.stats.StatsContext) Metadata(io.grpc.Metadata) TagValue(com.google.instrumentation.stats.TagValue) Test(org.junit.Test)

Example 4 with TagValue

use of com.google.instrumentation.stats.TagValue in project grpc-java by grpc.

the class ClientCallImplTest method assertStatusInStats.

private void assertStatusInStats(Status.Code statusCode) {
    StatsTestUtils.MetricsRecord record = statsCtxFactory.pollRecord();
    assertNotNull(record);
    TagValue statusTag = record.tags.get(RpcConstants.RPC_STATUS);
    assertNotNull(statusTag);
    assertEquals(statusCode.toString(), statusTag.toString());
}
Also used : StatsTestUtils(io.grpc.internal.testing.StatsTestUtils) TagValue(com.google.instrumentation.stats.TagValue)

Example 5 with TagValue

use of com.google.instrumentation.stats.TagValue in project grpc-java by grpc.

the class StatsTraceContextTest method clientBasic.

@Test
public void clientBasic() {
    String methodName = MethodDescriptor.generateFullMethodName("Service1", "method1");
    StatsTraceContext ctx = StatsTraceContext.newClientContextForTesting(methodName, statsCtxFactory, statsCtxFactory.getDefault(), fakeClock.getStopwatchSupplier());
    fakeClock.forwardMillis(30);
    ctx.clientHeadersSent();
    fakeClock.forwardMillis(100);
    ctx.wireBytesSent(1028);
    ctx.uncompressedBytesSent(1128);
    fakeClock.forwardMillis(16);
    ctx.wireBytesReceived(33);
    ctx.uncompressedBytesReceived(67);
    ctx.wireBytesSent(99);
    ctx.uncompressedBytesSent(865);
    fakeClock.forwardMillis(24);
    ctx.wireBytesReceived(154);
    ctx.uncompressedBytesReceived(552);
    ctx.callEnded(Status.OK);
    StatsTestUtils.MetricsRecord record = statsCtxFactory.pollRecord();
    assertNotNull(record);
    assertNoServerContent(record);
    TagValue methodTag = record.tags.get(RpcConstants.RPC_CLIENT_METHOD);
    assertEquals(methodName, methodTag.toString());
    TagValue statusTag = record.tags.get(RpcConstants.RPC_STATUS);
    assertEquals(Status.Code.OK.toString(), statusTag.toString());
    assertNull(record.getMetric(RpcConstants.RPC_CLIENT_ERROR_COUNT));
    assertEquals(1028 + 99, record.getMetricAsLongOrFail(RpcConstants.RPC_CLIENT_REQUEST_BYTES));
    assertEquals(1128 + 865, record.getMetricAsLongOrFail(RpcConstants.RPC_CLIENT_UNCOMPRESSED_REQUEST_BYTES));
    assertEquals(33 + 154, record.getMetricAsLongOrFail(RpcConstants.RPC_CLIENT_RESPONSE_BYTES));
    assertEquals(67 + 552, record.getMetricAsLongOrFail(RpcConstants.RPC_CLIENT_UNCOMPRESSED_RESPONSE_BYTES));
    assertEquals(30 + 100 + 16 + 24, record.getMetricAsLongOrFail(RpcConstants.RPC_CLIENT_ROUNDTRIP_LATENCY));
    assertEquals(100 + 16 + 24, record.getMetricAsLongOrFail(RpcConstants.RPC_CLIENT_SERVER_ELAPSED_TIME));
}
Also used : StatsTestUtils(io.grpc.internal.testing.StatsTestUtils) TagValue(com.google.instrumentation.stats.TagValue) Test(org.junit.Test)

Aggregations

TagValue (com.google.instrumentation.stats.TagValue)9 StatsTestUtils (io.grpc.internal.testing.StatsTestUtils)8 Test (org.junit.Test)6 Metadata (io.grpc.Metadata)4 StatsContext (com.google.instrumentation.stats.StatsContext)2 Status (io.grpc.Status)2 JumpToApplicationThreadServerStreamListener (io.grpc.internal.ServerImpl.JumpToApplicationThreadServerStreamListener)2 Compressor (io.grpc.Compressor)1 ServerCall (io.grpc.ServerCall)1 ServiceDescriptor (io.grpc.ServiceDescriptor)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1