Search in sources :

Example 26 with ViewData

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

Example 27 with ViewData

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));
    }
}
Also used : StatsTestUtil.createEmptyViewData(io.opencensus.implcore.stats.StatsTestUtil.createEmptyViewData) ViewData(io.opencensus.stats.ViewData) AggregationWindowData(io.opencensus.stats.ViewData.AggregationWindowData) Timestamp(io.opencensus.common.Timestamp) CumulativeData(io.opencensus.stats.ViewData.AggregationWindowData.CumulativeData)

Aggregations

ViewData (io.opencensus.stats.ViewData)27 StatsTestUtil.createEmptyViewData (io.opencensus.implcore.stats.StatsTestUtil.createEmptyViewData)21 Test (org.junit.Test)20 View (io.opencensus.stats.View)18 TagContext (io.opencensus.tags.TagContext)5 SimpleTagContext (io.opencensus.implcore.stats.StatsTestUtil.SimpleTagContext)4 Timestamp (io.opencensus.common.Timestamp)3 MeasureMap (io.opencensus.stats.MeasureMap)3 CurrentState (io.opencensus.implcore.internal.CurrentState)2 Aggregation (io.opencensus.stats.Aggregation)2 DistributionData (io.opencensus.stats.AggregationData.DistributionData)2 TagValue (io.opencensus.tags.TagValue)2 ImmutableList (com.google.common.collect.ImmutableList)1 Context (io.grpc.Context)1 Scope (io.opencensus.common.Scope)1 Exemplar (io.opencensus.metrics.data.Exemplar)1 AggregationData (io.opencensus.stats.AggregationData)1 CountData (io.opencensus.stats.AggregationData.CountData)1 LastValueDataDouble (io.opencensus.stats.AggregationData.LastValueDataDouble)1 SumDataDouble (io.opencensus.stats.AggregationData.SumDataDouble)1