use of io.opencensus.stats.View in project instrumentation-java by census-instrumentation.
the class ViewManagerImplTest method settingStateToDisabledWillClearStats_Interval.
@Test
public void settingStateToDisabledWillClearStats_Interval() {
View intervalView = View.create(VIEW_NAME_2, VIEW_DESCRIPTION, MEASURE_DOUBLE, MEAN, Arrays.asList(KEY), Interval.create(Duration.create(60, 0)));
settingStateToDisabledWillClearStats(intervalView);
}
use of io.opencensus.stats.View in project instrumentation-java by census-instrumentation.
the class ViewManagerImplTest method testRecordInterval.
private final void testRecordInterval(Measure measure, Aggregation aggregation, double[] initialValues, /* There are 5 initial values recorded before we call getView(). */
double value6, double value7, AggregationData expectedValues1, AggregationData expectedValues2, AggregationData expectedValues3) {
// The interval is 10 seconds, i.e. values should expire after 10 seconds.
// Each bucket has a duration of 2.5 seconds.
View view = View.create(VIEW_NAME, VIEW_DESCRIPTION, measure, aggregation, Arrays.asList(KEY), Interval.create(TEN_SECONDS));
// start at 30s
long startTimeMillis = 30 * MILLIS_PER_SECOND;
clock.setTime(Timestamp.fromMillis(startTimeMillis));
viewManager.registerView(view);
TagContext tags = tagger.emptyBuilder().put(KEY, VALUE).build();
for (int i = 1; i <= 5; i++) {
/*
* Add each value in sequence, at 31s, 32s, 33s, etc.
* 1st and 2nd values should fall into the first bucket [30.0, 32.5),
* 3rd and 4th values should fall into the second bucket [32.5, 35.0),
* 5th value should fall into the third bucket [35.0, 37.5).
*/
clock.setTime(Timestamp.fromMillis(startTimeMillis + i * MILLIS_PER_SECOND));
putToMeasureMap(statsRecorder.newMeasureMap(), measure, initialValues[i - 1]).record(tags);
}
clock.setTime(Timestamp.fromMillis(startTimeMillis + 8 * MILLIS_PER_SECOND));
// 38s, no values should have expired
StatsTestUtil.assertAggregationMapEquals(viewManager.getView(VIEW_NAME).getAggregationMap(), ImmutableMap.of(Arrays.asList(VALUE), StatsTestUtil.createAggregationData(aggregation, measure, initialValues)), EPSILON);
clock.setTime(Timestamp.fromMillis(startTimeMillis + 11 * MILLIS_PER_SECOND));
// 41s, 40% of the values in the first bucket should have expired (1 / 2.5 = 0.4).
StatsTestUtil.assertAggregationMapEquals(viewManager.getView(VIEW_NAME).getAggregationMap(), ImmutableMap.of(Arrays.asList(VALUE), expectedValues1), EPSILON);
clock.setTime(Timestamp.fromMillis(startTimeMillis + 12 * MILLIS_PER_SECOND));
// 42s, add a new value value1, should fall into bucket [40.0, 42.5)
putToMeasureMap(statsRecorder.newMeasureMap(), measure, value6).record(tags);
clock.setTime(Timestamp.fromMillis(startTimeMillis + 17 * MILLIS_PER_SECOND));
// 47s, values in the first and second bucket should have expired, and 80% of values in the
// third bucket should have expired. The new value should persist.
StatsTestUtil.assertAggregationMapEquals(viewManager.getView(VIEW_NAME).getAggregationMap(), ImmutableMap.of(Arrays.asList(VALUE), expectedValues2), EPSILON);
clock.setTime(Timestamp.fromMillis(60 * MILLIS_PER_SECOND));
// 60s, all previous values should have expired, add another value value2
putToMeasureMap(statsRecorder.newMeasureMap(), measure, value7).record(tags);
StatsTestUtil.assertAggregationMapEquals(viewManager.getView(VIEW_NAME).getAggregationMap(), ImmutableMap.of(Arrays.asList(VALUE), expectedValues3), EPSILON);
clock.setTime(Timestamp.fromMillis(100 * MILLIS_PER_SECOND));
// 100s, all values should have expired
assertThat(viewManager.getView(VIEW_NAME).getAggregationMap()).isEmpty();
}
use of io.opencensus.stats.View in project instrumentation-java by census-instrumentation.
the class ViewManagerImplTest method registerRecordAndGetView_StatsDisabled.
@Test
@SuppressWarnings("deprecation")
public void registerRecordAndGetView_StatsDisabled() {
statsComponent.setState(StatsCollectionState.DISABLED);
View view = createCumulativeView(VIEW_NAME, MEASURE_DOUBLE, MEAN, Arrays.asList(KEY));
viewManager.registerView(view);
statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 1.1).record(tagger.emptyBuilder().put(KEY, VALUE).build());
assertThat(viewManager.getView(VIEW_NAME)).isEqualTo(createEmptyViewData(view));
}
use of io.opencensus.stats.View in project instrumentation-java by census-instrumentation.
the class ViewManagerImplTest method preventRegisteringDifferentViewWithSameName.
@Test
public void preventRegisteringDifferentViewWithSameName() {
View view1 = View.create(VIEW_NAME, "View description.", MEASURE_DOUBLE, DISTRIBUTION, Arrays.asList(KEY), CUMULATIVE);
View view2 = View.create(VIEW_NAME, "This is a different description.", MEASURE_DOUBLE, DISTRIBUTION, Arrays.asList(KEY), CUMULATIVE);
testFailedToRegisterView(view1, view2, "A different view with the same name is already registered");
}
Aggregations