use of io.opencensus.tags.TagValue in project grpc-java by grpc.
the class CensusModulesTest method subtestServerBasicStatsNoHeaders.
private void subtestServerBasicStatsNoHeaders(boolean recordStarts, boolean recordFinishes, boolean recordRealTime) {
CensusStatsModule localCensusStats = new CensusStatsModule(tagger, tagCtxSerializer, statsRecorder, fakeClock.getStopwatchSupplier(), true, recordStarts, recordFinishes, recordRealTime, true);
ServerStreamTracer.Factory tracerFactory = localCensusStats.getServerTracerFactory();
ServerStreamTracer tracer = tracerFactory.newServerStreamTracer(method.getFullMethodName(), new Metadata());
if (recordStarts) {
StatsTestUtils.MetricsRecord record = statsRecorder.pollRecord();
assertNotNull(record);
assertNoClientContent(record);
assertEquals(1, record.tags.size());
TagValue methodTag = record.tags.get(RpcMeasureConstants.GRPC_SERVER_METHOD);
assertEquals(method.getFullMethodName(), methodTag.asString());
assertEquals(1, record.getMetricAsLongOrFail(DeprecatedCensusConstants.RPC_SERVER_STARTED_COUNT));
} else {
assertNull(statsRecorder.pollRecord());
}
Context filteredContext = tracer.filterContext(Context.ROOT);
TagContext statsCtx = io.opencensus.tags.unsafe.ContextUtils.getValue(filteredContext);
assertEquals(tagger.emptyBuilder().putLocal(RpcMeasureConstants.GRPC_SERVER_METHOD, TagValue.create(method.getFullMethodName())).build(), statsCtx);
tracer.inboundMessage(0);
assertRealTimeMetric(RpcMeasureConstants.GRPC_SERVER_RECEIVED_MESSAGES_PER_METHOD, 1, recordRealTime, false);
tracer.inboundWireSize(34);
assertRealTimeMetric(RpcMeasureConstants.GRPC_SERVER_RECEIVED_BYTES_PER_METHOD, 34, recordRealTime, false);
tracer.inboundUncompressedSize(67);
fakeClock.forwardTime(100, MILLISECONDS);
tracer.outboundMessage(0);
assertRealTimeMetric(RpcMeasureConstants.GRPC_SERVER_SENT_MESSAGES_PER_METHOD, 1, recordRealTime, false);
tracer.outboundWireSize(1028);
assertRealTimeMetric(RpcMeasureConstants.GRPC_SERVER_SENT_BYTES_PER_METHOD, 1028, recordRealTime, false);
tracer.outboundUncompressedSize(1128);
fakeClock.forwardTime(16, MILLISECONDS);
tracer.inboundMessage(1);
assertRealTimeMetric(RpcMeasureConstants.GRPC_SERVER_RECEIVED_MESSAGES_PER_METHOD, 1, recordRealTime, false);
tracer.inboundWireSize(154);
assertRealTimeMetric(RpcMeasureConstants.GRPC_SERVER_RECEIVED_BYTES_PER_METHOD, 154, recordRealTime, false);
tracer.inboundUncompressedSize(552);
tracer.outboundMessage(1);
assertRealTimeMetric(RpcMeasureConstants.GRPC_SERVER_SENT_MESSAGES_PER_METHOD, 1, recordRealTime, false);
tracer.outboundWireSize(99);
assertRealTimeMetric(RpcMeasureConstants.GRPC_SERVER_SENT_BYTES_PER_METHOD, 99, recordRealTime, false);
tracer.outboundUncompressedSize(865);
fakeClock.forwardTime(24, MILLISECONDS);
tracer.streamClosed(Status.CANCELLED);
if (recordFinishes) {
StatsTestUtils.MetricsRecord record = statsRecorder.pollRecord();
assertNotNull(record);
assertNoClientContent(record);
TagValue methodTag = record.tags.get(RpcMeasureConstants.GRPC_SERVER_METHOD);
assertEquals(method.getFullMethodName(), methodTag.asString());
TagValue statusTag = record.tags.get(RpcMeasureConstants.GRPC_SERVER_STATUS);
assertEquals(Status.Code.CANCELLED.toString(), statusTag.asString());
assertEquals(1, record.getMetricAsLongOrFail(DeprecatedCensusConstants.RPC_SERVER_FINISHED_COUNT));
assertEquals(1, record.getMetricAsLongOrFail(DeprecatedCensusConstants.RPC_SERVER_ERROR_COUNT));
assertEquals(2, record.getMetricAsLongOrFail(DeprecatedCensusConstants.RPC_SERVER_RESPONSE_COUNT));
assertEquals(1028 + 99, record.getMetricAsLongOrFail(DeprecatedCensusConstants.RPC_SERVER_RESPONSE_BYTES));
assertEquals(1128 + 865, record.getMetricAsLongOrFail(DeprecatedCensusConstants.RPC_SERVER_UNCOMPRESSED_RESPONSE_BYTES));
assertEquals(2, record.getMetricAsLongOrFail(DeprecatedCensusConstants.RPC_SERVER_REQUEST_COUNT));
assertEquals(34 + 154, record.getMetricAsLongOrFail(DeprecatedCensusConstants.RPC_SERVER_REQUEST_BYTES));
assertEquals(67 + 552, record.getMetricAsLongOrFail(DeprecatedCensusConstants.RPC_SERVER_UNCOMPRESSED_REQUEST_BYTES));
assertEquals(100 + 16 + 24, record.getMetricAsLongOrFail(DeprecatedCensusConstants.RPC_SERVER_SERVER_LATENCY));
} else {
assertNull(statsRecorder.pollRecord());
}
}
use of io.opencensus.tags.TagValue in project instrumentation-java by census-instrumentation.
the class ViewDataTest method testViewDataEquals.
@Test
public void testViewDataEquals() {
View cumulativeView = View.create(NAME, DESCRIPTION, MEASURE_DOUBLE, DISTRIBUTION, TAG_KEYS, CUMULATIVE);
View intervalView = View.create(NAME, DESCRIPTION, MEASURE_DOUBLE, DISTRIBUTION, TAG_KEYS, INTERVAL_HOUR);
new EqualsTester().addEqualityGroup(ViewData.create(cumulativeView, ENTRIES, CumulativeData.create(Timestamp.fromMillis(1000), Timestamp.fromMillis(2000))), ViewData.create(cumulativeView, ENTRIES, CumulativeData.create(Timestamp.fromMillis(1000), Timestamp.fromMillis(2000)))).addEqualityGroup(ViewData.create(cumulativeView, ENTRIES, CumulativeData.create(Timestamp.fromMillis(1000), Timestamp.fromMillis(3000)))).addEqualityGroup(ViewData.create(intervalView, ENTRIES, IntervalData.create(Timestamp.fromMillis(2000))), ViewData.create(intervalView, ENTRIES, IntervalData.create(Timestamp.fromMillis(2000)))).addEqualityGroup(ViewData.create(intervalView, Collections.<List<TagValue>, AggregationData>emptyMap(), IntervalData.create(Timestamp.fromMillis(2000)))).testEquals();
}
use of io.opencensus.tags.TagValue in project instrumentation-java by census-instrumentation.
the class StatszZPageHandler method emitViewDataRow.
private static void emitViewDataRow(View view, Entry<List</*@Nullable*/
TagValue>, AggregationData> entry, PrintWriter out, Formatter formatter) {
out.write("<tr>");
for (/*@Nullable*/
TagValue tagValue : entry.getKey()) {
String tagValueStr = tagValue == null ? "" : tagValue.asString();
formatter.format("<td class=\"borderRL\">%s</td>", tagValueStr);
}
entry.getValue().match(new Function<SumDataDouble, Void>() {
@Override
public Void apply(SumDataDouble arg) {
formatter.format("<td class=\"borderLL\">%.3f</td>", arg.getSum());
return null;
}
}, new Function<SumDataLong, Void>() {
@Override
public Void apply(SumDataLong arg) {
formatter.format("<td class=\"borderLL\">%d</td>", arg.getSum());
return null;
}
}, new Function<CountData, Void>() {
@Override
public Void apply(CountData arg) {
formatter.format("<td class=\"borderLL\">%d</td>", arg.getCount());
return null;
}
}, new Function<DistributionData, Void>() {
@Override
public Void apply(DistributionData arg) {
checkArgument(view.getAggregation() instanceof Distribution, "Distribution expected.");
formatter.format("<td>%.3f</td>", arg.getMean());
formatter.format("<td class=\"borderLL\">%d</td>", arg.getCount());
formatter.format("<td class=\"borderLL\">%.3f</td>", arg.getMax());
formatter.format("<td class=\"borderLL\">%.3f</td>", arg.getMin());
formatter.format("<td class=\"borderLL\">%.3f</td>", arg.getSumOfSquaredDeviations());
emitHistogramBuckets(((Distribution) view.getAggregation()).getBucketBoundaries().getBoundaries(), arg.getBucketCounts(), out, formatter);
return null;
}
}, new Function<LastValueDataDouble, Void>() {
@Override
public Void apply(LastValueDataDouble arg) {
formatter.format("<td>%.3f</td>", arg.getLastValue());
return null;
}
}, new Function<LastValueDataLong, Void>() {
@Override
public Void apply(LastValueDataLong arg) {
formatter.format("<td>%d</td>", arg.getLastValue());
return null;
}
}, new Function<AggregationData, Void>() {
@Override
public Void apply(AggregationData arg) {
if (arg instanceof AggregationData.MeanData) {
AggregationData.MeanData meanData = (AggregationData.MeanData) arg;
formatter.format("<td>%.3f</td>", meanData.getMean());
formatter.format("<td class=\"borderLL\">%d</td>", meanData.getCount());
return null;
}
throw new IllegalArgumentException("Unknown Aggregation.");
}
});
out.write("</tr>");
}
use of io.opencensus.tags.TagValue in project instrumentation-java by census-instrumentation.
the class BinarySerializationUtils method parseTags.
private static Map<TagKey, TagValueWithMetadata> parseTags(ByteBuffer buffer) throws TagContextDeserializationException {
Map<TagKey, TagValueWithMetadata> tags = new HashMap<TagKey, TagValueWithMetadata>();
int limit = buffer.limit();
// Here chars are equivalent to bytes, since we're using ascii chars.
int totalChars = 0;
while (buffer.position() < limit) {
int type = buffer.get();
if (type == TAG_FIELD_ID) {
TagKey key = createTagKey(decodeString(buffer));
TagValue val = createTagValue(key, decodeString(buffer));
totalChars += key.getName().length();
totalChars += val.asString().length();
tags.put(key, TagValueWithMetadata.create(val, METADATA_UNLIMITED_PROPAGATION));
} else {
// TODO(sebright): Consider storing the rest of the byte array in the TagContext.
break;
}
}
if (totalChars > TAGCONTEXT_SERIALIZED_SIZE_LIMIT) {
throw new TagContextDeserializationException("Size of TagContext exceeds the maximum serialized size " + TAGCONTEXT_SERIALIZED_SIZE_LIMIT);
}
return tags;
}
use of io.opencensus.tags.TagValue in project instrumentation-java by census-instrumentation.
the class CorrelationContextFormat method decodeTag.
// Decodes tag key, value and metadata from the encoded string tag, then puts it into the tag map.
// The format of encoded string tag is name1=value1;properties1=p1;properties2=p2.
private static void decodeTag(String stringTag, Map<TagKey, TagValueWithMetadata> tags) {
String keyWithValue;
int firstPropertyIndex = stringTag.indexOf(TAG_PROPERTIES_DELIMITER);
if (firstPropertyIndex != -1) {
// Tag with properties.
keyWithValue = stringTag.substring(0, firstPropertyIndex);
// TODO(songya): support decoding tag properties.
} else {
// Tag without properties.
keyWithValue = stringTag;
}
List<String> keyValuePair = TAG_KEY_VALUE_SPLITTER.splitToList(keyWithValue);
checkArgument(keyValuePair.size() == 2, "Malformed tag " + stringTag);
TagKey key = TagKey.create(keyValuePair.get(0).trim());
TagValue value = TagValue.create(keyValuePair.get(1).trim());
TagValueWithMetadata valueWithMetadata = TagValueWithMetadata.create(value, METADATA_UNLIMITED_PROPAGATION);
tags.put(key, valueWithMetadata);
}
Aggregations