Skip to content

Commit

Permalink
fix: apply changes picked up in rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
mwear committed Jan 28, 2023
1 parent be43207 commit dcd4cd2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 30 deletions.
27 changes: 11 additions & 16 deletions packages/sdk-metrics/src/aggregator/ExponentialHistogram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ import { InstrumentDescriptor, InstrumentType } from '../InstrumentDescriptor';
import { Maybe } from '../utils';
import { AggregationTemporality } from '../export/AggregationTemporality';
import { Buckets } from './exponential-histogram/Buckets';
import { getMapping } from './exponential-histogram/mapping/getMapping';
import { Mapping } from './exponential-histogram/mapping/types';
import { ExponentMapping } from './exponential-histogram/mapping/ExponentMapping';
import { LogarithmMapping } from './exponential-histogram/mapping/LogarithmMapping';
import * as util from './exponential-histogram//util';

/**
Expand Down Expand Up @@ -66,13 +65,14 @@ class HighLow {
constructor(public low: number, public high: number) {}
}

export class ExponentialHistogramAccumulation implements Accumulation {
static DEFAULT_MAX_SIZE = 160;
static MIN_MAX_SIZE = 2;
const MAX_SCALE = 20;
const DEFAULT_MAX_SIZE = 160;
const MIN_MAX_SIZE = 2;

export class ExponentialHistogramAccumulation implements Accumulation {
constructor(
public startTime: HrTime = startTime,
private _maxSize = ExponentialHistogramAccumulation.DEFAULT_MAX_SIZE,
private _maxSize = DEFAULT_MAX_SIZE,
private _recordMinMax = true,
private _sum = 0,
private _count = 0,
Expand All @@ -81,13 +81,12 @@ export class ExponentialHistogramAccumulation implements Accumulation {
private _max = Number.NEGATIVE_INFINITY,
private _positive = new Buckets(),
private _negative = new Buckets(),
private _mapping: Mapping = LogarithmMapping.get(LogarithmMapping.MAX_SCALE)
private _mapping: Mapping = getMapping(MAX_SCALE)
) {
if (this._maxSize < ExponentialHistogramAccumulation.MIN_MAX_SIZE) {
if (this._maxSize < MIN_MAX_SIZE) {
diag.warn(`Exponential Histogram Max Size set to ${this._maxSize}, \
changing to the minimum size of: \
${ExponentialHistogramAccumulation.MIN_MAX_SIZE}`);
this._maxSize = ExponentialHistogramAccumulation.MIN_MAX_SIZE;
changing to the minimum size of: ${MIN_MAX_SIZE}`);
this._maxSize = MIN_MAX_SIZE;
}
}

Expand Down Expand Up @@ -419,11 +418,7 @@ export class ExponentialHistogramAccumulation implements Accumulation {
this._positive.downscale(change);
this._negative.downscale(change);

if (newScale <= 0) {
this._mapping = ExponentMapping.get(newScale);
} else {
this._mapping = LogarithmMapping.get(newScale);
}
this._mapping = getMapping(newScale);
}

/**
Expand Down
16 changes: 2 additions & 14 deletions packages/sdk-metrics/test/aggregator/ExponentialHistogram.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ import {
ExponentialHistogramAggregator,
} from '../../src/aggregator/ExponentialHistogram';
import { Buckets } from '../../src/aggregator/exponential-histogram/Buckets';
import { getMapping } from '../../src/aggregator/exponential-histogram/mapping/getMapping';
import { Mapping } from '../../src/aggregator/exponential-histogram//mapping/types';
import { ExponentMapping } from '../../src/aggregator/exponential-histogram//mapping/ExponentMapping';
import { LogarithmMapping } from '../../src/aggregator/exponential-histogram/mapping/LogarithmMapping';
import * as assert from 'assert';
import {
assertInEpsilon,
Expand Down Expand Up @@ -534,10 +533,7 @@ describe('ExponentialHistogramAccumulation', () => {
describe('min max size', () => {
it('auto-corrects to min max', () => {
const acc: any = new ExponentialHistogramAccumulation([0, 0], 0);
assert.strictEqual(
acc['_maxSize'],
ExponentialHistogramAccumulation.MIN_MAX_SIZE
);
assert.strictEqual(acc['_maxSize'], 2);
});
});
});
Expand Down Expand Up @@ -783,14 +779,6 @@ function centerValue(mapper: Mapping, x: number): number {
return (lower + upper) / 2;
}

function getMapping(scale: number): Mapping {
if (scale <= 0) {
return ExponentMapping.get(scale);
} else {
return LogarithmMapping.get(scale);
}
}

function assertHistogramsEqual(
actual: ExponentialHistogramAccumulation,
expected: ExponentialHistogramAccumulation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,11 @@ export function assertInEpsilon(
`expected relative error: ${relErr} to be < ${epsilon}`
);
}

export function assertInDelta(actual: number, expected: number, delta: number) {
const actualDelta = Math.abs(expected - actual);
assert.ok(
actualDelta < delta,
`expected delta: ${delta} to be < ${actualDelta}`
);
}

0 comments on commit dcd4cd2

Please sign in to comment.