Skip to content
Merged
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
fixup!
  • Loading branch information
legendecas committed Mar 15, 2022
commit 29d81d78423ff222279595f4fa4e02160968c766
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class HistogramAccumulation implements Accumulation {
this._current.buckets.counts[this._boundaries.length] += 1;
}

toPoint(): Histogram {
toPointValue(): Histogram {
return this._current;
}
}
Expand Down Expand Up @@ -89,66 +89,66 @@ export class HistogramAggregator implements Aggregator<HistogramAccumulation> {
* merging accumulations with different boundaries.
*/
merge(previous: HistogramAccumulation, delta: HistogramAccumulation): HistogramAccumulation {
const previousPoint = previous.toPoint();
const deltaPoint = delta.toPoint();
const previousValue = previous.toPointValue();
const deltaValue = delta.toPointValue();

const previousCounts = previousPoint.buckets.counts;
const deltaCounts = deltaPoint.buckets.counts;
const previousCounts = previousValue.buckets.counts;
const deltaCounts = deltaValue.buckets.counts;

const mergedCounts = new Array(previousCounts.length);
for (let idx = 0; idx < previousCounts.length; idx++) {
mergedCounts[idx] = previousCounts[idx] + deltaCounts[idx];
}

return new HistogramAccumulation(previousPoint.buckets.boundaries, {
return new HistogramAccumulation(previousValue.buckets.boundaries, {
buckets: {
boundaries: previousPoint.buckets.boundaries,
boundaries: previousValue.buckets.boundaries,
counts: mergedCounts,
},
count: previousPoint.count + deltaPoint.count,
sum: previousPoint.sum + deltaPoint.sum,
count: previousValue.count + deltaValue.count,
sum: previousValue.sum + deltaValue.sum,
});
}

/**
* Returns a new DELTA aggregation by comparing two cumulative measurements.
*/
diff(previous: HistogramAccumulation, current: HistogramAccumulation): HistogramAccumulation {
const previousPoint = previous.toPoint();
const currentPoint = current.toPoint();
const previousValue = previous.toPointValue();
const currentValue = current.toPointValue();

const previousCounts = previousPoint.buckets.counts;
const currentCounts = currentPoint.buckets.counts;
const previousCounts = previousValue.buckets.counts;
const currentCounts = currentValue.buckets.counts;

const diffedCounts = new Array(previousCounts.length);
for (let idx = 0; idx < previousCounts.length; idx++) {
diffedCounts[idx] = currentCounts[idx] - previousCounts[idx];
}

return new HistogramAccumulation(previousPoint.buckets.boundaries, {
return new HistogramAccumulation(previousValue.buckets.boundaries, {
buckets: {
boundaries: previousPoint.buckets.boundaries,
boundaries: previousValue.buckets.boundaries,
counts: diffedCounts,
},
count: currentPoint.count - previousPoint.count,
sum: currentPoint.sum - previousPoint.sum,
count: currentValue.count - previousValue.count,
sum: currentValue.sum - previousValue.sum,
});
}

toMetricData(
metricDescriptor: InstrumentDescriptor,
descriptor: InstrumentDescriptor,
accumulationByAttributes: AccumulationRecord<HistogramAccumulation>[],
startTime: HrTime,
endTime: HrTime): Maybe<HistogramMetricData> {
return {
descriptor: metricDescriptor,
descriptor,
dataPointType: DataPointType.HISTOGRAM,
dataPoints: accumulationByAttributes.map(([attributes, accumulation]) => {
return {
attributes,
startTime,
endTime,
value: accumulation.toPoint(),
value: accumulation.toPointValue(),
};
})
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class LastValueAccumulation implements Accumulation {
this.sampleTime = hrTime();
}

toPoint(): LastValue {
toPointValue(): LastValue {
return this._current;
}
}
Expand All @@ -50,7 +50,7 @@ export class LastValueAggregator implements Aggregator<LastValueAccumulation> {
merge(previous: LastValueAccumulation, delta: LastValueAccumulation): LastValueAccumulation {
// nanoseconds may lose precisions.
const latestAccumulation = hrTimeToMicroseconds(delta.sampleTime) >= hrTimeToMicroseconds(previous.sampleTime) ? delta : previous;
return new LastValueAccumulation(latestAccumulation.toPoint(), latestAccumulation.sampleTime);
return new LastValueAccumulation(latestAccumulation.toPointValue(), latestAccumulation.sampleTime);
}

/**
Expand All @@ -62,7 +62,7 @@ export class LastValueAggregator implements Aggregator<LastValueAccumulation> {
diff(previous: LastValueAccumulation, current: LastValueAccumulation): LastValueAccumulation {
// nanoseconds may lose precisions.
const latestAccumulation = hrTimeToMicroseconds(current.sampleTime) >= hrTimeToMicroseconds(previous.sampleTime) ? current : previous;
return new LastValueAccumulation(latestAccumulation.toPoint(), latestAccumulation.sampleTime);
return new LastValueAccumulation(latestAccumulation.toPointValue(), latestAccumulation.sampleTime);
}

toMetricData(
Expand All @@ -78,7 +78,7 @@ export class LastValueAggregator implements Aggregator<LastValueAccumulation> {
attributes,
startTime,
endTime,
value: accumulation.toPoint(),
value: accumulation.toPointValue(),
};
})
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class SumAccumulation implements Accumulation {
this._current += value;
}

toPoint(): Sum {
toPointValue(): Sum {
return this._current;
}
}
Expand All @@ -44,14 +44,14 @@ export class SumAggregator implements Aggregator<SumAccumulation> {
* Returns the result of the merge of the given accumulations.
*/
merge(previous: SumAccumulation, delta: SumAccumulation): SumAccumulation {
return new SumAccumulation(previous.toPoint() + delta.toPoint());
return new SumAccumulation(previous.toPointValue() + delta.toPointValue());
}

/**
* Returns a new DELTA aggregation by comparing two cumulative measurements.
*/
diff(previous: SumAccumulation, current: SumAccumulation): SumAccumulation {
return new SumAccumulation(current.toPoint() - previous.toPoint());
return new SumAccumulation(current.toPointValue() - previous.toPointValue());
}

toMetricData(
Expand All @@ -67,7 +67,7 @@ export class SumAggregator implements Aggregator<SumAccumulation> {
attributes,
startTime,
endTime,
value: accumulation.toPoint(),
value: accumulation.toPointValue(),
};
})
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ export enum AggregatorKind {
HISTOGRAM,
}

/** Point type for SumAggregation. */
/** DataPoint value type for SumAggregation. */
export type Sum = number;

/** Point type for LastValueAggregation. */
/** DataPoint value type for LastValueAggregation. */
export type LastValue = number;

/** Point type for HistogramAggregation. */
/** DataPoint value type for HistogramAggregation. */
export interface Histogram {
/**
* Buckets are implemented using two different arrays:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe('DeltaMetricProcessor', () => {
metricProcessor.batchCumulate(measurements);
const accumulations = metricProcessor.collect();
const accumulation = accumulations.get({});
assert.strictEqual(accumulation?.toPoint(), 10);
assert.strictEqual(accumulation?.toPointValue(), 10);
}

{
Expand All @@ -87,7 +87,7 @@ describe('DeltaMetricProcessor', () => {
metricProcessor.batchCumulate(measurements);
const accumulations = metricProcessor.collect();
const accumulation = accumulations.get({});
assert.strictEqual(accumulation?.toPoint(), 11);
assert.strictEqual(accumulation?.toPointValue(), 11);
}
});
});
Expand All @@ -104,11 +104,11 @@ describe('DeltaMetricProcessor', () => {
assert.strictEqual(accumulations.size, 2);
{
const accumulation = accumulations.get({ attribute: '1' });
assert.strictEqual(accumulation?.toPoint(), 3);
assert.strictEqual(accumulation?.toPointValue(), 3);
}
{
const accumulation = accumulations.get({ attribute: '2' });
assert.strictEqual(accumulation?.toPoint(), 1);
assert.strictEqual(accumulation?.toPointValue(), 1);
}

/** the accumulations shall be reset. */
Expand Down