use of io.opencensus.stats.View 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.View in project instrumentation-java by census-instrumentation.
the class ViewManagerImplTest method getAllExportedViewsResultIsUnmodifiable.
@Test
public void getAllExportedViewsResultIsUnmodifiable() {
View view1 = View.create(View.Name.create("View 1"), VIEW_DESCRIPTION, MEASURE_DOUBLE, DISTRIBUTION, Arrays.asList(KEY), CUMULATIVE);
viewManager.registerView(view1);
Set<View> exported = viewManager.getAllExportedViews();
View view2 = View.create(View.Name.create("View 2"), VIEW_DESCRIPTION, MEASURE_DOUBLE, DISTRIBUTION, Arrays.asList(KEY), CUMULATIVE);
thrown.expect(UnsupportedOperationException.class);
exported.add(view2);
}
use of io.opencensus.stats.View 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.View 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();
}
use of io.opencensus.stats.View in project instrumentation-java by census-instrumentation.
the class RpczZPageHandler method getStatsSnapshots.
private void getStatsSnapshots(Map<String, StatsSnapshot> map, List<View> views) {
for (View view : views) {
ViewData viewData = viewManager.getView(view.getName());
if (viewData == null) {
continue;
}
for (Entry<List<TagValue>, AggregationData> /*@Nullable*/
entry : viewData.getAggregationMap().entrySet()) {
TagValue tagValue;
List<TagValue> /*@Nullable*/
tagValues = entry.getKey();
if (tagValues.size() == 1) {
tagValue = tagValues.get(0);
} else {
// Error count views have two tag key: status and method.
tagValue = tagValues.get(1);
}
String method = tagValue == null ? "" : tagValue.asString();
StatsSnapshot snapshot = map.get(method);
if (snapshot == null) {
snapshot = new StatsSnapshot();
map.put(method, snapshot);
}
getStats(snapshot, entry.getValue(), view, viewData.getWindowData());
}
}
}
Aggregations