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

feat: Add Exponential Histogram #3498

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
chore: linting
  • Loading branch information
mwear committed Dec 21, 2022
commit 44c38f24552c6cce534b020d45422d64967bf3b3
4 changes: 2 additions & 2 deletions packages/sdk-metrics/src/aggregator/ExponentialHistogram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export class ExponentialHistogramAccumulation implements Accumulation {
this.positive().clone(),
this.negative().clone(),
this._mapping,
)
);
}

/**
Expand Down Expand Up @@ -398,7 +398,7 @@ export class ExponentialHistogramAccumulation implements Accumulation {
}

private _minScale(other: ExponentialHistogramAccumulation):number {
let minScale = Math.min(this.scale(), other.scale());
const minScale = Math.min(this.scale(), other.scale());

const ourHighLowPos = this.highLowAtScale(this.positive(), minScale);
const otherHighLowPos = other.highLowAtScale(other.positive(), minScale);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class Buckets {
this.indexBase,
this.indexStart,
this.indexEnd,
)
);
}

length(): number {
Expand Down Expand Up @@ -87,7 +87,7 @@ export class Buckets {
* @param bucketIndex
* @param increment
*/
decrementBucket(bucketIndex: number, decrement: number) {
decrementBucket(bucketIndex: number, decrement: number) {
this.backing.decrement(bucketIndex, decrement);
}

Expand All @@ -103,19 +103,18 @@ export class Buckets {
*/
trim() {
for(let i = 0; i < this.length(); i++) {
if(this.at(i) !== 0) {
this.indexStart += i
break;
}
else if(i == this.length() - 1) {
//the entire array is zeroed out
this.indexStart = this.indexEnd = this.indexBase = 0;
return;
}
if(this.at(i) !== 0) {
this.indexStart += i;
break;
} else if(i === this.length() - 1) {
//the entire array is zeroed out
this.indexStart = this.indexEnd = this.indexBase = 0;
return;
}
}

for(let i = this.length() - 1; i >= 0; i--) {
console.log(i)
console.log(i);
if(this.at(i) !== 0 ) {
this.indexEnd -= this.length() - i - 1;
break;
Expand Down
26 changes: 13 additions & 13 deletions packages/sdk-metrics/test/aggregator/ExponentialHistogram.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ describe('ExponentialHistogramAccumulation', () => {
aHist.merge(bHist);

assertHistogramsEqual(aHist, cHist);
}
};

const factor = 1024.0;
const count = 16;
Expand All @@ -305,12 +305,12 @@ describe('ExponentialHistogramAccumulation', () => {
const sizes = [2, 6, 8, 9, 16];
const increments = [1, 0x100, 0x10000, 0x100000000];

for(let mean of means) {
for(let stddev of stddevs) {
for(const mean of means) {
for(const stddev of stddevs) {
const values = Array.from({length: count}, () => mean + Math.random() * stddev);
for(let part = 1; part < count; part++) {
for(let size of sizes) {
for (let incr of increments) {
for(const size of sizes) {
for (const incr of increments) {
testMergeExhaustive(values.slice(0, part), values.slice(part, count), size, incr);
}
}
Expand Down Expand Up @@ -354,11 +354,11 @@ describe('ExponentialHistogramAccumulation', () => {
for(let i = 0; i < 4; i++) {
const v1 = 2 << i;

if( i % 2 == 0) {
if( i % 2 === 0) {
acc0.record(v1);
}

if( i % 2 == 1 ) {
if( i % 2 === 1 ) {
acc1.record(v1);
}

Expand Down Expand Up @@ -390,11 +390,11 @@ describe('ExponentialHistogramAccumulation', () => {
for(let i = 0; i < 4; i++) {
const v1 = 2 << i;

if( i % 2 == 1 ) {
if( i % 2 === 1 ) {
acc0.record(v1);
}

if( i % 2 == 0) {
if( i % 2 === 0) {
acc1.record(v1);
}

Expand Down Expand Up @@ -451,9 +451,9 @@ describe('ExponentialHistogramAccumulation', () => {
const acc1 = new ExponentialHistogramAccumulation([0, 0], 4);

for(let i = 0; i < 4; i++) {
const v = 2 << i
const v = 2 << i;
acc0.record(v);
acc1.record(v)
acc1.record(v);
}

assertHistogramsEqual(acc0, acc1);
Expand All @@ -471,7 +471,7 @@ describe('ExponentialHistogramAccumulation', () => {
assert.notDeepStrictEqual(getCounts(acc0.positive()), getCounts(acc2.positive()));

// ensure acc0 wasn't mutated
assertHistogramsEqual(acc0, acc1)
assertHistogramsEqual(acc0, acc1);
});
});

Expand All @@ -483,7 +483,7 @@ describe('ExponentialHistogramAccumulation', () => {
acc.record(2 << i);
}

const pv = acc.toPointValue()
const pv = acc.toPointValue();

assert.strictEqual(pv.scale, acc.scale());
assert.strictEqual(pv.min, acc.min());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ export function assertInDelta(
actualDelta < delta,
`expected delta: ${delta} to be < ${actualDelta}`
);
}
}