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);
}
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));
}
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);
}
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);
}
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();
}
Aggregations