Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: proper histogram boundaries sort #1475

Merged
merged 3 commits into from
Aug 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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