Search in sources :

Example 6 with MetricsRecord

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

the class AbstractInteropTest method cancelAfterBegin.

@Test
public void cancelAfterBegin() throws Exception {
    StreamRecorder<StreamingInputCallResponse> responseObserver = StreamRecorder.create();
    StreamObserver<StreamingInputCallRequest> requestObserver = asyncStub.streamingInputCall(responseObserver);
    requestObserver.onError(new RuntimeException());
    responseObserver.awaitCompletion();
    assertEquals(Arrays.<StreamingInputCallResponse>asList(), responseObserver.getValues());
    assertEquals(Status.Code.CANCELLED, Status.fromThrowable(responseObserver.getError()).getCode());
    if (metricsExpected()) {
        MetricsRecord clientStartRecord = clientStatsRecorder.pollRecord(5, TimeUnit.SECONDS);
        checkStartTags(clientStartRecord, "grpc.testing.TestService/StreamingInputCall", true);
        // CensusStreamTracerModule record final status in the interceptor, thus is guaranteed to be
        // recorded.  The tracer stats rely on the stream being created, which is not always the case
        // in this test.  Therefore we don't check the tracer stats.
        MetricsRecord clientEndRecord = clientStatsRecorder.pollRecord(5, TimeUnit.SECONDS);
        checkEndTags(clientEndRecord, "grpc.testing.TestService/StreamingInputCall", Status.CANCELLED.getCode(), true);
    // Do not check server-side metrics, because the status on the server side is undetermined.
    }
}
Also used : StreamingInputCallRequest(io.grpc.testing.integration.Messages.StreamingInputCallRequest) StatusRuntimeException(io.grpc.StatusRuntimeException) MetricsRecord(io.grpc.internal.testing.StatsTestUtils.MetricsRecord) StreamingInputCallResponse(io.grpc.testing.integration.Messages.StreamingInputCallResponse) Test(org.junit.Test)

Example 7 with MetricsRecord

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

the class AbstractInteropTest method assertZeroRetryRecorded.

private void assertZeroRetryRecorded() {
    MetricsRecord retryRecord = clientStatsRecorder.pollRecord();
    assertThat(retryRecord.getMetric(RETRIES_PER_CALL)).isEqualTo(0);
    assertThat(retryRecord.getMetric(TRANSPARENT_RETRIES_PER_CALL)).isEqualTo(0);
    assertThat(retryRecord.getMetric(RETRY_DELAY_PER_CALL)).isEqualTo(0D);
}
Also used : MetricsRecord(io.grpc.internal.testing.StatsTestUtils.MetricsRecord)

Example 8 with MetricsRecord

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

the class AbstractInteropTest method timeoutOnSleepingServer.

/**
 * Start a fullDuplexCall which the server will not respond, and verify the deadline expires.
 */
@SuppressWarnings("MissingFail")
@Test
public void timeoutOnSleepingServer() throws Exception {
    TestServiceGrpc.TestServiceStub stub = asyncStub.withDeadlineAfter(1, TimeUnit.MILLISECONDS);
    StreamRecorder<StreamingOutputCallResponse> responseObserver = StreamRecorder.create();
    StreamObserver<StreamingOutputCallRequest> requestObserver = stub.fullDuplexCall(responseObserver);
    StreamingOutputCallRequest request = StreamingOutputCallRequest.newBuilder().setPayload(Payload.newBuilder().setBody(ByteString.copyFrom(new byte[27182]))).build();
    try {
        requestObserver.onNext(request);
    } catch (IllegalStateException expected) {
    // This can happen if the stream has already been terminated due to deadline exceeded.
    }
    assertTrue(responseObserver.awaitCompletion(operationTimeoutMillis(), TimeUnit.MILLISECONDS));
    assertEquals(0, responseObserver.getValues().size());
    assertEquals(Status.DEADLINE_EXCEEDED.getCode(), Status.fromThrowable(responseObserver.getError()).getCode());
    if (metricsExpected()) {
        // CensusStreamTracerModule record final status in the interceptor, thus is guaranteed to be
        // recorded.  The tracer stats rely on the stream being created, which is not always the case
        // in this test, thus we will not check that.
        MetricsRecord clientStartRecord = clientStatsRecorder.pollRecord(5, TimeUnit.SECONDS);
        checkStartTags(clientStartRecord, "grpc.testing.TestService/FullDuplexCall", true);
        MetricsRecord clientEndRecord = clientStatsRecorder.pollRecord(5, TimeUnit.SECONDS);
        checkEndTags(clientEndRecord, "grpc.testing.TestService/FullDuplexCall", Status.DEADLINE_EXCEEDED.getCode(), true);
    }
}
Also used : MetricsRecord(io.grpc.internal.testing.StatsTestUtils.MetricsRecord) StreamingOutputCallRequest(io.grpc.testing.integration.Messages.StreamingOutputCallRequest) StreamingOutputCallResponse(io.grpc.testing.integration.Messages.StreamingOutputCallResponse) Test(org.junit.Test)

Example 9 with MetricsRecord

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

the class AbstractInteropTest method deadlineExceeded.

@Test
public void deadlineExceeded() throws Exception {
    // warm up the channel and JVM
    blockingStub.emptyCall(Empty.getDefaultInstance());
    TestServiceGrpc.TestServiceBlockingStub stub = blockingStub.withDeadlineAfter(1, TimeUnit.SECONDS);
    StreamingOutputCallRequest request = StreamingOutputCallRequest.newBuilder().addResponseParameters(ResponseParameters.newBuilder().setIntervalUs((int) TimeUnit.SECONDS.toMicros(20))).build();
    try {
        stub.streamingOutputCall(request).next();
        fail("Expected deadline to be exceeded");
    } catch (StatusRuntimeException ex) {
        assertEquals(Status.DEADLINE_EXCEEDED.getCode(), ex.getStatus().getCode());
        String desc = ex.getStatus().getDescription();
        assertTrue(desc, // If client expires first, it'd generate this message
        Pattern.matches("deadline exceeded after .*s. \\[.*\\]", desc) || // message
        desc.startsWith("ClientCall was cancelled at or after deadline."));
    }
    assertStatsTrace("grpc.testing.TestService/EmptyCall", Status.Code.OK);
    if (metricsExpected()) {
        // Stream may not have been created before deadline is exceeded, thus we don't test the tracer
        // stats.
        MetricsRecord clientStartRecord = clientStatsRecorder.pollRecord(5, TimeUnit.SECONDS);
        checkStartTags(clientStartRecord, "grpc.testing.TestService/StreamingOutputCall", true);
        MetricsRecord clientEndRecord = clientStatsRecorder.pollRecord(5, TimeUnit.SECONDS);
        checkEndTags(clientEndRecord, "grpc.testing.TestService/StreamingOutputCall", Status.Code.DEADLINE_EXCEEDED, true);
    // Do not check server-side metrics, because the status on the server side is undetermined.
    }
}
Also used : MetricsRecord(io.grpc.internal.testing.StatsTestUtils.MetricsRecord) StatusRuntimeException(io.grpc.StatusRuntimeException) ByteString(com.google.protobuf.ByteString) StreamingOutputCallRequest(io.grpc.testing.integration.Messages.StreamingOutputCallRequest) Test(org.junit.Test)

Example 10 with MetricsRecord

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

the class MessageFramerTest method checkStats.

private void checkStats(long wireBytesSent, long uncompressedBytesSent) {
    statsTraceCtx.callEnded(Status.OK);
    MetricsRecord record = statsCtxFactory.pollRecord();
    assertEquals(0, record.getMetricAsLongOrFail(RpcConstants.RPC_SERVER_REQUEST_BYTES));
    assertEquals(0, record.getMetricAsLongOrFail(RpcConstants.RPC_SERVER_UNCOMPRESSED_REQUEST_BYTES));
    assertEquals(wireBytesSent, record.getMetricAsLongOrFail(RpcConstants.RPC_SERVER_RESPONSE_BYTES));
    assertEquals(uncompressedBytesSent, record.getMetricAsLongOrFail(RpcConstants.RPC_SERVER_UNCOMPRESSED_RESPONSE_BYTES));
    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));
}
Also used : MetricsRecord(io.grpc.internal.testing.StatsTestUtils.MetricsRecord)

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