Search in sources :

Example 1 with Exemplar

use of io.opencensus.metrics.data.Exemplar in project instrumentation-java by census-instrumentation.

the class MetricsProtoUtils method toBucketProto.

private static DistributionValue.Bucket toBucketProto(io.opencensus.metrics.export.Distribution.Bucket bucket) {
    DistributionValue.Bucket.Builder builder = DistributionValue.Bucket.newBuilder().setCount(bucket.getCount());
    Exemplar exemplar = bucket.getExemplar();
    if (exemplar != null) {
        builder.setExemplar(toExemplarProto(exemplar));
    }
    return builder.build();
}
Also used : Exemplar(io.opencensus.metrics.data.Exemplar)

Example 2 with Exemplar

use of io.opencensus.metrics.data.Exemplar in project instrumentation-java by census-instrumentation.

the class MutableAggregationTest method testAdd_DistributionWithExemplarAttachments.

@Test
public void testAdd_DistributionWithExemplarAttachments() {
    MutableDistribution mutableDistribution = MutableDistribution.create(BUCKET_BOUNDARIES);
    MutableDistribution mutableDistributionNoHistogram = MutableDistribution.create(BUCKET_BOUNDARIES_EMPTY);
    List<Double> values = Arrays.asList(-1.0, 1.0, -5.0, 20.0, 5.0);
    List<Map<String, AttachmentValue>> attachmentsList = ImmutableList.<Map<String, AttachmentValue>>of(Collections.<String, AttachmentValue>singletonMap("k1", ATTACHMENT_VALUE_1), Collections.<String, AttachmentValue>singletonMap("k2", ATTACHMENT_VALUE_2), Collections.<String, AttachmentValue>singletonMap("k3", ATTACHMENT_VALUE_3), Collections.<String, AttachmentValue>singletonMap("k4", ATTACHMENT_VALUE_4), Collections.<String, AttachmentValue>singletonMap("k5", ATTACHMENT_VALUE_5));
    List<Timestamp> timestamps = Arrays.asList(Timestamp.fromMillis(500), Timestamp.fromMillis(1000), Timestamp.fromMillis(2000), Timestamp.fromMillis(3000), Timestamp.fromMillis(4000));
    for (int i = 0; i < values.size(); i++) {
        mutableDistribution.add(values.get(i), attachmentsList.get(i), timestamps.get(i));
        mutableDistributionNoHistogram.add(values.get(i), attachmentsList.get(i), timestamps.get(i));
    }
    // Each bucket can only have up to one exemplar. If there are more than one exemplars in a
    // bucket, only the last one will be kept.
    List<Exemplar> expected = Arrays.<Exemplar>asList(Exemplar.create(values.get(4), timestamps.get(4), attachmentsList.get(4)), Exemplar.create(values.get(3), timestamps.get(3), attachmentsList.get(3)));
    assertThat(mutableDistribution.getExemplars()).asList().containsExactlyElementsIn(expected).inOrder();
    assertThat(mutableDistributionNoHistogram.getExemplars()).isNull();
}
Also used : Exemplar(io.opencensus.metrics.data.Exemplar) MutableDistribution(io.opencensus.implcore.stats.MutableAggregation.MutableDistribution) MutableLastValueDouble(io.opencensus.implcore.stats.MutableAggregation.MutableLastValueDouble) MutableSumDouble(io.opencensus.implcore.stats.MutableAggregation.MutableSumDouble) SumDataDouble(io.opencensus.stats.AggregationData.SumDataDouble) LastValueDataDouble(io.opencensus.stats.AggregationData.LastValueDataDouble) Map(java.util.Map) Timestamp(io.opencensus.common.Timestamp) Point(io.opencensus.metrics.export.Point) Test(org.junit.Test)

Example 3 with Exemplar

use of io.opencensus.metrics.data.Exemplar in project instrumentation-java by census-instrumentation.

the class StatsRecorderImplTest method record_WithAttachments_Distribution.

@Test
public void record_WithAttachments_Distribution() {
    testClock.setTime(START_TIME);
    View view = View.create(VIEW_NAME, "description", MEASURE_DOUBLE, DISTRIBUTION, Arrays.asList(KEY));
    viewManager.registerView(view);
    recordWithAttachments();
    ViewData viewData = viewManager.getView(VIEW_NAME);
    assertThat(viewData).isNotNull();
    DistributionData distributionData = (DistributionData) viewData.getAggregationMap().get(Collections.singletonList(VALUE));
    List<Exemplar> expected = Arrays.asList(Exemplar.create(1.0, Timestamp.create(2, 0), Collections.singletonMap("k2", ATTACHMENT_VALUE_2)), Exemplar.create(12.0, Timestamp.create(3, 0), Collections.singletonMap("k1", ATTACHMENT_VALUE_3)));
    assertThat(distributionData.getExemplars()).containsExactlyElementsIn(expected).inOrder();
}
Also used : Exemplar(io.opencensus.metrics.data.Exemplar) DistributionData(io.opencensus.stats.AggregationData.DistributionData) StatsTestUtil.createEmptyViewData(io.opencensus.implcore.stats.StatsTestUtil.createEmptyViewData) ViewData(io.opencensus.stats.ViewData) View(io.opencensus.stats.View) Test(org.junit.Test)

Example 4 with Exemplar

use of io.opencensus.metrics.data.Exemplar in project instrumentation-java by census-instrumentation.

the class DistributionTest method createAndGet_Distribution.

@Test
public void createAndGet_Distribution() {
    Exemplar exemplar = Exemplar.create(15.0, TIMESTAMP, ATTACHMENTS);
    List<Double> bucketBounds = Arrays.asList(1.0, 2.0, 5.0);
    BucketOptions bucketOptions = BucketOptions.explicitOptions(bucketBounds);
    List<Bucket> buckets = Arrays.asList(Bucket.create(3), Bucket.create(1), Bucket.create(2), Bucket.create(4, exemplar));
    Distribution distribution = Distribution.create(10, 6.6, 678.54, bucketOptions, buckets);
    assertThat(distribution.getCount()).isEqualTo(10);
    assertThat(distribution.getSum()).isWithin(TOLERANCE).of(6.6);
    assertThat(distribution.getSumOfSquaredDeviations()).isWithin(TOLERANCE).of(678.54);
    final List<Double> actual = new ArrayList<Double>();
    distribution.getBucketOptions().match(new Function<ExplicitOptions, Object>() {

        @Override
        public Object apply(ExplicitOptions arg) {
            actual.addAll(arg.getBucketBoundaries());
            return null;
        }
    }, Functions.throwAssertionError());
    assertThat(actual).containsExactlyElementsIn(bucketBounds).inOrder();
    assertThat(distribution.getBuckets()).containsExactlyElementsIn(buckets).inOrder();
}
Also used : ExplicitOptions(io.opencensus.metrics.export.Distribution.BucketOptions.ExplicitOptions) Exemplar(io.opencensus.metrics.data.Exemplar) Bucket(io.opencensus.metrics.export.Distribution.Bucket) BucketOptions(io.opencensus.metrics.export.Distribution.BucketOptions) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 5 with Exemplar

use of io.opencensus.metrics.data.Exemplar in project instrumentation-java by census-instrumentation.

the class AggregationDataTest method testCreateDistributionDataWithExemplar.

@Test
public void testCreateDistributionDataWithExemplar() {
    Exemplar exemplar1 = Exemplar.create(4, TIMESTAMP_2, ATTACHMENTS);
    Exemplar exemplar2 = Exemplar.create(1, TIMESTAMP_1, ATTACHMENTS);
    DistributionData distributionData = DistributionData.create(7.7, 10, 32.2, Arrays.asList(4L, 1L), Arrays.asList(exemplar1, exemplar2));
    assertThat(distributionData.getExemplars()).containsExactly(exemplar1, exemplar2).inOrder();
}
Also used : Exemplar(io.opencensus.metrics.data.Exemplar) DistributionData(io.opencensus.stats.AggregationData.DistributionData) Test(org.junit.Test)

Aggregations

Exemplar (io.opencensus.metrics.data.Exemplar)7 Test (org.junit.Test)6 Bucket (io.opencensus.metrics.export.Distribution.Bucket)2 DistributionData (io.opencensus.stats.AggregationData.DistributionData)2 Timestamp (io.opencensus.common.Timestamp)1 MutableDistribution (io.opencensus.implcore.stats.MutableAggregation.MutableDistribution)1 MutableLastValueDouble (io.opencensus.implcore.stats.MutableAggregation.MutableLastValueDouble)1 MutableSumDouble (io.opencensus.implcore.stats.MutableAggregation.MutableSumDouble)1 StatsTestUtil.createEmptyViewData (io.opencensus.implcore.stats.StatsTestUtil.createEmptyViewData)1 BucketOptions (io.opencensus.metrics.export.Distribution.BucketOptions)1 ExplicitOptions (io.opencensus.metrics.export.Distribution.BucketOptions.ExplicitOptions)1 Point (io.opencensus.metrics.export.Point)1 LastValueDataDouble (io.opencensus.stats.AggregationData.LastValueDataDouble)1 SumDataDouble (io.opencensus.stats.AggregationData.SumDataDouble)1 View (io.opencensus.stats.View)1 ViewData (io.opencensus.stats.ViewData)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1