From 54bbb5c8528f24ca426fdcfd9dd08e9c690c6a81 Mon Sep 17 00:00:00 2001 From: Tiger He Date: Fri, 14 Aug 2020 02:24:24 -0400 Subject: [PATCH] chore: adding test and comment fix --- packages/opentelemetry-metrics/src/export/types.ts | 14 ++++++-------- .../test/export/aggregators/Histogram.test.ts | 11 +++++++++++ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/packages/opentelemetry-metrics/src/export/types.ts b/packages/opentelemetry-metrics/src/export/types.ts index 37f8912acc..fa1c9ddca2 100644 --- a/packages/opentelemetry-metrics/src/export/types.ts +++ b/packages/opentelemetry-metrics/src/export/types.ts @@ -53,21 +53,19 @@ export interface Distribution { export interface Histogram { /** - * Buckets are implemented using two different array: - * - boundaries contains every boundary (which are upper boundary for each slice) - * - counts contains count of event for each slice + * Buckets are implemented using two different arrays: + * - boundaries: contains every finite bucket boundary, which are inclusive lower bounds + * - counts contains event counts for each slice * - * Note that we'll always have n+1 (where n is the number of boundaries) slice - * because we need to count event that are above the highest boundary. This is the - * reason why it's not implement using array of object, because the last slice - * dont have any boundary. + * Note that we'll always have n+1 buckets, where n is the number of boundaries. + * Thsi is because we need to count events that are below the lowest boundary. * * Example if we measure the values: [5, 30, 5, 40, 5, 15, 15, 15, 25] * with the boundaries [ 10, 20, 30 ], we will have the following state: * * buckets: { * boundaries: [10, 20, 30], - * counts: [3, 3, 2, 1], + * counts: [3, 3, 1, 2], * } */ buckets: { diff --git a/packages/opentelemetry-metrics/test/export/aggregators/Histogram.test.ts b/packages/opentelemetry-metrics/test/export/aggregators/Histogram.test.ts index 9a2b43938c..c2397ae0b8 100644 --- a/packages/opentelemetry-metrics/test/export/aggregators/Histogram.test.ts +++ b/packages/opentelemetry-metrics/test/export/aggregators/Histogram.test.ts @@ -72,6 +72,17 @@ describe('HistogramAggregator', () => { assert.equal(point.buckets.counts[1], 0); assert.equal(point.buckets.counts[2], 1); }); + + it('should update the third bucket since boundaries are inclusive lower bounds', () => { + const aggregator = new HistogramAggregator([100, 200]); + aggregator.update(200); + const point = aggregator.toPoint().value as Histogram; + assert.equal(point.count, 1); + assert.equal(point.sum, 200); + assert.equal(point.buckets.counts[0], 0); + assert.equal(point.buckets.counts[1], 0); + assert.equal(point.buckets.counts[2], 1); + }); }); describe('.count', () => {