Search in sources :

Example 1 with BucketOptions

use of io.opencensus.metrics.export.Distribution.BucketOptions 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);
}
Also used : Bucket(io.opencensus.metrics.export.Distribution.Bucket) BucketOptions(io.opencensus.metrics.export.Distribution.BucketOptions) Test(org.junit.Test)

Example 2 with BucketOptions

use of io.opencensus.metrics.export.Distribution.BucketOptions 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);
}
Also used : Bucket(io.opencensus.metrics.export.Distribution.Bucket) BucketOptions(io.opencensus.metrics.export.Distribution.BucketOptions) Test(org.junit.Test)

Example 3 with BucketOptions

use of io.opencensus.metrics.export.Distribution.BucketOptions in project instrumentation-java by census-instrumentation.

the class DistributionTest method createAndGet_ExplicitBuckets.

@Test
public void createAndGet_ExplicitBuckets() {
    List<Double> bucketBounds = Arrays.asList(1.0, 2.0, 3.0);
    BucketOptions bucketOptions = BucketOptions.explicitOptions(bucketBounds);
    final List<Double> actual = new ArrayList<Double>();
    bucketOptions.match(new Function<ExplicitOptions, Object>() {

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

Example 4 with BucketOptions

use of io.opencensus.metrics.export.Distribution.BucketOptions 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 BucketOptions

use of io.opencensus.metrics.export.Distribution.BucketOptions in project instrumentation-java by census-instrumentation.

the class DistributionTest method createDistribution_NullBucketList.

@Test
public void createDistribution_NullBucketList() {
    List<Double> bucketBounds = Arrays.asList(1.0, 2.0, 5.0);
    BucketOptions bucketOptions = BucketOptions.explicitOptions(bucketBounds);
    thrown.expect(NullPointerException.class);
    thrown.expectMessage("buckets");
    Distribution.create(10, 6.6, 678.54, bucketOptions, null);
}
Also used : BucketOptions(io.opencensus.metrics.export.Distribution.BucketOptions) Test(org.junit.Test)

Aggregations

BucketOptions (io.opencensus.metrics.export.Distribution.BucketOptions)10 Test (org.junit.Test)9 Bucket (io.opencensus.metrics.export.Distribution.Bucket)6 ExplicitOptions (io.opencensus.metrics.export.Distribution.BucketOptions.ExplicitOptions)4 ArrayList (java.util.ArrayList)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 LabelValue (io.opencensus.metrics.LabelValue)1 Exemplar (io.opencensus.metrics.data.Exemplar)1 Distribution (io.opencensus.metrics.export.Distribution)1 Summary (io.opencensus.metrics.export.Summary)1 ValueAtPercentile (io.opencensus.metrics.export.Summary.Snapshot.ValueAtPercentile)1 Sample (io.prometheus.client.Collector.MetricFamilySamples.Sample)1 Collector.doubleToGoString (io.prometheus.client.Collector.doubleToGoString)1 List (java.util.List)1