Search in sources :

Example 6 with ViewData

use of io.opencensus.stats.ViewData in project instrumentation-java by census-instrumentation.

the class StatsRecorderImplTest method recordTwice.

@Test
public void recordTwice() {
    View view = View.create(VIEW_NAME, "description", MEASURE_DOUBLE, Sum.create(), Arrays.asList(KEY), Cumulative.create());
    viewManager.registerView(view);
    MeasureMap statsRecord = statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 1.0);
    statsRecord.record(new SimpleTagContext(Tag.create(KEY, VALUE)));
    statsRecord.record(new SimpleTagContext(Tag.create(KEY, VALUE_2)));
    ViewData viewData = viewManager.getView(VIEW_NAME);
    // There should be two entries.
    StatsTestUtil.assertAggregationMapEquals(viewData.getAggregationMap(), ImmutableMap.of(Arrays.asList(VALUE), StatsTestUtil.createAggregationData(Sum.create(), MEASURE_DOUBLE, 1.0), Arrays.asList(VALUE_2), StatsTestUtil.createAggregationData(Sum.create(), MEASURE_DOUBLE, 1.0)), 1e-6);
}
Also used : 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) MeasureMap(io.opencensus.stats.MeasureMap) Test(org.junit.Test)

Example 7 with ViewData

use of io.opencensus.stats.ViewData in project instrumentation-java by census-instrumentation.

the class StatsRecorderImplTest method record_CurrentContextNotSet.

@Test
public void record_CurrentContextNotSet() {
    View view = View.create(VIEW_NAME, "description", MEASURE_DOUBLE, Sum.create(), Arrays.asList(KEY), Cumulative.create());
    viewManager.registerView(view);
    statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 1.0).record();
    ViewData viewData = viewManager.getView(VIEW_NAME);
    // record() should have used the default TagContext, so the tag value should be null.
    assertThat(viewData.getAggregationMap().keySet()).containsExactly(Arrays.asList((TagValue) null));
}
Also used : StatsTestUtil.createEmptyViewData(io.opencensus.implcore.stats.StatsTestUtil.createEmptyViewData) ViewData(io.opencensus.stats.ViewData) TagValue(io.opencensus.tags.TagValue) View(io.opencensus.stats.View) Test(org.junit.Test)

Example 8 with ViewData

use of io.opencensus.stats.ViewData in project instrumentation-java by census-instrumentation.

the class ViewManagerImplTest method testRecordCumulativeMultipleTagValues.

@Test
public void testRecordCumulativeMultipleTagValues() {
    viewManager.registerView(createCumulativeView(VIEW_NAME, MEASURE_DOUBLE, DISTRIBUTION, Arrays.asList(KEY)));
    statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 10.0).record(tagger.emptyBuilder().put(KEY, VALUE).build());
    statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 30.0).record(tagger.emptyBuilder().put(KEY, VALUE_2).build());
    statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 50.0).record(tagger.emptyBuilder().put(KEY, VALUE_2).build());
    ViewData viewData = viewManager.getView(VIEW_NAME);
    assertAggregationMapEquals(viewData.getAggregationMap(), ImmutableMap.of(Arrays.asList(VALUE), createAggregationData(DISTRIBUTION, MEASURE_DOUBLE, 10.0), Arrays.asList(VALUE_2), createAggregationData(DISTRIBUTION, MEASURE_DOUBLE, 30.0, 50.0)), EPSILON);
}
Also used : StatsTestUtil.createEmptyViewData(io.opencensus.implcore.stats.StatsTestUtil.createEmptyViewData) ViewData(io.opencensus.stats.ViewData) Test(org.junit.Test)

Example 9 with ViewData

use of io.opencensus.stats.ViewData in project instrumentation-java by census-instrumentation.

the class MeasureToViewMapTest method testRegisterAndGetView.

@Test
public void testRegisterAndGetView() {
    MeasureToViewMap measureToViewMap = new MeasureToViewMap();
    TestClock clock = TestClock.create(Timestamp.create(10, 20));
    measureToViewMap.registerView(VIEW, clock);
    clock.setTime(Timestamp.create(30, 40));
    ViewData viewData = measureToViewMap.getView(VIEW_NAME, clock, State.ENABLED);
    assertThat(viewData.getView()).isEqualTo(VIEW);
    assertThat(viewData.getWindowData()).isEqualTo(CumulativeData.create(Timestamp.create(10, 20), Timestamp.create(30, 40)));
    assertThat(viewData.getAggregationMap()).isEmpty();
}
Also used : TestClock(io.opencensus.testing.common.TestClock) ViewData(io.opencensus.stats.ViewData) Test(org.junit.Test)

Example 10 with ViewData

use of io.opencensus.stats.ViewData in project instrumentation-java by census-instrumentation.

the class ViewManagerImplTest method testMultipleViewSameMeasure.

@Test
public void testMultipleViewSameMeasure() {
    final View view1 = createCumulativeView(VIEW_NAME, MEASURE_DOUBLE, DISTRIBUTION, Arrays.asList(KEY));
    final View view2 = createCumulativeView(VIEW_NAME_2, MEASURE_DOUBLE, DISTRIBUTION, Arrays.asList(KEY));
    clock.setTime(Timestamp.create(1, 1));
    viewManager.registerView(view1);
    clock.setTime(Timestamp.create(2, 2));
    viewManager.registerView(view2);
    statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 5.0).record(tagger.emptyBuilder().put(KEY, VALUE).build());
    clock.setTime(Timestamp.create(3, 3));
    ViewData viewData1 = viewManager.getView(VIEW_NAME);
    clock.setTime(Timestamp.create(4, 4));
    ViewData viewData2 = viewManager.getView(VIEW_NAME_2);
    assertThat(viewData1.getWindowData()).isEqualTo(CumulativeData.create(Timestamp.create(1, 1), Timestamp.create(3, 3)));
    StatsTestUtil.assertAggregationMapEquals(viewData1.getAggregationMap(), ImmutableMap.of(Arrays.asList(VALUE), StatsTestUtil.createAggregationData(DISTRIBUTION, MEASURE_DOUBLE, 5.0)), EPSILON);
    assertThat(viewData2.getWindowData()).isEqualTo(CumulativeData.create(Timestamp.create(2, 2), Timestamp.create(4, 4)));
    StatsTestUtil.assertAggregationMapEquals(viewData2.getAggregationMap(), ImmutableMap.of(Arrays.asList(VALUE), StatsTestUtil.createAggregationData(DISTRIBUTION, MEASURE_DOUBLE, 5.0)), EPSILON);
}
Also used : StatsTestUtil.createEmptyViewData(io.opencensus.implcore.stats.StatsTestUtil.createEmptyViewData) ViewData(io.opencensus.stats.ViewData) View(io.opencensus.stats.View) Test(org.junit.Test)

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