Search in sources :

Example 11 with View

use of io.opencensus.stats.View 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 12 with View

use of io.opencensus.stats.View 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 13 with View

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

the class StatsRecorderImplTest method record_StatsReenabled.

@Test
@SuppressWarnings("deprecation")
public void record_StatsReenabled() {
    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));
    statsComponent.setState(StatsCollectionState.ENABLED);
    assertThat(viewManager.getView(VIEW_NAME).getAggregationMap()).isEmpty();
    assertThat(viewManager.getView(VIEW_NAME).getWindowData()).isNotEqualTo(CumulativeData.create(ZERO_TIMESTAMP, ZERO_TIMESTAMP));
    statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 4.0).record(new SimpleTagContext(Tag.create(KEY, VALUE)));
    StatsTestUtil.assertAggregationMapEquals(viewManager.getView(VIEW_NAME).getAggregationMap(), ImmutableMap.of(Arrays.asList(VALUE), StatsTestUtil.createAggregationData(Sum.create(), MEASURE_DOUBLE, 4.0)), 1e-6);
}
Also used : SimpleTagContext(io.opencensus.implcore.stats.StatsTestUtil.SimpleTagContext) View(io.opencensus.stats.View) Test(org.junit.Test)

Example 14 with View

use of io.opencensus.stats.View 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)

Example 15 with View

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

the class ViewManagerImplTest method testRecordIntervalMultipleTagValues.

@Test
public void testRecordIntervalMultipleTagValues() {
    // The interval is 10 seconds, i.e. values should expire after 10 seconds.
    View view = View.create(VIEW_NAME, VIEW_DESCRIPTION, MEASURE_DOUBLE, DISTRIBUTION, Arrays.asList(KEY), Interval.create(TEN_SECONDS));
    // Start at 10s
    clock.setTime(Timestamp.create(10, 0));
    viewManager.registerView(view);
    // record for TagValue1 at 11s
    clock.setTime(Timestamp.fromMillis(11 * MILLIS_PER_SECOND));
    statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 10.0).record(tagger.emptyBuilder().put(KEY, VALUE).build());
    // record for TagValue2 at 15s
    clock.setTime(Timestamp.fromMillis(15 * MILLIS_PER_SECOND));
    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());
    // get ViewData at 19s, no stats should have expired.
    clock.setTime(Timestamp.fromMillis(19 * MILLIS_PER_SECOND));
    ViewData viewData1 = viewManager.getView(VIEW_NAME);
    StatsTestUtil.assertAggregationMapEquals(viewData1.getAggregationMap(), ImmutableMap.of(Arrays.asList(VALUE), StatsTestUtil.createAggregationData(DISTRIBUTION, MEASURE_DOUBLE, 10.0), Arrays.asList(VALUE_2), StatsTestUtil.createAggregationData(DISTRIBUTION, MEASURE_DOUBLE, 30.0, 50.0)), EPSILON);
    // record for TagValue2 again at 20s
    clock.setTime(Timestamp.fromMillis(20 * MILLIS_PER_SECOND));
    statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 40.0).record(tagger.emptyBuilder().put(KEY, VALUE_2).build());
    // get ViewData at 25s, stats for TagValue1 should have expired.
    clock.setTime(Timestamp.fromMillis(25 * MILLIS_PER_SECOND));
    ViewData viewData2 = viewManager.getView(VIEW_NAME);
    StatsTestUtil.assertAggregationMapEquals(viewData2.getAggregationMap(), ImmutableMap.of(Arrays.asList(VALUE_2), StatsTestUtil.createAggregationData(DISTRIBUTION, MEASURE_DOUBLE, 30.0, 50.0, 40.0)), EPSILON);
    // get ViewData at 30s, the first two values for TagValue2 should have expired.
    clock.setTime(Timestamp.fromMillis(30 * MILLIS_PER_SECOND));
    ViewData viewData3 = viewManager.getView(VIEW_NAME);
    StatsTestUtil.assertAggregationMapEquals(viewData3.getAggregationMap(), ImmutableMap.of(Arrays.asList(VALUE_2), StatsTestUtil.createAggregationData(DISTRIBUTION, MEASURE_DOUBLE, 40.0)), EPSILON);
    // get ViewData at 40s, all stats should have expired.
    clock.setTime(Timestamp.fromMillis(40 * MILLIS_PER_SECOND));
    ViewData viewData4 = viewManager.getView(VIEW_NAME);
    assertThat(viewData4.getAggregationMap()).isEmpty();
}
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

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