Skip to content

Commit

Permalink
fix: proper histogram boundaries sort (#1475)
Browse files Browse the repository at this point in the history
Co-authored-by: Valentin Marchaud <[email protected]>
  • Loading branch information
AndrewGrachov and vmarchaud authored Aug 28, 2020
1 parent e440d5e commit c5294ba
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class HistogramAggregator implements HistogramAggregatorType {
}
// we need to an ordered set to be able to correctly compute count for each
// boundary since we'll iterate on each in order.
this._boundaries = boundaries.sort();
this._boundaries = boundaries.sort((a, b) => a - b);
this._current = this._newEmptyCheckpoint();
this._lastUpdateTime = hrTime();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,23 @@ describe('HistogramAggregator', () => {
});

it('should sort boundaries', () => {
const aggregator = new HistogramAggregator([500, 300, 700]);
const aggregator = new HistogramAggregator([
200,
500,
300,
700,
1000,
1500,
]);
const point = aggregator.toPoint().value as Histogram;
assert.deepEqual(point.buckets.boundaries, [300, 500, 700]);
assert.deepEqual(point.buckets.boundaries, [
200,
300,
500,
700,
1000,
1500,
]);
});

it('should throw if no boundaries are defined', () => {
Expand Down

0 comments on commit c5294ba

Please sign in to comment.