use of io.opencensus.stats.ViewData in project instrumentation-java by census-instrumentation.
the class ViewManagerImplTest method getViewDoesNotClearStats.
@Test
public void getViewDoesNotClearStats() {
View view = createCumulativeView(VIEW_NAME, MEASURE_DOUBLE, DISTRIBUTION, Arrays.asList(KEY));
clock.setTime(Timestamp.create(10, 0));
viewManager.registerView(view);
TagContext tags = tagger.emptyBuilder().put(KEY, VALUE).build();
statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 0.1).record(tags);
clock.setTime(Timestamp.create(11, 0));
ViewData viewData1 = viewManager.getView(VIEW_NAME);
assertThat(viewData1.getWindowData()).isEqualTo(CumulativeData.create(Timestamp.create(10, 0), Timestamp.create(11, 0)));
StatsTestUtil.assertAggregationMapEquals(viewData1.getAggregationMap(), ImmutableMap.of(Arrays.asList(VALUE), StatsTestUtil.createAggregationData(DISTRIBUTION, MEASURE_DOUBLE, 0.1)), EPSILON);
statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 0.2).record(tags);
clock.setTime(Timestamp.create(12, 0));
ViewData viewData2 = viewManager.getView(VIEW_NAME);
// The second view should have the same start time as the first view, and it should include both
// recorded values:
assertThat(viewData2.getWindowData()).isEqualTo(CumulativeData.create(Timestamp.create(10, 0), Timestamp.create(12, 0)));
StatsTestUtil.assertAggregationMapEquals(viewData2.getAggregationMap(), ImmutableMap.of(Arrays.asList(VALUE), StatsTestUtil.createAggregationData(DISTRIBUTION, MEASURE_DOUBLE, 0.1, 0.2)), EPSILON);
}
use of io.opencensus.stats.ViewData in project instrumentation-java by census-instrumentation.
the class ViewManagerImplTest method testViewDataWithMultipleTagKeys.
@Test
public void testViewDataWithMultipleTagKeys() {
TagKey key1 = TagKey.create("Key-1");
TagKey key2 = TagKey.create("Key-2");
viewManager.registerView(createCumulativeView(VIEW_NAME, MEASURE_DOUBLE, DISTRIBUTION, Arrays.asList(key1, key2)));
statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 1.1).record(tagger.emptyBuilder().put(key1, TagValue.create("v1")).put(key2, TagValue.create("v10")).build());
statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 2.2).record(tagger.emptyBuilder().put(key1, TagValue.create("v1")).put(key2, TagValue.create("v20")).build());
statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 3.3).record(tagger.emptyBuilder().put(key1, TagValue.create("v2")).put(key2, TagValue.create("v10")).build());
statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 4.4).record(tagger.emptyBuilder().put(key1, TagValue.create("v1")).put(key2, TagValue.create("v10")).build());
ViewData viewData = viewManager.getView(VIEW_NAME);
assertAggregationMapEquals(viewData.getAggregationMap(), ImmutableMap.of(Arrays.asList(TagValue.create("v1"), TagValue.create("v10")), StatsTestUtil.createAggregationData(DISTRIBUTION, MEASURE_DOUBLE, 1.1, 4.4), Arrays.asList(TagValue.create("v1"), TagValue.create("v20")), StatsTestUtil.createAggregationData(DISTRIBUTION, MEASURE_DOUBLE, 2.2), Arrays.asList(TagValue.create("v2"), TagValue.create("v10")), StatsTestUtil.createAggregationData(DISTRIBUTION, MEASURE_DOUBLE, 3.3)), EPSILON);
}
use of io.opencensus.stats.ViewData in project instrumentation-java by census-instrumentation.
the class ViewManagerImplTest method testRecord_MeasureNotMatch.
private void testRecord_MeasureNotMatch(Measure measure1, Measure measure2, double value) {
viewManager.registerView(createCumulativeView(VIEW_NAME, measure1, MEAN, Arrays.asList(KEY)));
TagContext tags = tagger.emptyBuilder().put(KEY, VALUE).build();
putToMeasureMap(statsRecorder.newMeasureMap(), measure2, value).record(tags);
ViewData view = viewManager.getView(VIEW_NAME);
assertThat(view.getAggregationMap()).isEmpty();
}
use of io.opencensus.stats.ViewData in project instrumentation-java by census-instrumentation.
the class ViewManagerImplTest method testGetCumulativeViewDataWithoutBucketBoundaries.
@Test
public void testGetCumulativeViewDataWithoutBucketBoundaries() {
View view = createCumulativeView(VIEW_NAME, MEASURE_DOUBLE, MEAN, Arrays.asList(KEY));
clock.setTime(Timestamp.create(1, 0));
viewManager.registerView(view);
statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 1.1).record(tagger.emptyBuilder().put(KEY, VALUE).build());
clock.setTime(Timestamp.create(3, 0));
ViewData viewData = viewManager.getView(VIEW_NAME);
assertThat(viewData.getWindowData()).isEqualTo(CumulativeData.create(Timestamp.create(1, 0), Timestamp.create(3, 0)));
StatsTestUtil.assertAggregationMapEquals(viewData.getAggregationMap(), ImmutableMap.of(Arrays.asList(VALUE), StatsTestUtil.createAggregationData(MEAN, MEASURE_DOUBLE, 1.1)), EPSILON);
}
use of io.opencensus.stats.ViewData in project instrumentation-java by census-instrumentation.
the class ViewManagerImplTest method testMultipleViews_DifferentMeasures.
private void testMultipleViews_DifferentMeasures(Measure measure1, Measure measure2, double value1, double value2) {
final View view1 = createCumulativeView(VIEW_NAME, measure1, DISTRIBUTION, Arrays.asList(KEY));
final View view2 = createCumulativeView(VIEW_NAME_2, measure2, DISTRIBUTION, Arrays.asList(KEY));
clock.setTime(Timestamp.create(1, 0));
viewManager.registerView(view1);
clock.setTime(Timestamp.create(2, 0));
viewManager.registerView(view2);
TagContext tags = tagger.emptyBuilder().put(KEY, VALUE).build();
MeasureMap measureMap = statsRecorder.newMeasureMap();
putToMeasureMap(measureMap, measure1, value1);
putToMeasureMap(measureMap, measure2, value2);
measureMap.record(tags);
clock.setTime(Timestamp.create(3, 0));
ViewData viewData1 = viewManager.getView(VIEW_NAME);
clock.setTime(Timestamp.create(4, 0));
ViewData viewData2 = viewManager.getView(VIEW_NAME_2);
assertThat(viewData1.getWindowData()).isEqualTo(CumulativeData.create(Timestamp.create(1, 0), Timestamp.create(3, 0)));
StatsTestUtil.assertAggregationMapEquals(viewData1.getAggregationMap(), ImmutableMap.of(Arrays.asList(VALUE), StatsTestUtil.createAggregationData(DISTRIBUTION, measure1, value1)), EPSILON);
assertThat(viewData2.getWindowData()).isEqualTo(CumulativeData.create(Timestamp.create(2, 0), Timestamp.create(4, 0)));
StatsTestUtil.assertAggregationMapEquals(viewData2.getAggregationMap(), ImmutableMap.of(Arrays.asList(VALUE), StatsTestUtil.createAggregationData(DISTRIBUTION, measure2, value2)), EPSILON);
}
Aggregations