io.opencensus.stats.AggregationData Java Examples
The following examples show how to use
io.opencensus.stats.AggregationData.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StatszZPageHandler.java From opencensus-java with Apache License 2.0 | 6 votes |
private static void emitViewData( /*@Nullable*/ ViewData viewData, View.Name viewName, PrintWriter out, Formatter formatter) { if (viewData == null) { formatter.format("<p class=\"view\">No Stats found for View %s.</p>", viewName.asString()); return; } View view = viewData.getView(); emitViewInfo(view, viewData.getWindowData(), out, formatter); formatter.format("<p class=\"view\">Stats for View: %s</p>", view.getName().asString()); formatter.format("<table cellspacing=0 cellpadding=0>"); emitViewDataTableHeader(view, out, formatter); for (Entry<List</*@Nullable*/ TagValue>, AggregationData> entry : viewData.getAggregationMap().entrySet()) { emitViewDataRow(view, entry, out, formatter); } out.write("</table>"); out.write("<p></p>"); }
Example #2
Source File: RpczZPageHandler.java From opencensus-java with Apache License 2.0 | 6 votes |
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</*@Nullable*/ TagValue>, AggregationData> entry : viewData.getAggregationMap().entrySet()) { TagValue tagValue; List</*@Nullable*/ TagValue> 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()); } } }
Example #3
Source File: MutableAggregation.java From opencensus-java with Apache License 2.0 | 6 votes |
@Override AggregationData toAggregationData() { List<Long> boxedBucketCounts = new ArrayList<Long>(); for (long bucketCount : bucketCounts) { boxedBucketCounts.add(bucketCount); } List<Exemplar> exemplarList = new ArrayList<Exemplar>(); if (exemplars != null) { for (Exemplar exemplar : exemplars) { if (exemplar != null) { exemplarList.add(exemplar); } } } return DistributionData.create( mean, count, sumOfSquaredDeviations, boxedBucketCounts, exemplarList); }
Example #4
Source File: MutableViewData.java From opencensus-java with Apache License 2.0 | 6 votes |
@Override ViewData toViewData(Timestamp now, State state) { refreshBucketList(now); if (state == State.ENABLED) { return ViewData.create( super.view, combineBucketsAndGetAggregationMap(now), ViewData.AggregationWindowData.IntervalData.create(now)); } else { // If Stats state is DISABLED, return an empty ViewData. return ViewData.create( super.view, Collections.<List</*@Nullable*/ TagValue>, AggregationData>emptyMap(), ViewData.AggregationWindowData.IntervalData.create(ZERO_TIMESTAMP)); } }
Example #5
Source File: OpenCensusTest.java From google-maps-services-java with Apache License 2.0 | 5 votes |
@Test public void testSuccess() throws Exception { server.enqueue(mockResponse(500, "OK", 100)); // retry 1 server.enqueue(mockResponse(500, "OK", 100)); // retry 2 server.enqueue(mockResponse(200, "OK", 300)); // succeed GeocodingResult[] result = context.get(new ApiConfig("/path"), GeocodingApi.Response.class, "k", "v").await(); assertEquals(1, result.length); List<TagValue> tags = Arrays.asList(TagValue.create(""), TagValue.create("200"), TagValue.create("/path")); Map.Entry<List<TagValue>, AggregationData> latencyMetric = getMetric("maps.googleapis.com/client/request_latency"); assertNotNull(latencyMetric); assertEquals(tags, latencyMetric.getKey()); AggregationData.DistributionData latencyDist = (AggregationData.DistributionData) latencyMetric.getValue(); assertEquals(1, latencyDist.getCount()); assertTrue(latencyDist.getMean() > 500); Map.Entry<List<TagValue>, AggregationData> retryMetric = getMetric("maps.googleapis.com/client/retry_count"); assertNotNull(retryMetric); assertEquals(tags, retryMetric.getKey()); AggregationData.DistributionData retryDist = (AggregationData.DistributionData) retryMetric.getValue(); assertEquals(1, retryDist.getCount()); assertEquals(2.0, retryDist.getMean(), 0.1); Map.Entry<List<TagValue>, AggregationData> countMetric = getMetric("maps.googleapis.com/client/request_count"); assertNotNull(countMetric); assertEquals(tags, countMetric.getKey()); AggregationData.CountData count = (AggregationData.CountData) countMetric.getValue(); assertEquals(1, count.getCount()); }
Example #6
Source File: RecordUtils.java From opencensus-java with Apache License 2.0 | 5 votes |
static <T> Map<T, AggregationData> createAggregationMap( Map<T, MutableAggregation> tagValueAggregationMap, Measure measure) { Map<T, AggregationData> map = Maps.newHashMap(); for (Entry<T, MutableAggregation> entry : tagValueAggregationMap.entrySet()) { map.put(entry.getKey(), entry.getValue().toAggregationData()); } return map; }
Example #7
Source File: OpenCensusTest.java From google-maps-services-java with Apache License 2.0 | 5 votes |
private Map.Entry<List<TagValue>, AggregationData> getMetric(String name) { sleep(10); ViewData viewData = Stats.getViewManager().getView(View.Name.create(name)); Map<List<TagValue>, AggregationData> values = viewData.getAggregationMap(); assertEquals(1, values.size()); for (Map.Entry<List<TagValue>, AggregationData> entry : values.entrySet()) { return entry; } return null; }
Example #8
Source File: StatsTestUtil.java From opencensus-java with Apache License 2.0 | 5 votes |
static ViewData createEmptyViewData(View view) { return ViewData.create( view, Collections.<List<TagValue>, AggregationData>emptyMap(), view.getWindow() .match( Functions.<AggregationWindowData>returnConstant( CumulativeData.create(ZERO_TIMESTAMP, ZERO_TIMESTAMP)), Functions.<AggregationWindowData>returnConstant( IntervalData.create(ZERO_TIMESTAMP)), Functions.<AggregationWindowData>throwAssertionError())); }
Example #9
Source File: StatsTestUtil.java From opencensus-java with Apache License 2.0 | 5 votes |
/** * Compare the actual and expected AggregationMap within the given tolerance. * * @param expected the expected map. * @param actual the actual mapping from {@code List<TagValue>} to {@code AggregationData}. * @param tolerance the tolerance used for {@code double} comparison. */ static void assertAggregationMapEquals( Map<? extends List<? extends TagValue>, ? extends AggregationData> actual, Map<? extends List<? extends TagValue>, ? extends AggregationData> expected, double tolerance) { assertThat(actual.keySet()).containsExactlyElementsIn(expected.keySet()); for (Entry<? extends List<? extends TagValue>, ? extends AggregationData> entry : actual.entrySet()) { assertAggregationDataEquals(expected.get(entry.getKey()), entry.getValue(), tolerance); } }
Example #10
Source File: StatsTestUtil.java From opencensus-java with Apache License 2.0 | 5 votes |
/** * Creates an {@link AggregationData} by adding the given sequence of values, based on the * definition of the given {@link Aggregation}. * * @param aggregation the {@code Aggregation} to apply the values to. * @param values the values to add to the {@code MutableAggregation}s. * @return an {@code AggregationData}. */ static AggregationData createAggregationData( Aggregation aggregation, Measure measure, double... values) { MutableAggregation mutableAggregation = RecordUtils.createMutableAggregation(aggregation, measure); for (double value : values) { mutableAggregation.add(value, Collections.<String, AttachmentValue>emptyMap(), EMPTY); } return mutableAggregation.toAggregationData(); }
Example #11
Source File: MutableViewData.java From opencensus-java with Apache License 2.0 | 5 votes |
private Map<List</*@Nullable*/ TagValue>, AggregationData> combineBucketsAndGetAggregationMap( Timestamp now) { // Need to maintain the order of inserted MutableAggregations (inserted based on time order). Multimap<List</*@Nullable*/ TagValue>, MutableAggregation> multimap = LinkedHashMultimap.create(); ArrayDeque<IntervalBucket> shallowCopy = new ArrayDeque<IntervalBucket>(buckets); Aggregation aggregation = super.view.getAggregation(); Measure measure = super.view.getMeasure(); putBucketsIntoMultiMap(shallowCopy, multimap, aggregation, measure, now); Map<List</*@Nullable*/ TagValue>, MutableAggregation> singleMap = aggregateOnEachTagValueList(multimap, aggregation, measure); return createAggregationMap(singleMap, super.getView().getMeasure()); }
Example #12
Source File: MutableViewData.java From opencensus-java with Apache License 2.0 | 5 votes |
@Override ViewData toViewData(Timestamp now, State state) { if (state == State.ENABLED) { return ViewData.create( super.view, createAggregationMap(tagValueAggregationMap, super.view.getMeasure()), ViewData.AggregationWindowData.CumulativeData.create(start, now)); } else { // If Stats state is DISABLED, return an empty ViewData. return ViewData.create( super.view, Collections.<List</*@Nullable*/ TagValue>, AggregationData>emptyMap(), ViewData.AggregationWindowData.CumulativeData.create(ZERO_TIMESTAMP, ZERO_TIMESTAMP)); } }
Example #13
Source File: MutableAggregation.java From opencensus-java with Apache License 2.0 | 4 votes |
@Override AggregationData toAggregationData() { return AggregationData.LastValueDataLong.create(Math.round(getLastValue())); }
Example #14
Source File: MutableAggregation.java From opencensus-java with Apache License 2.0 | 4 votes |
@Override AggregationData toAggregationData() { return AggregationData.LastValueDataDouble.create(lastValue); }
Example #15
Source File: MutableAggregation.java From opencensus-java with Apache License 2.0 | 4 votes |
@SuppressWarnings("deprecation") @Override AggregationData toAggregationData() { return AggregationData.MeanData.create(getMean(), count); }
Example #16
Source File: ViewManagerImplTest.java From opencensus-java with Apache License 2.0 | 4 votes |
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)); long startTimeMillis = 30 * MILLIS_PER_SECOND; // start at 30s 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(); }
Example #17
Source File: MutableAggregationTest.java From opencensus-java with Apache License 2.0 | 4 votes |
@Test public void testAdd() { List<MutableAggregation> aggregations = Arrays.asList( MutableSumDouble.create(), MutableSumLong.create(), MutableCount.create(), MutableMean.create(), MutableDistribution.create(BUCKET_BOUNDARIES), MutableLastValueDouble.create(), MutableLastValueLong.create()); List<Double> values = Arrays.asList(-1.0, 1.0, -5.0, 20.0, 5.0); for (double value : values) { for (MutableAggregation aggregation : aggregations) { aggregation.add(value, Collections.<String, AttachmentValue>emptyMap(), TIMESTAMP); } } assertAggregationDataEquals( aggregations.get(0).toAggregationData(), AggregationData.SumDataDouble.create(20.0), TOLERANCE); assertAggregationDataEquals( aggregations.get(1).toAggregationData(), AggregationData.SumDataLong.create(20), TOLERANCE); assertAggregationDataEquals( aggregations.get(2).toAggregationData(), AggregationData.CountData.create(5), TOLERANCE); assertAggregationDataEquals( aggregations.get(3).toAggregationData(), AggregationData.MeanData.create(4.0, 5), TOLERANCE); assertAggregationDataEquals( aggregations.get(4).toAggregationData(), AggregationData.DistributionData.create(4.0, 5, 372, Arrays.asList(4L, 1L)), TOLERANCE); assertAggregationDataEquals( aggregations.get(5).toAggregationData(), AggregationData.LastValueDataDouble.create(5.0), TOLERANCE); assertAggregationDataEquals( aggregations.get(6).toAggregationData(), AggregationData.LastValueDataLong.create(5), TOLERANCE); }
Example #18
Source File: MutableAggregation.java From opencensus-java with Apache License 2.0 | 4 votes |
@Override AggregationData toAggregationData() { return AggregationData.CountData.create(count); }
Example #19
Source File: MutableAggregation.java From opencensus-java with Apache License 2.0 | 4 votes |
@Override AggregationData toAggregationData() { return AggregationData.SumDataLong.create(Math.round(getSum())); }
Example #20
Source File: MutableAggregation.java From opencensus-java with Apache License 2.0 | 4 votes |
@Override AggregationData toAggregationData() { return AggregationData.SumDataDouble.create(sum); }
Example #21
Source File: MutableAggregation.java From opencensus-java with Apache License 2.0 | votes |
abstract AggregationData toAggregationData();