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();
}
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();
}
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();
}
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();
}
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();
}
Aggregations