use of io.opencensus.tags.TagValue in project instrumentation-java by census-instrumentation.
the class RecordUtils method getTagValues.
@VisibleForTesting
static List</*@Nullable*/
TagValue> getTagValues(Map<? extends TagKey, TagValueWithMetadata> tags, List<? extends TagKey> columns) {
List<TagValue> /*@Nullable*/
tagValues = new ArrayList</*@Nullable*/
TagValue>(columns.size());
// Every view aggregates every measure. This is similar to doing a GROUPBY view’s keys.
for (int i = 0; i < columns.size(); ++i) {
TagKey tagKey = columns.get(i);
if (!tags.containsKey(tagKey)) {
@javax.annotation.Nullable TagValue tagValue = UNKNOWN_TAG_VALUE;
TagKey[] newKeys = RPC_TAG_MAPPINGS.get(tagKey);
if (newKeys != null) {
tagValue = getTagValueForDeprecatedRpcTag(tags, newKeys);
}
tagValues.add(tagValue);
} else {
tagValues.add(tags.get(tagKey).getTagValue());
}
}
return tagValues;
}
use of io.opencensus.tags.TagValue in project instrumentation-java by census-instrumentation.
the class IntervalBucketTest method testRecord.
@Test
public void testRecord() {
IntervalBucket bucket = new IntervalBucket(START, MINUTE, MEAN, MEASURE_DOUBLE);
List<TagValue> tagValues1 = Arrays.<TagValue>asList(TagValue.create("VALUE1"));
List<TagValue> tagValues2 = Arrays.<TagValue>asList(TagValue.create("VALUE2"));
bucket.record(tagValues1, 5.0, Collections.<String, AttachmentValue>emptyMap(), START);
bucket.record(tagValues1, 15.0, Collections.<String, AttachmentValue>emptyMap(), START);
bucket.record(tagValues2, 10.0, Collections.<String, AttachmentValue>emptyMap(), START);
assertThat(bucket.getTagValueAggregationMap().keySet()).containsExactly(tagValues1, tagValues2);
MutableMean mutableMean1 = (MutableMean) bucket.getTagValueAggregationMap().get(tagValues1);
MutableMean mutableMean2 = (MutableMean) bucket.getTagValueAggregationMap().get(tagValues2);
assertThat(mutableMean1.getSum()).isWithin(TOLERANCE).of(20);
assertThat(mutableMean2.getSum()).isWithin(TOLERANCE).of(10);
assertThat(mutableMean1.getCount()).isEqualTo(2);
assertThat(mutableMean2.getCount()).isEqualTo(1);
}
Aggregations