Search in sources :

Example 1 with MutableDistribution

use of io.opencensus.implcore.stats.MutableAggregation.MutableDistribution in project instrumentation-java by census-instrumentation.

the class MutableAggregationTest method testCreateEmpty.

@Test
public void testCreateEmpty() {
    assertThat(MutableSumDouble.create().getSum()).isWithin(TOLERANCE).of(0);
    assertThat(MutableSumLong.create().getSum()).isWithin(TOLERANCE).of(0);
    assertThat(MutableCount.create().getCount()).isEqualTo(0);
    assertThat(MutableMean.create().getMean()).isWithin(TOLERANCE).of(0);
    assertThat(MutableLastValueDouble.create().getLastValue()).isNaN();
    assertThat(MutableLastValueLong.create().getLastValue()).isNaN();
    BucketBoundaries bucketBoundaries = BucketBoundaries.create(Arrays.asList(0.1, 2.2, 33.3));
    MutableDistribution mutableDistribution = MutableDistribution.create(bucketBoundaries);
    assertThat(mutableDistribution.getMean()).isWithin(TOLERANCE).of(0);
    assertThat(mutableDistribution.getCount()).isEqualTo(0);
    assertThat(mutableDistribution.getSumOfSquaredDeviations()).isWithin(TOLERANCE).of(0);
    assertThat(mutableDistribution.getBucketCounts()).isEqualTo(new long[4]);
    assertThat(mutableDistribution.getExemplars()).isEqualTo(new Exemplar[4]);
    MutableDistribution mutableDistributionNoHistogram = MutableDistribution.create(BUCKET_BOUNDARIES_EMPTY);
    assertThat(mutableDistributionNoHistogram.getExemplars()).isNull();
}
Also used : MutableDistribution(io.opencensus.implcore.stats.MutableAggregation.MutableDistribution) BucketBoundaries(io.opencensus.stats.BucketBoundaries) Test(org.junit.Test)

Example 2 with MutableDistribution

use of io.opencensus.implcore.stats.MutableAggregation.MutableDistribution 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 MutableDistribution

use of io.opencensus.implcore.stats.MutableAggregation.MutableDistribution in project instrumentation-java by census-instrumentation.

the class RecordUtilsTest method createMutableAggregation.

@Test
public void createMutableAggregation() {
    BucketBoundaries bucketBoundaries = BucketBoundaries.create(Arrays.asList(-1.0, 0.0, 1.0));
    assertThat(RecordUtils.createMutableAggregation(Sum.create(), MEASURE_DOUBLE).toAggregationData()).isEqualTo(SumDataDouble.create(0));
    assertThat(RecordUtils.createMutableAggregation(Sum.create(), MEASURE_LONG).toAggregationData()).isEqualTo(SumDataLong.create(0));
    assertThat(RecordUtils.createMutableAggregation(Count.create(), MEASURE_DOUBLE).toAggregationData()).isEqualTo(CountData.create(0));
    assertThat(RecordUtils.createMutableAggregation(Count.create(), MEASURE_LONG).toAggregationData()).isEqualTo(CountData.create(0));
    assertThat(RecordUtils.createMutableAggregation(Mean.create(), MEASURE_DOUBLE).toAggregationData()).isEqualTo(MeanData.create(0, 0));
    assertThat(RecordUtils.createMutableAggregation(Mean.create(), MEASURE_LONG).toAggregationData()).isEqualTo(MeanData.create(0, 0));
    assertThat(RecordUtils.createMutableAggregation(LastValue.create(), MEASURE_DOUBLE).toAggregationData()).isEqualTo(LastValueDataDouble.create(Double.NaN));
    assertThat(RecordUtils.createMutableAggregation(LastValue.create(), MEASURE_LONG).toAggregationData()).isEqualTo(LastValueDataLong.create(0));
    MutableDistribution mutableDistribution = (MutableDistribution) RecordUtils.createMutableAggregation(Distribution.create(bucketBoundaries), MEASURE_DOUBLE);
    assertThat(mutableDistribution.getSumOfSquaredDeviations()).isWithin(EPSILON).of(0);
    assertThat(mutableDistribution.getBucketCounts()).isEqualTo(new long[2]);
}
Also used : MutableDistribution(io.opencensus.implcore.stats.MutableAggregation.MutableDistribution) BucketBoundaries(io.opencensus.stats.BucketBoundaries) Test(org.junit.Test)

Example 4 with MutableDistribution

use of io.opencensus.implcore.stats.MutableAggregation.MutableDistribution in project instrumentation-java by census-instrumentation.

the class MutableAggregationTest method testCombine_Distribution.

@Test
public void testCombine_Distribution() {
    // combine() for Mutable Distribution will ignore fractional stats
    MutableDistribution distribution1 = MutableDistribution.create(BUCKET_BOUNDARIES);
    MutableDistribution distribution2 = MutableDistribution.create(BUCKET_BOUNDARIES);
    MutableDistribution distribution3 = MutableDistribution.create(BUCKET_BOUNDARIES);
    for (double val : Arrays.asList(5.0, -5.0)) {
        distribution1.add(val, Collections.<String, AttachmentValue>emptyMap(), TIMESTAMP);
    }
    for (double val : Arrays.asList(10.0, 20.0)) {
        distribution2.add(val, Collections.<String, AttachmentValue>emptyMap(), TIMESTAMP);
    }
    for (double val : Arrays.asList(-10.0, 15.0, -15.0, -20.0)) {
        distribution3.add(val, Collections.<String, AttachmentValue>emptyMap(), TIMESTAMP);
    }
    MutableDistribution combined = MutableDistribution.create(BUCKET_BOUNDARIES);
    // distribution1 will be combined
    combined.combine(distribution1, 1.0);
    // distribution2 will be ignored
    combined.combine(distribution2, 0.6);
    verifyMutableDistribution(combined, 0, 2, 50.0, new long[] { 2, 0 });
    // distribution2 will be combined
    combined.combine(distribution2, 1.0);
    verifyMutableDistribution(combined, 7.5, 4, 325.0, new long[] { 2, 2 });
    // distribution3 will be combined
    combined.combine(distribution3, 1.0);
    verifyMutableDistribution(combined, 0, 8, 1500.0, new long[] { 5, 3 });
}
Also used : MutableDistribution(io.opencensus.implcore.stats.MutableAggregation.MutableDistribution) Test(org.junit.Test)

Example 5 with MutableDistribution

use of io.opencensus.implcore.stats.MutableAggregation.MutableDistribution in project instrumentation-java by census-instrumentation.

the class MutableAggregationTest method testNoBoundaries.

@Test
public void testNoBoundaries() {
    MutableDistribution noBoundaries = MutableDistribution.create(BucketBoundaries.create(Collections.<Double>emptyList()));
    assertThat(noBoundaries.getBucketCounts().length).isEqualTo(1);
    assertThat(noBoundaries.getBucketCounts()[0]).isEqualTo(0);
}
Also used : 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) Test(org.junit.Test)

Aggregations

MutableDistribution (io.opencensus.implcore.stats.MutableAggregation.MutableDistribution)5 Test (org.junit.Test)5 MutableLastValueDouble (io.opencensus.implcore.stats.MutableAggregation.MutableLastValueDouble)2 MutableSumDouble (io.opencensus.implcore.stats.MutableAggregation.MutableSumDouble)2 LastValueDataDouble (io.opencensus.stats.AggregationData.LastValueDataDouble)2 SumDataDouble (io.opencensus.stats.AggregationData.SumDataDouble)2 BucketBoundaries (io.opencensus.stats.BucketBoundaries)2 Timestamp (io.opencensus.common.Timestamp)1 Exemplar (io.opencensus.metrics.data.Exemplar)1 Point (io.opencensus.metrics.export.Point)1 Map (java.util.Map)1