Search in sources :

Example 31 with View

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);
}
Also used : View(io.opencensus.stats.View)

Example 32 with View

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));
}
Also used : SimpleTagContext(io.opencensus.implcore.stats.StatsTestUtil.SimpleTagContext) View(io.opencensus.stats.View) Test(org.junit.Test)

Example 33 with 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));
}
Also used : SimpleTagContext(io.opencensus.implcore.stats.StatsTestUtil.SimpleTagContext) Context(io.grpc.Context) TagContext(io.opencensus.tags.TagContext) SimpleTagContext(io.opencensus.implcore.stats.StatsTestUtil.SimpleTagContext) TagContext(io.opencensus.tags.TagContext) SimpleTagContext(io.opencensus.implcore.stats.StatsTestUtil.SimpleTagContext) StatsTestUtil.createEmptyViewData(io.opencensus.implcore.stats.StatsTestUtil.createEmptyViewData) ViewData(io.opencensus.stats.ViewData) View(io.opencensus.stats.View) Test(org.junit.Test)

Example 34 with View

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);
}
Also used : TagContext(io.opencensus.tags.TagContext) StatsTestUtil.createEmptyViewData(io.opencensus.implcore.stats.StatsTestUtil.createEmptyViewData) ViewData(io.opencensus.stats.ViewData) View(io.opencensus.stats.View) Test(org.junit.Test)

Example 35 with View

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);
}
Also used : View(io.opencensus.stats.View) Test(org.junit.Test)

Aggregations

View (io.opencensus.stats.View)45 Test (org.junit.Test)31 ViewData (io.opencensus.stats.ViewData)18 StatsTestUtil.createEmptyViewData (io.opencensus.implcore.stats.StatsTestUtil.createEmptyViewData)15 SimpleTagContext (io.opencensus.implcore.stats.StatsTestUtil.SimpleTagContext)6 Aggregation (io.opencensus.stats.Aggregation)5 TagContext (io.opencensus.tags.TagContext)5 Timestamp (io.opencensus.common.Timestamp)3 AggregationData (io.opencensus.stats.AggregationData)3 Measure (io.opencensus.stats.Measure)3 MeasureMap (io.opencensus.stats.MeasureMap)3 TagKey (io.opencensus.tags.TagKey)3 TagValue (io.opencensus.tags.TagValue)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 CurrentState (io.opencensus.implcore.internal.CurrentState)2 DistributionData (io.opencensus.stats.AggregationData.DistributionData)2 MeasureDouble (io.opencensus.stats.Measure.MeasureDouble)2 ViewManager (io.opencensus.stats.ViewManager)2 ImmutableList (com.google.common.collect.ImmutableList)1