Skip to content

Commit

Permalink
fix(gc): compute to zero nan values
Browse files Browse the repository at this point in the history
  • Loading branch information
dnlup committed Nov 2, 2023
1 parent 410bbf0 commit ebd33a0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 20 deletions.
4 changes: 2 additions & 2 deletions lib/gc.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class GCEntry {
}

get mean () {
return this[kHistogram].mean
return isNaN(this[kHistogram].mean) ? 0 : this[kHistogram].mean
}

get max () {
Expand All @@ -54,7 +54,7 @@ class GCEntry {
}

get stdDeviation () {
return this[kHistogram].stddev
return isNaN(this[kHistogram].stddev) ? 0 : this[kHistogram].stddev
}

getPercentile (percentile) {
Expand Down
22 changes: 4 additions & 18 deletions test/gc.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ test('garbage collection metric with aggregation', t => {
'weakCb'
]) {
const errorMessage = `Failed check for entry ${entry}`
t.ok(isNaN(gc[entry].mean), errorMessage)
t.equal(gc[entry].mean, 0, errorMessage)
t.equal(gc[entry].totalCount, 0, errorMessage)
t.ok(gc[entry].flags === undefined)
}
Expand Down Expand Up @@ -228,14 +228,7 @@ test('garbage collection metric with aggregation and flags', t => {
'totalDuration'
]) {
const errorMessage = `Failed check for ${entry}.flags.${flag}.${value}`
switch (value) {
case 'mean':
case 'stdDeviation':
t.ok(isNaN(gc.major.flags[flag][value]), errorMessage)
break
default:
t.ok(gc.major.flags[flag][value] === 0, errorMessage)
}
t.ok(gc.major.flags[flag][value] === 0, errorMessage)
}
}
}
Expand All @@ -258,7 +251,7 @@ test('garbage collection metric with aggregation and flags', t => {
'weakCb'
]) {
const errorMessage = `Failed check for entry ${entry}`
t.ok(isNaN(gc[entry].mean), errorMessage)
t.equal(gc[entry].mean, 0, errorMessage)
t.equal(gc[entry].totalCount, 0, errorMessage)
t.ok(gc.major.flags.no instanceof GCEntry)
t.equal(gc.major.flags.no.getPercentile(99), 0, errorMessage)
Expand All @@ -282,14 +275,7 @@ test('garbage collection metric with aggregation and flags', t => {
'totalDuration'
]) {
const errorMessage = `Failed check for ${entry}.flags.${flag}.${value}`
switch (value) {
case 'mean':
case 'stdDeviation':
t.ok(isNaN(gc.major.flags[flag][value]), errorMessage)
break
default:
t.ok(gc.major.flags[flag][value] === 0, errorMessage)
}
t.ok(gc.major.flags[flag][value] === 0, errorMessage)
}
}
}
Expand Down

0 comments on commit ebd33a0

Please sign in to comment.