use of io.opencensus.stats.View in project instrumentation-java by census-instrumentation.
the class MeasureToViewMap method getMutableViewData.
@javax.annotation.Nullable
private synchronized MutableViewData getMutableViewData(View.Name viewName) {
View view = registeredViews.get(viewName);
if (view == null) {
return null;
}
Collection<MutableViewData> views = mutableMap.get(view.getMeasure().getName());
for (MutableViewData viewData : views) {
if (viewData.getView().getName().equals(viewName)) {
return viewData;
}
}
throw new AssertionError("Internal error: Not recording stats for view: \"" + viewName + "\" registeredViews=" + registeredViews + ", mutableMap=" + mutableMap);
}
use of io.opencensus.stats.View in project instrumentation-java by census-instrumentation.
the class StatsRecorderImplTest method record_StatsDisabled.
@Test
@SuppressWarnings("deprecation")
public void record_StatsDisabled() {
View view = View.create(VIEW_NAME, "description", MEASURE_DOUBLE, Sum.create(), Arrays.asList(KEY), Cumulative.create());
viewManager.registerView(view);
statsComponent.setState(StatsCollectionState.DISABLED);
statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 1.0).record(new SimpleTagContext(Tag.create(KEY, VALUE)));
assertThat(viewManager.getView(VIEW_NAME)).isEqualTo(createEmptyViewData(view));
}
use of io.opencensus.stats.View in project instrumentation-java by census-instrumentation.
the class StatsRecorderImplTest method record_CurrentContextSet.
@Test
public void record_CurrentContextSet() {
View view = View.create(VIEW_NAME, "description", MEASURE_DOUBLE, Sum.create(), Arrays.asList(KEY), Cumulative.create());
viewManager.registerView(view);
TagContext tags = new SimpleTagContext(Tag.create(KEY, VALUE));
Context orig = ContextUtils.withValue(Context.current(), tags).attach();
try {
statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 1.0).record();
} finally {
Context.current().detach(orig);
}
ViewData viewData = viewManager.getView(VIEW_NAME);
// record() should have used the given TagContext.
assertThat(viewData.getAggregationMap().keySet()).containsExactly(Arrays.asList(VALUE));
}
use of io.opencensus.stats.View 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.View in project instrumentation-java by census-instrumentation.
the class ViewManagerImplTest method testGetAllExportedViews.
@Test
public void testGetAllExportedViews() {
assertThat(viewManager.getAllExportedViews()).isEmpty();
View cumulativeView1 = createCumulativeView(View.Name.create("View 1"), MEASURE_DOUBLE, DISTRIBUTION, Arrays.asList(KEY));
View cumulativeView2 = createCumulativeView(View.Name.create("View 2"), MEASURE_DOUBLE, DISTRIBUTION, Arrays.asList(KEY));
View intervalView = View.create(View.Name.create("View 3"), VIEW_DESCRIPTION, MEASURE_DOUBLE, DISTRIBUTION, Arrays.asList(KEY), INTERVAL);
viewManager.registerView(cumulativeView1);
viewManager.registerView(cumulativeView2);
viewManager.registerView(intervalView);
// Only cumulative views should be exported.
assertThat(viewManager.getAllExportedViews()).containsExactly(cumulativeView1, cumulativeView2);
}
Aggregations