Search in sources :

Example 1 with CallAttemptsTracerFactory

use of io.grpc.census.CensusTracingModule.CallAttemptsTracerFactory in project grpc-java by grpc.

the class CensusModulesTest method clientTracingSampledToLocalSpanStore.

@Test
public void clientTracingSampledToLocalSpanStore() {
    CallAttemptsTracerFactory callTracer = censusTracing.newClientCallTracer(null, sampledMethod);
    callTracer.callEnded(Status.OK);
    verify(spyClientSpan).end(EndSpanOptions.builder().setStatus(io.opencensus.trace.Status.OK).setSampleToLocalSpanStore(true).build());
}
Also used : CallAttemptsTracerFactory(io.grpc.census.CensusTracingModule.CallAttemptsTracerFactory) Test(org.junit.Test)

Example 2 with CallAttemptsTracerFactory

use of io.grpc.census.CensusTracingModule.CallAttemptsTracerFactory in project grpc-java by grpc.

the class CensusModulesTest method subtestClientBasicStatsDefaultContext.

private void subtestClientBasicStatsDefaultContext(boolean recordStarts, boolean recordFinishes, boolean recordRealTime) {
    CensusStatsModule localCensusStats = new CensusStatsModule(tagger, tagCtxSerializer, statsRecorder, fakeClock.getStopwatchSupplier(), true, recordStarts, recordFinishes, recordRealTime, true);
    CensusStatsModule.CallAttemptsTracerFactory callAttemptsTracerFactory = new CensusStatsModule.CallAttemptsTracerFactory(localCensusStats, tagger.empty(), method.getFullMethodName());
    Metadata headers = new Metadata();
    ClientStreamTracer tracer = callAttemptsTracerFactory.newClientStreamTracer(STREAM_INFO, headers);
    if (recordStarts) {
        StatsTestUtils.MetricsRecord record = statsRecorder.pollRecord();
        assertNotNull(record);
        assertNoServerContent(record);
        assertEquals(1, record.tags.size());
        TagValue methodTag = record.tags.get(RpcMeasureConstants.GRPC_CLIENT_METHOD);
        assertEquals(method.getFullMethodName(), methodTag.asString());
        assertEquals(1, record.getMetricAsLongOrFail(DeprecatedCensusConstants.RPC_CLIENT_STARTED_COUNT));
    } else {
        assertNull(statsRecorder.pollRecord());
    }
    fakeClock.forwardTime(30, MILLISECONDS);
    tracer.outboundHeaders();
    fakeClock.forwardTime(100, MILLISECONDS);
    tracer.outboundMessage(0);
    assertRealTimeMetric(RpcMeasureConstants.GRPC_CLIENT_SENT_MESSAGES_PER_METHOD, 1, recordRealTime, true);
    tracer.outboundWireSize(1028);
    assertRealTimeMetric(RpcMeasureConstants.GRPC_CLIENT_SENT_BYTES_PER_METHOD, 1028, recordRealTime, true);
    tracer.outboundUncompressedSize(1128);
    fakeClock.forwardTime(16, MILLISECONDS);
    tracer.inboundMessage(0);
    assertRealTimeMetric(RpcMeasureConstants.GRPC_CLIENT_RECEIVED_MESSAGES_PER_METHOD, 1, recordRealTime, true);
    tracer.inboundWireSize(33);
    assertRealTimeMetric(RpcMeasureConstants.GRPC_CLIENT_RECEIVED_BYTES_PER_METHOD, 33, recordRealTime, true);
    tracer.inboundUncompressedSize(67);
    tracer.outboundMessage(1);
    assertRealTimeMetric(RpcMeasureConstants.GRPC_CLIENT_SENT_MESSAGES_PER_METHOD, 1, recordRealTime, true);
    tracer.outboundWireSize(99);
    assertRealTimeMetric(RpcMeasureConstants.GRPC_CLIENT_SENT_BYTES_PER_METHOD, 99, recordRealTime, true);
    tracer.outboundUncompressedSize(865);
    fakeClock.forwardTime(24, MILLISECONDS);
    tracer.inboundMessage(1);
    assertRealTimeMetric(RpcMeasureConstants.GRPC_CLIENT_RECEIVED_MESSAGES_PER_METHOD, 1, recordRealTime, true);
    tracer.inboundWireSize(154);
    assertRealTimeMetric(RpcMeasureConstants.GRPC_CLIENT_RECEIVED_BYTES_PER_METHOD, 154, recordRealTime, true);
    tracer.inboundUncompressedSize(552);
    tracer.streamClosed(Status.OK);
    callAttemptsTracerFactory.callEnded(Status.OK);
    if (recordFinishes) {
        StatsTestUtils.MetricsRecord record = statsRecorder.pollRecord();
        assertNotNull(record);
        assertNoServerContent(record);
        TagValue methodTag = record.tags.get(RpcMeasureConstants.GRPC_CLIENT_METHOD);
        assertEquals(method.getFullMethodName(), methodTag.asString());
        TagValue statusTag = record.tags.get(RpcMeasureConstants.GRPC_CLIENT_STATUS);
        assertEquals(Status.Code.OK.toString(), statusTag.asString());
        assertEquals(1, record.getMetricAsLongOrFail(DeprecatedCensusConstants.RPC_CLIENT_FINISHED_COUNT));
        assertNull(record.getMetric(DeprecatedCensusConstants.RPC_CLIENT_ERROR_COUNT));
        assertEquals(2, record.getMetricAsLongOrFail(DeprecatedCensusConstants.RPC_CLIENT_REQUEST_COUNT));
        assertEquals(1028 + 99, record.getMetricAsLongOrFail(DeprecatedCensusConstants.RPC_CLIENT_REQUEST_BYTES));
        assertEquals(1128 + 865, record.getMetricAsLongOrFail(DeprecatedCensusConstants.RPC_CLIENT_UNCOMPRESSED_REQUEST_BYTES));
        assertEquals(2, record.getMetricAsLongOrFail(DeprecatedCensusConstants.RPC_CLIENT_RESPONSE_COUNT));
        assertEquals(33 + 154, record.getMetricAsLongOrFail(DeprecatedCensusConstants.RPC_CLIENT_RESPONSE_BYTES));
        assertEquals(67 + 552, record.getMetricAsLongOrFail(DeprecatedCensusConstants.RPC_CLIENT_UNCOMPRESSED_RESPONSE_BYTES));
        assertEquals(30 + 100 + 16 + 24, record.getMetricAsLongOrFail(DeprecatedCensusConstants.RPC_CLIENT_ROUNDTRIP_LATENCY));
        assertZeroRetryRecorded();
    } else {
        assertNull(statsRecorder.pollRecord());
    }
}
Also used : ClientStreamTracer(io.grpc.ClientStreamTracer) StatsTestUtils(io.grpc.internal.testing.StatsTestUtils) Metadata(io.grpc.Metadata) TagValue(io.opencensus.tags.TagValue) CallAttemptsTracerFactory(io.grpc.census.CensusTracingModule.CallAttemptsTracerFactory)

Example 3 with CallAttemptsTracerFactory

use of io.grpc.census.CensusTracingModule.CallAttemptsTracerFactory in project grpc-java by grpc.

the class CensusModulesTest method newTagsPopulateOldViews.

@Deprecated
@Test
public void newTagsPopulateOldViews() throws InterruptedException {
    StatsComponent localStats = new StatsComponentImpl();
    // Test views that contain both of the remap tags: method & status.
    localStats.getViewManager().registerView(RpcViewConstants.RPC_CLIENT_ERROR_COUNT_VIEW);
    localStats.getViewManager().registerView(RpcViewConstants.GRPC_CLIENT_COMPLETED_RPC_VIEW);
    CensusStatsModule localCensusStats = new CensusStatsModule(tagger, tagCtxSerializer, localStats.getStatsRecorder(), fakeClock.getStopwatchSupplier(), false, false, true, false, /* real-time */
    true);
    CensusStatsModule.CallAttemptsTracerFactory callAttemptsTracerFactory = new CensusStatsModule.CallAttemptsTracerFactory(localCensusStats, tagger.empty(), method.getFullMethodName());
    Metadata headers = new Metadata();
    ClientStreamTracer tracer = callAttemptsTracerFactory.newClientStreamTracer(STREAM_INFO, headers);
    tracer.streamCreated(Attributes.EMPTY, headers);
    fakeClock.forwardTime(30, MILLISECONDS);
    Status status = Status.PERMISSION_DENIED.withDescription("No you don't");
    tracer.streamClosed(status);
    callAttemptsTracerFactory.callEnded(status);
    // Give OpenCensus a chance to update the views asynchronously.
    Thread.sleep(100);
    assertWithMessage("Legacy error count view had unexpected count").that(getAggregationValueAsLong(localStats, RpcViewConstants.RPC_CLIENT_ERROR_COUNT_VIEW, ImmutableList.of(TagValue.create("PERMISSION_DENIED"), TagValue.create(method.getFullMethodName())))).isEqualTo(1);
    assertWithMessage("New error count view had unexpected count").that(getAggregationValueAsLong(localStats, RpcViewConstants.GRPC_CLIENT_COMPLETED_RPC_VIEW, ImmutableList.of(TagValue.create(method.getFullMethodName()), TagValue.create("PERMISSION_DENIED")))).isEqualTo(1);
}
Also used : Status(io.grpc.Status) ClientStreamTracer(io.grpc.ClientStreamTracer) StatsComponentImpl(io.opencensus.impl.stats.StatsComponentImpl) Metadata(io.grpc.Metadata) StatsComponent(io.opencensus.stats.StatsComponent) CallAttemptsTracerFactory(io.grpc.census.CensusTracingModule.CallAttemptsTracerFactory) Test(org.junit.Test)

Example 4 with CallAttemptsTracerFactory

use of io.grpc.census.CensusTracingModule.CallAttemptsTracerFactory in project grpc-java by grpc.

the class CensusModulesTest method traceHeaders_clientMissingCensusImpl_preservingHeaders.

@Test
public void traceHeaders_clientMissingCensusImpl_preservingHeaders() throws Exception {
    reset(spyClientSpanBuilder);
    reset(spyAttemptSpanBuilder);
    when(spyClientSpanBuilder.startSpan()).thenReturn(BlankSpan.INSTANCE);
    when(spyAttemptSpanBuilder.startSpan()).thenReturn(BlankSpan.INSTANCE);
    Metadata headers = new Metadata();
    headers.put(Metadata.Key.of("never-used-key-bin", Metadata.BINARY_BYTE_MARSHALLER), new byte[] {});
    Set<String> originalHeaderKeys = new HashSet<>(headers.keys());
    CallAttemptsTracerFactory callTracer = censusTracing.newClientCallTracer(BlankSpan.INSTANCE, method);
    callTracer.newClientStreamTracer(STREAM_INFO, headers).streamCreated(Attributes.EMPTY, headers);
    assertThat(headers.keys()).containsExactlyElementsIn(originalHeaderKeys);
}
Also used : Metadata(io.grpc.Metadata) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CallAttemptsTracerFactory(io.grpc.census.CensusTracingModule.CallAttemptsTracerFactory) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with CallAttemptsTracerFactory

use of io.grpc.census.CensusTracingModule.CallAttemptsTracerFactory in project grpc-java by grpc.

the class CensusModulesTest method statsHeadersNotPropagateDefaultContext.

@Test
public void statsHeadersNotPropagateDefaultContext() {
    CensusStatsModule.CallAttemptsTracerFactory callAttemptsTracerFactory = new CensusStatsModule.CallAttemptsTracerFactory(censusStats, tagger.empty(), method.getFullMethodName());
    Metadata headers = new Metadata();
    callAttemptsTracerFactory.newClientStreamTracer(STREAM_INFO, headers).streamCreated(Attributes.EMPTY, headers);
    assertFalse(headers.containsKey(censusStats.statsHeader));
    // Clear recorded stats to satisfy the assertions in wrapUp()
    statsRecorder.rolloverRecords();
}
Also used : Metadata(io.grpc.Metadata) CallAttemptsTracerFactory(io.grpc.census.CensusTracingModule.CallAttemptsTracerFactory) Test(org.junit.Test)

Aggregations

CallAttemptsTracerFactory (io.grpc.census.CensusTracingModule.CallAttemptsTracerFactory)14 Metadata (io.grpc.Metadata)12 Test (org.junit.Test)11 ClientStreamTracer (io.grpc.ClientStreamTracer)8 StatsTestUtils (io.grpc.internal.testing.StatsTestUtils)5 TagValue (io.opencensus.tags.TagValue)5 Context (io.grpc.Context)3 Status (io.grpc.Status)3 TagContext (io.opencensus.tags.TagContext)3 SpanContext (io.opencensus.trace.SpanContext)3 ServerStreamTracer (io.grpc.ServerStreamTracer)2 EndSpanOptions (io.opencensus.trace.EndSpanOptions)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 CallOptions (io.grpc.CallOptions)1 Channel (io.grpc.Channel)1 ClientInterceptor (io.grpc.ClientInterceptor)1 MethodDescriptor (io.grpc.MethodDescriptor)1 StatsComponentImpl (io.opencensus.impl.stats.StatsComponentImpl)1 StatsComponent (io.opencensus.stats.StatsComponent)1 MessageEvent (io.opencensus.trace.MessageEvent)1