Search in sources :

Example 21 with TagValue

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;
}
Also used : ArrayList(java.util.ArrayList) TagKey(io.opencensus.tags.TagKey) TagValue(io.opencensus.tags.TagValue) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 22 with TagValue

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);
}
Also used : MutableMean(io.opencensus.implcore.stats.MutableAggregation.MutableMean) TagValue(io.opencensus.tags.TagValue) Test(org.junit.Test)

Aggregations

TagValue (io.opencensus.tags.TagValue)22 StatsTestUtils (io.grpc.internal.testing.StatsTestUtils)8 Metadata (io.grpc.Metadata)7 TagKey (io.opencensus.tags.TagKey)7 Test (org.junit.Test)7 ClientStreamTracer (io.grpc.ClientStreamTracer)5 CallAttemptsTracerFactory (io.grpc.census.CensusTracingModule.CallAttemptsTracerFactory)5 Context (io.grpc.Context)4 SpanContext (io.opencensus.trace.SpanContext)4 Status (io.grpc.Status)3 AggregationData (io.opencensus.stats.AggregationData)3 View (io.opencensus.stats.View)3 TagContext (io.opencensus.tags.TagContext)3 CallOptions (io.grpc.CallOptions)2 ServerStreamTracer (io.grpc.ServerStreamTracer)2 MetricsRecord (io.grpc.internal.testing.StatsTestUtils.MetricsRecord)2 TagValueWithMetadata (io.opencensus.implcore.tags.TagValueWithMetadata)2 ViewData (io.opencensus.stats.ViewData)2 List (java.util.List)2 Map (java.util.Map)2