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());
}
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());
}
}
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);
}
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);
}
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();
}
Aggregations