Skip to content
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 @@ -45,6 +45,7 @@ export class HistogramAggregator implements HistogramAggregatorType {
}

update(value: number): void {
this._lastUpdateTime = hrTime();
this._current.count += 1;
this._current.sum += value;

Expand All @@ -54,7 +55,6 @@ export class HistogramAggregator implements HistogramAggregatorType {
return;
}
}

// value is above all observed boundaries
this._current.buckets.counts[this._boundaries.length] += 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import * as assert from 'assert';
import { HistogramAggregator } from '../../../src/export/aggregators';
import { Histogram } from '../../../src';
import { hrTime, hrTimeToMilliseconds } from '@opentelemetry/core';
import sinon = require('sinon');

describe('HistogramAggregator', () => {
describe('constructor()', () => {
Expand Down Expand Up @@ -99,6 +101,30 @@ describe('HistogramAggregator', () => {
});
});

describe('.timestamp', () => {
let clock: sinon.SinonFakeTimers;
before(() => {
clock = sinon.useFakeTimers({ toFake: ['hrtime'] });
});

it('should update point timestamp', () => {
const aggregator = new HistogramAggregator([100, 200]);
const timestamp = hrTimeToMilliseconds(hrTime());
const timeDiff = 10;
clock.tick(timeDiff);
aggregator.update(150);
assert.equal(
hrTimeToMilliseconds(aggregator.toPoint().timestamp) >=
timestamp + timeDiff,
true
);
});

after(() => {
clock.restore();
});
});

describe('.count', () => {
it('should return last checkpoint count', () => {
const aggregator = new HistogramAggregator([100]);
Expand Down