use of io.opencensus.stats.ViewData 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();
}
use of io.opencensus.stats.ViewData in project instrumentation-java by census-instrumentation.
the class ViewManagerImplTest method testGetCumulativeViewDataWithEmptyBucketBoundaries.
@Test
public void testGetCumulativeViewDataWithEmptyBucketBoundaries() {
Aggregation noHistogram = Distribution.create(BucketBoundaries.create(Collections.<Double>emptyList()));
View view = createCumulativeView(VIEW_NAME, MEASURE_DOUBLE, noHistogram, 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(noHistogram, MEASURE_DOUBLE, 1.1)), EPSILON);
}
use of io.opencensus.stats.ViewData in project instrumentation-java by census-instrumentation.
the class ViewManagerImplTest method testRecordCumulative.
private void testRecordCumulative(Measure measure, Aggregation aggregation, double... values) {
View view = createCumulativeView(VIEW_NAME, measure, aggregation, Arrays.asList(KEY));
clock.setTime(Timestamp.create(1, 2));
viewManager.registerView(view);
TagContext tags = tagger.emptyBuilder().put(KEY, VALUE).build();
for (double val : values) {
putToMeasureMap(statsRecorder.newMeasureMap(), measure, val).record(tags);
}
clock.setTime(Timestamp.create(3, 4));
ViewData viewData = viewManager.getView(VIEW_NAME);
assertThat(viewData.getView()).isEqualTo(view);
assertThat(viewData.getWindowData()).isEqualTo(CumulativeData.create(Timestamp.create(1, 2), Timestamp.create(3, 4)));
StatsTestUtil.assertAggregationMapEquals(viewData.getAggregationMap(), ImmutableMap.of(Arrays.asList(VALUE), StatsTestUtil.createAggregationData(aggregation, measure, values)), EPSILON);
}
use of io.opencensus.stats.ViewData in project instrumentation-java by census-instrumentation.
the class MutableViewDataTest method testTimeRewindsOnCountViewNoThrow.
@Test
public void testTimeRewindsOnCountViewNoThrow() {
// First we set up some buckets THEN we rewind time for giggles.
View tester = View.create(View.Name.create("view"), "Description", MeasureDouble.create("name", "desc", "us"), Count.create(), Collections.singletonList(TagKey.create("KEY")));
Timestamp start = Timestamp.create(10000000, 0);
Timestamp validPointTime = Timestamp.create(10000010, 0);
CurrentState.State state = CurrentState.State.ENABLED;
MutableViewData viewData = MutableViewData.create(tester, start);
// Create a data points to get thrown away.
viewData.record(TagMapImpl.EMPTY, 1.0, validPointTime, Collections.<String, AttachmentValue>emptyMap());
// Rewind time and look for explosions.
Timestamp thePast = Timestamp.create(0, 0);
ViewData result = viewData.toViewData(thePast, state);
assertThat(result.getAggregationMap()).isEmpty();
}
use of io.opencensus.stats.ViewData in project instrumentation-java by census-instrumentation.
the class MutableViewDataTest method testTimeRewindsOnDistributionViewNoThrow.
@Test
public void testTimeRewindsOnDistributionViewNoThrow() {
// First we set up some buckets THEN we rewind time for giggles.
Aggregation latencyDistribution = Distribution.create(BucketBoundaries.create(Arrays.asList(0.0, 25.0, 100.0, 200.0, 400.0, 800.0, 10000.0)));
View tester = View.create(View.Name.create("view"), "Description", MeasureDouble.create("name", "desc", "us"), latencyDistribution, Collections.singletonList(TagKey.create("KEY")));
Timestamp start = Timestamp.create(10000000, 0);
Timestamp validPointTime = Timestamp.create(10000010, 0);
CurrentState.State state = CurrentState.State.ENABLED;
MutableViewData viewData = MutableViewData.create(tester, start);
// Create a data points to get thrown away.
viewData.record(TagMapImpl.EMPTY, 1.0, validPointTime, Collections.<String, AttachmentValue>emptyMap());
// Rewind time and look for explosions.
Timestamp thePast = Timestamp.create(0, 0);
ViewData result = viewData.toViewData(thePast, state);
assertThat(result.getAggregationMap()).isEmpty();
}
Aggregations