use of io.opencensus.metrics.export.Distribution.Bucket in project instrumentation-java by census-instrumentation.
the class StackdriverExportUtils method setBucketCountsAndExemplars.
// Convert OpenCensus Buckets to a list of bucket counts and a list of proto Exemplars, then set
// them to the builder.
private static void setBucketCountsAndExemplars(List<Bucket> buckets, Distribution.Builder builder) {
// The first bucket (underflow bucket) should always be 0 count because the Metrics first bucket
// is [0, first_bound) but StackDriver distribution consists of an underflow bucket (number 0).
builder.addBucketCounts(0L);
for (Bucket bucket : buckets) {
builder.addBucketCounts(bucket.getCount());
@javax.annotation.Nullable io.opencensus.metrics.data.Exemplar exemplar = bucket.getExemplar();
if (exemplar != null) {
builder.addExemplars(toProtoExemplar(exemplar));
}
}
}
use of io.opencensus.metrics.export.Distribution.Bucket in project instrumentation-java by census-instrumentation.
the class DistributionTest method createDistribution_ZeroCountAndPositiveMean.
@Test
public void createDistribution_ZeroCountAndPositiveMean() {
List<Double> bucketBounds = Arrays.asList(1.0, 2.0, 5.0);
BucketOptions bucketOptions = BucketOptions.explicitOptions(bucketBounds);
List<Bucket> buckets = Arrays.asList(Bucket.create(0), Bucket.create(0), Bucket.create(0), Bucket.create(0));
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("sum should be 0 if count is 0.");
Distribution.create(0, 6.6, 0, bucketOptions, buckets);
}
use of io.opencensus.metrics.export.Distribution.Bucket in project instrumentation-java by census-instrumentation.
the class DistributionTest method createAndGet_Bucket.
@Test
public void createAndGet_Bucket() {
Bucket bucket = Bucket.create(98);
assertThat(bucket.getCount()).isEqualTo(98);
assertThat(bucket.getExemplar()).isNull();
}
use of io.opencensus.metrics.export.Distribution.Bucket in project instrumentation-java by census-instrumentation.
the class DistributionTest method createDistribution_NegativeCount.
@Test
public void createDistribution_NegativeCount() {
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));
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("count should be non-negative.");
Distribution.create(-10, 6.6, 678.54, bucketOptions, buckets);
}
use of io.opencensus.metrics.export.Distribution.Bucket 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();
}
Aggregations