io.opencensus.stats.BucketBoundaries Java Examples
The following examples show how to use
io.opencensus.stats.BucketBoundaries.
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: ViewManagerImplTest.java From opencensus-java with Apache License 2.0 | 6 votes |
@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); }
Example #2
Source File: MutableAggregationTest.java From opencensus-java with Apache License 2.0 | 6 votes |
@Test public void testCreateEmpty() { assertThat(MutableSumDouble.create().getSum()).isWithin(TOLERANCE).of(0); assertThat(MutableSumLong.create().getSum()).isWithin(TOLERANCE).of(0); assertThat(MutableCount.create().getCount()).isEqualTo(0); assertThat(MutableMean.create().getMean()).isWithin(TOLERANCE).of(0); assertThat(MutableLastValueDouble.create().getLastValue()).isNaN(); assertThat(MutableLastValueLong.create().getLastValue()).isNaN(); BucketBoundaries bucketBoundaries = BucketBoundaries.create(Arrays.asList(0.1, 2.2, 33.3)); MutableDistribution mutableDistribution = MutableDistribution.create(bucketBoundaries); assertThat(mutableDistribution.getMean()).isWithin(TOLERANCE).of(0); assertThat(mutableDistribution.getCount()).isEqualTo(0); assertThat(mutableDistribution.getSumOfSquaredDeviations()).isWithin(TOLERANCE).of(0); assertThat(mutableDistribution.getBucketCounts()).isEqualTo(new long[4]); assertThat(mutableDistribution.getExemplars()).isEqualTo(new Exemplar[4]); MutableDistribution mutableDistributionNoHistogram = MutableDistribution.create(BUCKET_BOUNDARIES_EMPTY); assertThat(mutableDistributionNoHistogram.getExemplars()).isNull(); }
Example #3
Source File: BatchWrite.java From gcp-ingestion with Mozilla Public License 2.0 | 5 votes |
/** * Create exponential distribution for aggregating values. * * <p>Round boundaries to the nearest integer and remove duplicates. */ private static Distribution exponentialDistribution(double base, double expStart, double expStep, long steps) { return Distribution .create(BucketBoundaries.create(DoubleStream.iterate(expStart, v -> v + expStep) .limit(steps + 1).map(exp -> Math.round(Math.pow(base, exp))).distinct().boxed() .collect(Collectors.toList()))); }
Example #4
Source File: MutableAggregation.java From opencensus-java with Apache License 2.0 | 5 votes |
private MutableDistribution(BucketBoundaries bucketBoundaries) { this.bucketBoundaries = bucketBoundaries; int buckets = bucketBoundaries.getBoundaries().size() + 1; this.bucketCounts = new long[buckets]; // In the implementation, each histogram bucket can have up to one exemplar, and the exemplar // array is guaranteed to be in ascending order. // If there's no histogram, don't record exemplars. this.exemplars = bucketBoundaries.getBoundaries().isEmpty() ? null : new Exemplar[buckets]; }
Example #5
Source File: RecordUtilsTest.java From opencensus-java with Apache License 2.0 | 5 votes |
@Test public void createMutableAggregation() { BucketBoundaries bucketBoundaries = BucketBoundaries.create(Arrays.asList(-1.0, 0.0, 1.0)); assertThat( RecordUtils.createMutableAggregation(Sum.create(), MEASURE_DOUBLE).toAggregationData()) .isEqualTo(SumDataDouble.create(0)); assertThat(RecordUtils.createMutableAggregation(Sum.create(), MEASURE_LONG).toAggregationData()) .isEqualTo(SumDataLong.create(0)); assertThat( RecordUtils.createMutableAggregation(Count.create(), MEASURE_DOUBLE) .toAggregationData()) .isEqualTo(CountData.create(0)); assertThat( RecordUtils.createMutableAggregation(Count.create(), MEASURE_LONG).toAggregationData()) .isEqualTo(CountData.create(0)); assertThat( RecordUtils.createMutableAggregation(Mean.create(), MEASURE_DOUBLE).toAggregationData()) .isEqualTo(MeanData.create(0, 0)); assertThat( RecordUtils.createMutableAggregation(Mean.create(), MEASURE_LONG).toAggregationData()) .isEqualTo(MeanData.create(0, 0)); assertThat( RecordUtils.createMutableAggregation(LastValue.create(), MEASURE_DOUBLE) .toAggregationData()) .isEqualTo(LastValueDataDouble.create(Double.NaN)); assertThat( RecordUtils.createMutableAggregation(LastValue.create(), MEASURE_LONG) .toAggregationData()) .isEqualTo(LastValueDataLong.create(0)); MutableDistribution mutableDistribution = (MutableDistribution) RecordUtils.createMutableAggregation( Distribution.create(bucketBoundaries), MEASURE_DOUBLE); assertThat(mutableDistribution.getSumOfSquaredDeviations()).isWithin(EPSILON).of(0); assertThat(mutableDistribution.getBucketCounts()).isEqualTo(new long[2]); }
Example #6
Source File: MutableAggregationTest.java From opencensus-java with Apache License 2.0 | 5 votes |
@Test public void testNoBoundaries() { MutableDistribution noBoundaries = MutableDistribution.create(BucketBoundaries.create(Collections.<Double>emptyList())); assertThat(noBoundaries.getBucketCounts().length).isEqualTo(1); assertThat(noBoundaries.getBucketCounts()[0]).isEqualTo(0); }
Example #7
Source File: TelemetryUtils.java From meghanada-server with GNU General Public License v3.0 | 4 votes |
private static void registerAllViews() { Aggregation commandLatencyDistribution = Aggregation.Distribution.create( BucketBoundaries.create( Arrays.asList( 0.0, // >=0ms 25.0, // >=25ms 50.0, // >=50ms 100.0, // >=100ms 200.0, // >=200ms 400.0, // >=400ms 800.0, // >=800ms 1000.0, // >=1s 2000.0, // >=2s 5000.0, // >=5s 8000.0, // >=8s 10000.0 // >=10s ))); View[] views; views = new View[] { View.create( View.Name.create("meghanada/command_latency"), "The distribution of the command latencies", M_COMMAND_LATENCY_MS, commandLatencyDistribution, Collections.unmodifiableList(Arrays.asList(KEY_UID, KEY_COMMAND))), View.create( View.Name.create("meghanada/class_index_size"), "The number of class indexes", M_CLASS_INDEX, Aggregation.LastValue.create(), Collections.unmodifiableList(Collections.singletonList(KEY_UID))), View.create( View.Name.create("meghanada/autocomplete"), "The number of autocomplete count", M_AUTOCOMPLETE_COUNT, Aggregation.Sum.create(), Collections.unmodifiableList(Arrays.asList(KEY_UID, KEY_DESCRIPTION))), View.create( View.Name.create("meghanada/member_cache_hit_rate"), "The member cache hit rate", M_MEMBER_CACHE_HIT_RATE, Aggregation.LastValue.create(), Collections.unmodifiableList(Collections.singletonList(KEY_UID))), View.create( View.Name.create("meghanada/member_cache_load_exception_rate"), "The member cache load exception rate", M_MEMBER_CACHE_LOAD_ERROR_RATE, Aggregation.LastValue.create(), Collections.unmodifiableList(Collections.singletonList(KEY_UID))), View.create( View.Name.create("meghanada/member_cache_miss_rate"), "The member cache miss rate", M_MEMBER_CACHE_MISS_RATE, Aggregation.LastValue.create(), Collections.unmodifiableList(Collections.singletonList(KEY_UID))), View.create( View.Name.create("meghanada/vm_memory"), "The vm memory", M_MEMORY, Aggregation.LastValue.create(), Collections.unmodifiableList(Collections.singletonList(KEY_UID))), }; ViewManager vmgr = Stats.getViewManager(); for (View view : views) { vmgr.registerView(view); } }
Example #8
Source File: Repl.java From opencensus-java with Apache License 2.0 | 4 votes |
private static void registerAllViews() { // Defining the distribution aggregations Aggregation latencyDistribution = Distribution.create( BucketBoundaries.create( Arrays.asList( // [>=0ms, >=25ms, >=50ms, >=75ms, >=100ms, >=200ms, >=400ms, >=600ms, >=800ms, // >=1s, >=2s, >=4s, >=6s] 0.0, 25.0, 50.0, 75.0, 100.0, 200.0, 400.0, 600.0, 800.0, 1000.0, 2000.0, 4000.0, 6000.0))); Aggregation lengthsDistribution = Distribution.create( BucketBoundaries.create( Arrays.asList( // [>=0B, >=5B, >=10B, >=20B, >=40B, >=60B, >=80B, >=100B, >=200B, >=400B, // >=600B, // >=800B, >=1000B] 0.0, 5.0, 10.0, 20.0, 40.0, 60.0, 80.0, 100.0, 200.0, 400.0, 600.0, 800.0, 1000.0))); // Define the count aggregation Aggregation countAggregation = Aggregation.Count.create(); // So tagKeys List<TagKey> noKeys = new ArrayList<TagKey>(); // Define the views View[] views = new View[] { View.create( Name.create("ocjavametrics/latency"), "The distribution of latencies", M_LATENCY_MS, latencyDistribution, Collections.singletonList(KEY_METHOD)), View.create( Name.create("ocjavametrics/lines_in"), "The number of lines read in from standard input", M_LINES_IN, countAggregation, noKeys), View.create( Name.create("ocjavametrics/errors"), "The number of errors encountered", M_ERRORS, countAggregation, Collections.singletonList(KEY_METHOD)), View.create( Name.create("ocjavametrics/line_lengths"), "The distribution of line lengths", M_LINE_LENGTHS, lengthsDistribution, noKeys) }; // Create the view manager ViewManager vmgr = Stats.getViewManager(); // Then finally register the views for (View view : views) { vmgr.registerView(view); } }
Example #9
Source File: MutableAggregation.java From opencensus-java with Apache License 2.0 | 4 votes |
BucketBoundaries getBucketBoundaries() { return bucketBoundaries; }
Example #10
Source File: MutableAggregation.java From opencensus-java with Apache License 2.0 | 2 votes |
/** * Construct a {@code MutableDistribution}. * * @return an empty {@code MutableDistribution}. */ static MutableDistribution create(BucketBoundaries bucketBoundaries) { checkNotNull(bucketBoundaries, "bucketBoundaries should not be null."); return new MutableDistribution(bucketBoundaries); }