Search in sources :

Example 1 with MetricsRecord

use of io.grpc.internal.testing.StatsTestUtils.MetricsRecord in project grpc-java by grpc.

the class MessageDeframerTest method checkStats.

private void checkStats(long wireBytesReceived, long uncompressedBytesReceived) {
    statsTraceCtx.callEnded(Status.OK);
    MetricsRecord record = statsCtxFactory.pollRecord();
    assertEquals(0, record.getMetricAsLongOrFail(RpcConstants.RPC_CLIENT_REQUEST_BYTES));
    assertEquals(0, record.getMetricAsLongOrFail(RpcConstants.RPC_CLIENT_UNCOMPRESSED_REQUEST_BYTES));
    assertEquals(wireBytesReceived, record.getMetricAsLongOrFail(RpcConstants.RPC_CLIENT_RESPONSE_BYTES));
    assertEquals(uncompressedBytesReceived, record.getMetricAsLongOrFail(RpcConstants.RPC_CLIENT_UNCOMPRESSED_RESPONSE_BYTES));
    assertNull(record.getMetric(RpcConstants.RPC_SERVER_REQUEST_BYTES));
    assertNull(record.getMetric(RpcConstants.RPC_SERVER_RESPONSE_BYTES));
    assertNull(record.getMetric(RpcConstants.RPC_SERVER_UNCOMPRESSED_REQUEST_BYTES));
    assertNull(record.getMetric(RpcConstants.RPC_SERVER_UNCOMPRESSED_RESPONSE_BYTES));
}
Also used : MetricsRecord(io.grpc.internal.testing.StatsTestUtils.MetricsRecord)

Example 2 with MetricsRecord

use of io.grpc.internal.testing.StatsTestUtils.MetricsRecord in project grpc-java by grpc.

the class AbstractInteropTest method assertClientMetrics.

private void assertClientMetrics(String method, Status.Code status, Collection<? extends MessageLite> requests, Collection<? extends MessageLite> responses) {
    MetricsRecord clientRecord = clientStatsFactory.pollRecord();
    assertNotNull("clientRecord is not null", clientRecord);
    checkTags(clientRecord, false, method, status);
    if (requests != null && responses != null) {
        checkMetrics(clientRecord, false, requests, responses);
    }
}
Also used : MetricsRecord(io.grpc.internal.testing.StatsTestUtils.MetricsRecord)

Example 3 with MetricsRecord

use of io.grpc.internal.testing.StatsTestUtils.MetricsRecord in project grpc-java by grpc.

the class RetryTest method assertRpcStartedRecorded.

private void assertRpcStartedRecorded() throws Exception {
    MetricsRecord record = clientStatsRecorder.pollRecord(5, SECONDS);
    assertThat(record.getMetricAsLongOrFail(DeprecatedCensusConstants.RPC_CLIENT_STARTED_COUNT)).isEqualTo(1);
}
Also used : MetricsRecord(io.grpc.internal.testing.StatsTestUtils.MetricsRecord)

Example 4 with MetricsRecord

use of io.grpc.internal.testing.StatsTestUtils.MetricsRecord in project grpc-java by grpc.

the class AbstractInteropTest method assertServerStatsTrace.

// Failure is checked in the end by the passed flag.
@SuppressWarnings("AssertionFailureIgnored")
private void assertServerStatsTrace(String method, Status.Code code, Collection<? extends MessageLite> requests, Collection<? extends MessageLite> responses) {
    if (server == null) {
        // Server is not in the same process.  We can't check server-side stats.
        return;
    }
    if (metricsExpected()) {
        MetricsRecord serverStartRecord;
        MetricsRecord serverEndRecord;
        try {
            // On the server, the stats is finalized in ServerStreamListener.closed(), which can be
            // run after the client receives the final status.  So we use a timeout.
            serverStartRecord = serverStatsRecorder.pollRecord(5, TimeUnit.SECONDS);
            serverEndRecord = serverStatsRecorder.pollRecord(5, TimeUnit.SECONDS);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        assertNotNull(serverStartRecord);
        assertNotNull(serverEndRecord);
        checkStartTags(serverStartRecord, method, false);
        checkEndTags(serverEndRecord, method, code, false);
        if (requests != null && responses != null) {
            checkCensus(serverEndRecord, true, requests, responses);
        }
    }
    ServerStreamTracerInfo tracerInfo;
    tracerInfo = serverStreamTracers.poll();
    assertNotNull(tracerInfo);
    assertEquals(method, tracerInfo.fullMethodName);
    assertNotNull(tracerInfo.tracer.contextCapture);
    // So we use a timeout.
    try {
        assertTrue(tracerInfo.tracer.await(1, TimeUnit.SECONDS));
    } catch (InterruptedException e) {
        throw new AssertionError(e);
    }
    assertEquals(code, tracerInfo.tracer.getStatus().getCode());
    if (requests != null && responses != null) {
        checkTracers(tracerInfo.tracer, responses, requests);
    }
}
Also used : StatusRuntimeException(io.grpc.StatusRuntimeException) MetricsRecord(io.grpc.internal.testing.StatsTestUtils.MetricsRecord)

Example 5 with MetricsRecord

use of io.grpc.internal.testing.StatsTestUtils.MetricsRecord in project grpc-java by grpc.

the class AbstractInteropTest method deadlineInPast.

@Test
public void deadlineInPast() throws Exception {
    // Test once with idle channel and once with active channel
    try {
        blockingStub.withDeadlineAfter(-10, TimeUnit.SECONDS).emptyCall(Empty.getDefaultInstance());
        fail("Should have thrown");
    } catch (StatusRuntimeException ex) {
        assertEquals(Status.Code.DEADLINE_EXCEEDED, ex.getStatus().getCode());
        assertThat(ex.getStatus().getDescription()).startsWith("ClientCall started after deadline exceeded");
    }
    // deadline is exceeded before the call is created. Therefore we don't check the tracer stats.
    if (metricsExpected()) {
        MetricsRecord clientStartRecord = clientStatsRecorder.pollRecord(5, TimeUnit.SECONDS);
        checkStartTags(clientStartRecord, "grpc.testing.TestService/EmptyCall", true);
        MetricsRecord clientEndRecord = clientStatsRecorder.pollRecord(5, TimeUnit.SECONDS);
        checkEndTags(clientEndRecord, "grpc.testing.TestService/EmptyCall", Status.DEADLINE_EXCEEDED.getCode(), true);
        assertZeroRetryRecorded();
    }
    // warm up the channel
    blockingStub.emptyCall(Empty.getDefaultInstance());
    if (metricsExpected()) {
        // clientStartRecord
        clientStatsRecorder.pollRecord(5, TimeUnit.SECONDS);
        // clientEndRecord
        clientStatsRecorder.pollRecord(5, TimeUnit.SECONDS);
        assertZeroRetryRecorded();
    }
    try {
        blockingStub.withDeadlineAfter(-10, TimeUnit.SECONDS).emptyCall(Empty.getDefaultInstance());
        fail("Should have thrown");
    } catch (StatusRuntimeException ex) {
        assertEquals(Status.Code.DEADLINE_EXCEEDED, ex.getStatus().getCode());
        assertThat(ex.getStatus().getDescription()).startsWith("ClientCall started after deadline exceeded");
    }
    if (metricsExpected()) {
        MetricsRecord clientStartRecord = clientStatsRecorder.pollRecord(5, TimeUnit.SECONDS);
        checkStartTags(clientStartRecord, "grpc.testing.TestService/EmptyCall", true);
        MetricsRecord clientEndRecord = clientStatsRecorder.pollRecord(5, TimeUnit.SECONDS);
        checkEndTags(clientEndRecord, "grpc.testing.TestService/EmptyCall", Status.DEADLINE_EXCEEDED.getCode(), true);
        assertZeroRetryRecorded();
    }
}
Also used : MetricsRecord(io.grpc.internal.testing.StatsTestUtils.MetricsRecord) StatusRuntimeException(io.grpc.StatusRuntimeException) Test(org.junit.Test)

Aggregations

MetricsRecord (io.grpc.internal.testing.StatsTestUtils.MetricsRecord)19 Test (org.junit.Test)6 StatusRuntimeException (io.grpc.StatusRuntimeException)4 StreamingOutputCallRequest (io.grpc.testing.integration.Messages.StreamingOutputCallRequest)3 StreamingOutputCallResponse (io.grpc.testing.integration.Messages.StreamingOutputCallResponse)2 TagValue (io.opencensus.tags.TagValue)2 ByteString (com.google.protobuf.ByteString)1 Attributes (io.grpc.Attributes)1 CallOptions (io.grpc.CallOptions)1 ClientStreamTracer (io.grpc.ClientStreamTracer)1 StreamInfo (io.grpc.ClientStreamTracer.StreamInfo)1 Metadata (io.grpc.Metadata)1 Status (io.grpc.Status)1 TestClientStreamTracer (io.grpc.internal.testing.TestClientStreamTracer)1 ResponseParameters (io.grpc.testing.integration.Messages.ResponseParameters)1 StreamingInputCallRequest (io.grpc.testing.integration.Messages.StreamingInputCallRequest)1 StreamingInputCallResponse (io.grpc.testing.integration.Messages.StreamingInputCallResponse)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1