Search in sources :

Example 21 with ViewData

use of io.opencensus.stats.ViewData 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 22 with ViewData

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

the class ViewManagerImplTest method testViewDataWithMultipleTagKeys.

@Test
public void testViewDataWithMultipleTagKeys() {
    TagKey key1 = TagKey.create("Key-1");
    TagKey key2 = TagKey.create("Key-2");
    viewManager.registerView(createCumulativeView(VIEW_NAME, MEASURE_DOUBLE, DISTRIBUTION, Arrays.asList(key1, key2)));
    statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 1.1).record(tagger.emptyBuilder().put(key1, TagValue.create("v1")).put(key2, TagValue.create("v10")).build());
    statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 2.2).record(tagger.emptyBuilder().put(key1, TagValue.create("v1")).put(key2, TagValue.create("v20")).build());
    statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 3.3).record(tagger.emptyBuilder().put(key1, TagValue.create("v2")).put(key2, TagValue.create("v10")).build());
    statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 4.4).record(tagger.emptyBuilder().put(key1, TagValue.create("v1")).put(key2, TagValue.create("v10")).build());
    ViewData viewData = viewManager.getView(VIEW_NAME);
    assertAggregationMapEquals(viewData.getAggregationMap(), ImmutableMap.of(Arrays.asList(TagValue.create("v1"), TagValue.create("v10")), StatsTestUtil.createAggregationData(DISTRIBUTION, MEASURE_DOUBLE, 1.1, 4.4), Arrays.asList(TagValue.create("v1"), TagValue.create("v20")), StatsTestUtil.createAggregationData(DISTRIBUTION, MEASURE_DOUBLE, 2.2), Arrays.asList(TagValue.create("v2"), TagValue.create("v10")), StatsTestUtil.createAggregationData(DISTRIBUTION, MEASURE_DOUBLE, 3.3)), EPSILON);
}
Also used : StatsTestUtil.createEmptyViewData(io.opencensus.implcore.stats.StatsTestUtil.createEmptyViewData) ViewData(io.opencensus.stats.ViewData) TagKey(io.opencensus.tags.TagKey) Test(org.junit.Test)

Example 23 with ViewData

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

the class ViewManagerImplTest method testRecord_MeasureNotMatch.

private void testRecord_MeasureNotMatch(Measure measure1, Measure measure2, double value) {
    viewManager.registerView(createCumulativeView(VIEW_NAME, measure1, MEAN, Arrays.asList(KEY)));
    TagContext tags = tagger.emptyBuilder().put(KEY, VALUE).build();
    putToMeasureMap(statsRecorder.newMeasureMap(), measure2, value).record(tags);
    ViewData view = viewManager.getView(VIEW_NAME);
    assertThat(view.getAggregationMap()).isEmpty();
}
Also used : TagContext(io.opencensus.tags.TagContext) StatsTestUtil.createEmptyViewData(io.opencensus.implcore.stats.StatsTestUtil.createEmptyViewData) ViewData(io.opencensus.stats.ViewData)

Example 24 with ViewData

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

the class ViewManagerImplTest method testGetCumulativeViewDataWithoutBucketBoundaries.

@Test
public void testGetCumulativeViewDataWithoutBucketBoundaries() {
    View view = createCumulativeView(VIEW_NAME, MEASURE_DOUBLE, MEAN, Arrays.asList(KEY));
    clock.setTime(Timestamp.create(1, 0));
    viewManager.registerView(view);
    statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 1.1).record(tagger.emptyBuilder().put(KEY, VALUE).build());
    clock.setTime(Timestamp.create(3, 0));
    ViewData viewData = viewManager.getView(VIEW_NAME);
    assertThat(viewData.getWindowData()).isEqualTo(CumulativeData.create(Timestamp.create(1, 0), Timestamp.create(3, 0)));
    StatsTestUtil.assertAggregationMapEquals(viewData.getAggregationMap(), ImmutableMap.of(Arrays.asList(VALUE), StatsTestUtil.createAggregationData(MEAN, MEASURE_DOUBLE, 1.1)), 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)

Example 25 with ViewData

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

the class ViewManagerImplTest method testMultipleViews_DifferentMeasures.

private void testMultipleViews_DifferentMeasures(Measure measure1, Measure measure2, double value1, double value2) {
    final View view1 = createCumulativeView(VIEW_NAME, measure1, DISTRIBUTION, Arrays.asList(KEY));
    final View view2 = createCumulativeView(VIEW_NAME_2, measure2, DISTRIBUTION, Arrays.asList(KEY));
    clock.setTime(Timestamp.create(1, 0));
    viewManager.registerView(view1);
    clock.setTime(Timestamp.create(2, 0));
    viewManager.registerView(view2);
    TagContext tags = tagger.emptyBuilder().put(KEY, VALUE).build();
    MeasureMap measureMap = statsRecorder.newMeasureMap();
    putToMeasureMap(measureMap, measure1, value1);
    putToMeasureMap(measureMap, measure2, value2);
    measureMap.record(tags);
    clock.setTime(Timestamp.create(3, 0));
    ViewData viewData1 = viewManager.getView(VIEW_NAME);
    clock.setTime(Timestamp.create(4, 0));
    ViewData viewData2 = viewManager.getView(VIEW_NAME_2);
    assertThat(viewData1.getWindowData()).isEqualTo(CumulativeData.create(Timestamp.create(1, 0), Timestamp.create(3, 0)));
    StatsTestUtil.assertAggregationMapEquals(viewData1.getAggregationMap(), ImmutableMap.of(Arrays.asList(VALUE), StatsTestUtil.createAggregationData(DISTRIBUTION, measure1, value1)), EPSILON);
    assertThat(viewData2.getWindowData()).isEqualTo(CumulativeData.create(Timestamp.create(2, 0), Timestamp.create(4, 0)));
    StatsTestUtil.assertAggregationMapEquals(viewData2.getAggregationMap(), ImmutableMap.of(Arrays.asList(VALUE), StatsTestUtil.createAggregationData(DISTRIBUTION, measure2, value2)), 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) MeasureMap(io.opencensus.stats.MeasureMap)

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