use of io.opencensus.stats.ViewData in project instrumentation-java by census-instrumentation.
the class ViewManagerImplTest method testRecordWithTagsThatDoNotMatchViewData.
@Test
public void testRecordWithTagsThatDoNotMatchViewData() {
viewManager.registerView(createCumulativeView(VIEW_NAME, MEASURE_DOUBLE, DISTRIBUTION, Arrays.asList(KEY)));
statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 10.0).record(tagger.emptyBuilder().put(TagKey.create("wrong key"), VALUE).build());
statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 50.0).record(tagger.emptyBuilder().put(TagKey.create("another wrong key"), VALUE).build());
ViewData viewData = viewManager.getView(VIEW_NAME);
assertAggregationMapEquals(viewData.getAggregationMap(), ImmutableMap.of(// tag value : "unknown/not set".
Arrays.asList(RecordUtils.UNKNOWN_TAG_VALUE), // Should record stats with default tag value: "KEY" : "unknown/not set".
createAggregationData(DISTRIBUTION, MEASURE_DOUBLE, 10.0, 50.0)), EPSILON);
}
use of io.opencensus.stats.ViewData in project instrumentation-java by census-instrumentation.
the class ViewManagerImplTest method settingStateToDisabledWillClearStats.
@SuppressWarnings("deprecation")
private void settingStateToDisabledWillClearStats(View view) {
Timestamp timestamp1 = Timestamp.create(1, 0);
clock.setTime(timestamp1);
viewManager.registerView(view);
statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 1.1).record(tagger.emptyBuilder().put(KEY, VALUE).build());
StatsTestUtil.assertAggregationMapEquals(viewManager.getView(view.getName()).getAggregationMap(), ImmutableMap.of(Arrays.asList(VALUE), StatsTestUtil.createAggregationData(view.getAggregation(), view.getMeasure(), 1.1)), EPSILON);
Timestamp timestamp2 = Timestamp.create(2, 0);
clock.setTime(timestamp2);
// This will clear stats.
statsComponent.setState(StatsCollectionState.DISABLED);
assertThat(viewManager.getView(view.getName())).isEqualTo(createEmptyViewData(view));
Timestamp timestamp3 = Timestamp.create(3, 0);
clock.setTime(timestamp3);
statsComponent.setState(StatsCollectionState.ENABLED);
Timestamp timestamp4 = Timestamp.create(4, 0);
clock.setTime(timestamp4);
// This ViewData does not have any stats, but it should not be an empty ViewData, since it has
// non-zero TimeStamps.
ViewData viewData = viewManager.getView(view.getName());
assertThat(viewData.getAggregationMap()).isEmpty();
AggregationWindowData windowData = viewData.getWindowData();
if (windowData instanceof CumulativeData) {
assertThat(windowData).isEqualTo(CumulativeData.create(timestamp3, timestamp4));
} else {
assertThat(windowData).isEqualTo(IntervalData.create(timestamp4));
}
}
Aggregations