use of io.opencensus.stats.ViewData in project instrumentation-java by census-instrumentation.
the class StatsRecorderImplTest method record_UnregisteredMeasure.
@Test
public void record_UnregisteredMeasure() {
View view = View.create(VIEW_NAME, "description", MEASURE_DOUBLE, Sum.create(), Arrays.asList(KEY), Cumulative.create());
viewManager.registerView(view);
statsRecorder.newMeasureMap().put(MEASURE_DOUBLE_NO_VIEW_1, 1.0).put(MEASURE_DOUBLE, 2.0).put(MEASURE_DOUBLE_NO_VIEW_2, 3.0).record(new SimpleTagContext(Tag.create(KEY, VALUE)));
ViewData viewData = viewManager.getView(VIEW_NAME);
// There should be one entry.
StatsTestUtil.assertAggregationMapEquals(viewData.getAggregationMap(), ImmutableMap.of(Arrays.asList(VALUE), StatsTestUtil.createAggregationData(Sum.create(), MEASURE_DOUBLE, 2.0)), 1e-6);
}
use of io.opencensus.stats.ViewData in project instrumentation-java by census-instrumentation.
the class StatsRecorderImplTest method record_WithAttachments_DistributionNoHistogram.
@Test
public void record_WithAttachments_DistributionNoHistogram() {
testClock.setTime(START_TIME);
View view = View.create(VIEW_NAME, "description", MEASURE_DOUBLE, DISTRIBUTION_NO_HISTOGRAM, 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));
// Recording exemplar has no effect if there's no histogram.
assertThat(distributionData.getExemplars()).isEmpty();
}
use of io.opencensus.stats.ViewData in project instrumentation-java by census-instrumentation.
the class StatsRecorderImplTest method record_WithAttachments_Count.
@Test
public void record_WithAttachments_Count() {
testClock.setTime(START_TIME);
View view = View.create(VIEW_NAME, "description", MEASURE_DOUBLE, Count.create(), Arrays.asList(KEY));
viewManager.registerView(view);
recordWithAttachments();
ViewData viewData = viewManager.getView(VIEW_NAME);
assertThat(viewData).isNotNull();
CountData countData = (CountData) viewData.getAggregationMap().get(Collections.singletonList(VALUE));
// Recording exemplar does not affect views with an aggregation other than distribution.
assertThat(countData.getCount()).isEqualTo(2L);
}
use of io.opencensus.stats.ViewData in project instrumentation-java by census-instrumentation.
the class StatsRecorderImplTest method record_MapDeprecatedRpcConstants.
@Test
public void record_MapDeprecatedRpcConstants() {
View view = View.create(VIEW_NAME, "description", MEASURE_DOUBLE, Sum.create(), Arrays.asList(RecordUtils.RPC_METHOD));
viewManager.registerView(view);
MeasureMap statsRecord = statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 1.0);
statsRecord.record(new SimpleTagContext(Tag.create(RecordUtils.GRPC_CLIENT_METHOD, VALUE)));
ViewData viewData = viewManager.getView(VIEW_NAME);
// There should be two entries.
StatsTestUtil.assertAggregationMapEquals(viewData.getAggregationMap(), ImmutableMap.of(Arrays.asList(VALUE), StatsTestUtil.createAggregationData(Sum.create(), MEASURE_DOUBLE, 1.0)), 1e-6);
}
use of io.opencensus.stats.ViewData 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();
}
Aggregations