Skip to content

Commit

Permalink
chore: fix histogram type documentation (#1427)
Browse files Browse the repository at this point in the history
Co-authored-by: Valentin Marchaud <[email protected]>
Co-authored-by: Daniel Dyla <[email protected]>
  • Loading branch information
3 people authored Aug 17, 2020
1 parent 2916ecf commit d511a0e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
16 changes: 7 additions & 9 deletions packages/opentelemetry-metrics/src/export/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 bucket
*
* 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.
* This 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]
* 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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit d511a0e

Please sign in to comment.