Skip to content

Commit e5394bd

Browse files
committed
fix: apply changes picked up in rebase
1 parent be43207 commit e5394bd

File tree

3 files changed

+22
-31
lines changed

3 files changed

+22
-31
lines changed

packages/sdk-metrics/src/aggregator/ExponentialHistogram.ts

+11-16
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@ import { InstrumentDescriptor, InstrumentType } from '../InstrumentDescriptor';
2929
import { Maybe } from '../utils';
3030
import { AggregationTemporality } from '../export/AggregationTemporality';
3131
import { Buckets } from './exponential-histogram/Buckets';
32+
import { getMapping } from './exponential-histogram/mapping/getMapping';
3233
import { Mapping } from './exponential-histogram/mapping/types';
33-
import { ExponentMapping } from './exponential-histogram/mapping/ExponentMapping';
34-
import { LogarithmMapping } from './exponential-histogram/mapping/LogarithmMapping';
3534
import * as util from './exponential-histogram//util';
3635

3736
/**
@@ -66,13 +65,14 @@ class HighLow {
6665
constructor(public low: number, public high: number) {}
6766
}
6867

69-
export class ExponentialHistogramAccumulation implements Accumulation {
70-
static DEFAULT_MAX_SIZE = 160;
71-
static MIN_MAX_SIZE = 2;
68+
const MAX_SCALE = 20;
69+
const DEFAULT_MAX_SIZE = 160;
70+
const MIN_MAX_SIZE = 2;
7271

72+
export class ExponentialHistogramAccumulation implements Accumulation {
7373
constructor(
7474
public startTime: HrTime = startTime,
75-
private _maxSize = ExponentialHistogramAccumulation.DEFAULT_MAX_SIZE,
75+
private _maxSize = DEFAULT_MAX_SIZE,
7676
private _recordMinMax = true,
7777
private _sum = 0,
7878
private _count = 0,
@@ -81,13 +81,12 @@ export class ExponentialHistogramAccumulation implements Accumulation {
8181
private _max = Number.NEGATIVE_INFINITY,
8282
private _positive = new Buckets(),
8383
private _negative = new Buckets(),
84-
private _mapping: Mapping = LogarithmMapping.get(LogarithmMapping.MAX_SCALE)
84+
private _mapping: Mapping = getMapping(MAX_SCALE)
8585
) {
86-
if (this._maxSize < ExponentialHistogramAccumulation.MIN_MAX_SIZE) {
86+
if (this._maxSize < MIN_MAX_SIZE) {
8787
diag.warn(`Exponential Histogram Max Size set to ${this._maxSize}, \
88-
changing to the minimum size of: \
89-
${ExponentialHistogramAccumulation.MIN_MAX_SIZE}`);
90-
this._maxSize = ExponentialHistogramAccumulation.MIN_MAX_SIZE;
88+
changing to the minimum size of: ${MIN_MAX_SIZE}`);
89+
this._maxSize = MIN_MAX_SIZE;
9190
}
9291
}
9392

@@ -419,11 +418,7 @@ export class ExponentialHistogramAccumulation implements Accumulation {
419418
this._positive.downscale(change);
420419
this._negative.downscale(change);
421420

422-
if (newScale <= 0) {
423-
this._mapping = ExponentMapping.get(newScale);
424-
} else {
425-
this._mapping = LogarithmMapping.get(newScale);
426-
}
421+
this._mapping = getMapping(newScale);
427422
}
428423

429424
/**

packages/sdk-metrics/test/aggregator/ExponentialHistogram.test.ts

+2-14
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ import {
2626
ExponentialHistogramAggregator,
2727
} from '../../src/aggregator/ExponentialHistogram';
2828
import { Buckets } from '../../src/aggregator/exponential-histogram/Buckets';
29+
import { getMapping } from '../../src/aggregator/exponential-histogram/mapping/getMapping';
2930
import { Mapping } from '../../src/aggregator/exponential-histogram//mapping/types';
30-
import { ExponentMapping } from '../../src/aggregator/exponential-histogram//mapping/ExponentMapping';
31-
import { LogarithmMapping } from '../../src/aggregator/exponential-histogram/mapping/LogarithmMapping';
3231
import * as assert from 'assert';
3332
import {
3433
assertInEpsilon,
@@ -534,10 +533,7 @@ describe('ExponentialHistogramAccumulation', () => {
534533
describe('min max size', () => {
535534
it('auto-corrects to min max', () => {
536535
const acc: any = new ExponentialHistogramAccumulation([0, 0], 0);
537-
assert.strictEqual(
538-
acc['_maxSize'],
539-
ExponentialHistogramAccumulation.MIN_MAX_SIZE
540-
);
536+
assert.strictEqual(acc['_maxSize'], 2);
541537
});
542538
});
543539
});
@@ -783,14 +779,6 @@ function centerValue(mapper: Mapping, x: number): number {
783779
return (lower + upper) / 2;
784780
}
785781

786-
function getMapping(scale: number): Mapping {
787-
if (scale <= 0) {
788-
return ExponentMapping.get(scale);
789-
} else {
790-
return LogarithmMapping.get(scale);
791-
}
792-
}
793-
794782
function assertHistogramsEqual(
795783
actual: ExponentialHistogramAccumulation,
796784
expected: ExponentialHistogramAccumulation

packages/sdk-metrics/test/aggregator/exponential-histogram/helpers.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export function assertInEpsilon(
2121
epsilon: number
2222
) {
2323
assert.ok(!Number.isNaN(actual), 'unexpected NaN for actual argument');
24-
assert.ok(!Number.isNaN(expected), 'unexpected NaN for expected argument');
24+
assert.ok(!Number.isNaN(expected), 'unexpected NaN for exepected argument');
2525
assert.ok(actual !== 0, 'unexpected 0 for actual argument');
2626

2727
const relErr = Math.abs(actual - expected) / Math.abs(actual);
@@ -31,3 +31,11 @@ export function assertInEpsilon(
3131
`expected relative error: ${relErr} to be < ${epsilon}`
3232
);
3333
}
34+
35+
export function assertInDelta(actual: number, expected: number, delta: number) {
36+
const actualDelta = Math.abs(expected - actual);
37+
assert.ok(
38+
actualDelta < delta,
39+
`expected delta: ${delta} to be < ${actualDelta}`
40+
);
41+
}

0 commit comments

Comments
 (0)