Skip to content

Commit

Permalink
fixup!
Browse files Browse the repository at this point in the history
  • Loading branch information
legendecas committed Jun 28, 2022
1 parent 12d3ab8 commit 40d19c3
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@ export class SumAggregator implements Aggregator<SumAccumulation> {
* Returns the result of the merge of the given accumulations.
*/
merge(previous: SumAccumulation, delta: SumAccumulation): SumAccumulation {
const prevPv = previous.toPointValue();
const deltaPv = delta.toPointValue();
if (delta.reset) {
return new SumAccumulation(delta.startTime, this.monotonic, delta.toPointValue(), delta.reset);
return new SumAccumulation(delta.startTime, this.monotonic, deltaPv, delta.reset);
}
return new SumAccumulation(previous.startTime, this.monotonic, previous.toPointValue() + delta.toPointValue());
return new SumAccumulation(previous.startTime, this.monotonic, prevPv + deltaPv);
}

/**
Expand All @@ -74,7 +76,7 @@ export class SumAggregator implements Aggregator<SumAccumulation> {
if (this.monotonic && (prevPv > currPv)) {
return new SumAccumulation(current.startTime, this.monotonic, currPv, true);
}
return new SumAccumulation(current.startTime, this.monotonic, current.toPointValue() - previous.toPointValue());
return new SumAccumulation(current.startTime, this.monotonic, currPv - prevPv);
}

toMetricData(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class DeltaMetricProcessor<T extends Maybe<Accumulation>> {
accumulation?.record(value);
let delta = accumulation;
if (this._cumulativeMemoStorage.has(attributes, hashCode)) {
// previous must present.
// has() returned true, previous is present.
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const previous = this._cumulativeMemoStorage.get(attributes, hashCode)!;
delta = this._aggregator.diff(previous, accumulation);
Expand All @@ -62,7 +62,7 @@ export class DeltaMetricProcessor<T extends Maybe<Accumulation>> {
}

/**
* Returns a collection of delta metrics. Their start time is the when first
* Returns a collection of delta metrics. Start time is the when first
* time event collected.
*/
collect() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export class TemporalMetricProcessor<T extends Maybe<Accumulation>> {
const [key, record, hash] = next.value;
if (last.has(key, hash)) {
const lastAccumulation = last.get(key, hash);
// lastAccumulation must present.
// last.has() returned true, lastAccumulation is present.
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const accumulation = aggregator.merge(lastAccumulation!, record);
result.set(key, accumulation, hash);
Expand All @@ -167,20 +167,13 @@ export class TemporalMetricProcessor<T extends Maybe<Accumulation>> {
}

/**
* Calibrate the reported metric streams's startTime to lastCollectionTime. Leaves
* Calibrate the reported metric streams' startTime to lastCollectionTime. Leaves
* the new stream to be the initial observation time unchanged.
*/
static calibrateStartTime<T extends Maybe<Accumulation>>(last: AttributeHashMap<T>, current: AttributeHashMap<T>, lastCollectionTime: HrTime) {
const iterator = last.keys();
let next = iterator.next();
while (next.done !== true) {
const [key, hash] = next.value;
if (current.has(key, hash)) {
const currentAccumulation = current.get(key, hash);
currentAccumulation?.setStartTime(lastCollectionTime);
}

next = iterator.next();
for (const [key, hash] of last.keys()) {
const currentAccumulation = current.get(key, hash);
currentAccumulation?.setStartTime(lastCollectionTime);
}
return current;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe('SumAggregator', () => {
const prev = aggregator.createAccumulation([0, 0]);
prev.record(10);

// A new record with the value been reset.
// Create a new record that indicates a reset.
const curr = aggregator.createAccumulation([1, 1]);
curr.record(3);

Expand Down

0 comments on commit 40d19c3

Please sign in to comment.