Skip to content

Commit

Permalink
fix runtime metrics test not waiting for gc observer to run (#5039)
Browse files Browse the repository at this point in the history
  • Loading branch information
rochdev committed Dec 18, 2024
1 parent 472b1a4 commit ddb1e6e
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 63 deletions.
2 changes: 1 addition & 1 deletion packages/dd-trace/src/runtime_metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ function startGCObserver () {

gcObserver = new PerformanceObserver(list => {
for (const entry of list.getEntries()) {
const type = gcType(entry.kind)
const type = gcType(entry.detail?.kind || entry.kind)

console.log(entry, type)

Check failure on line 368 in packages/dd-trace/src/runtime_metrics.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

Expand Down
130 changes: 68 additions & 62 deletions packages/dd-trace/test/runtime_metrics.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ suiteDescribe('runtimeMetrics', () => {
let runtimeMetrics
let config
let clock
let setImmediate
let client
let Client

Expand Down Expand Up @@ -50,6 +51,7 @@ suiteDescribe('runtimeMetrics', () => {
}
}

setImmediate = globalThis.setImmediate
clock = sinon.useFakeTimers()

runtimeMetrics.start(config)
Expand Down Expand Up @@ -97,69 +99,73 @@ suiteDescribe('runtimeMetrics', () => {

global.gc()

clock.tick(10000)

setImmediate(() => {
expect(client.gauge).to.have.been.calledWith('runtime.node.cpu.user')
expect(client.gauge).to.have.been.calledWith('runtime.node.cpu.system')
expect(client.gauge).to.have.been.calledWith('runtime.node.cpu.total')

expect(client.gauge).to.have.been.calledWith('runtime.node.mem.rss')
expect(client.gauge).to.have.been.calledWith('runtime.node.mem.heap_total')
expect(client.gauge).to.have.been.calledWith('runtime.node.mem.heap_used')

expect(client.gauge).to.have.been.calledWith('runtime.node.process.uptime')

expect(client.gauge).to.have.been.calledWith('runtime.node.heap.total_heap_size')
expect(client.gauge).to.have.been.calledWith('runtime.node.heap.total_heap_size_executable')
expect(client.gauge).to.have.been.calledWith('runtime.node.heap.total_physical_size')
expect(client.gauge).to.have.been.calledWith('runtime.node.heap.total_available_size')
expect(client.gauge).to.have.been.calledWith('runtime.node.heap.total_heap_size')
expect(client.gauge).to.have.been.calledWith('runtime.node.heap.heap_size_limit')

expect(client.gauge).to.have.been.calledWith('runtime.node.heap.malloced_memory')
expect(client.gauge).to.have.been.calledWith('runtime.node.heap.peak_malloced_memory')

expect(client.gauge).to.have.been.calledWith('runtime.node.event_loop.delay.max')
expect(client.gauge).to.have.been.calledWith('runtime.node.event_loop.delay.min')
expect(client.increment).to.have.been.calledWith('runtime.node.event_loop.delay.sum')
expect(client.gauge).to.have.been.calledWith('runtime.node.event_loop.delay.avg')
expect(client.gauge).to.have.been.calledWith('runtime.node.event_loop.delay.median')
expect(client.gauge).to.have.been.calledWith('runtime.node.event_loop.delay.95percentile')
expect(client.increment).to.have.been.calledWith('runtime.node.event_loop.delay.count')

expect(client.gauge).to.have.been.calledWith('runtime.node.event_loop.utilization')

expect(client.gauge).to.have.been.calledWith('runtime.node.gc.pause.max')
expect(client.gauge).to.have.been.calledWith('runtime.node.gc.pause.min')
expect(client.increment).to.have.been.calledWith('runtime.node.gc.pause.sum')
expect(client.gauge).to.have.been.calledWith('runtime.node.gc.pause.avg')
expect(client.gauge).to.have.been.calledWith('runtime.node.gc.pause.median')
expect(client.gauge).to.have.been.calledWith('runtime.node.gc.pause.95percentile')
expect(client.increment).to.have.been.calledWith('runtime.node.gc.pause.count')

expect(client.gauge).to.have.been.calledWith('runtime.node.gc.pause.by.type.max')
expect(client.gauge).to.have.been.calledWith('runtime.node.gc.pause.by.type.min')
expect(client.increment).to.have.been.calledWith('runtime.node.gc.pause.by.type.sum')
expect(client.gauge).to.have.been.calledWith('runtime.node.gc.pause.by.type.avg')
expect(client.gauge).to.have.been.calledWith('runtime.node.gc.pause.by.type.median')
expect(client.gauge).to.have.been.calledWith('runtime.node.gc.pause.by.type.95percentile')
expect(client.increment).to.have.been.calledWith('runtime.node.gc.pause.by.type.count')
expect(client.increment).to.have.been.calledWith(
'runtime.node.gc.pause.by.type.count', sinon.match.any, sinon.match(val => {
return val && /^gc_type:[a-z_]+$/.test(val[0])
})
)

expect(client.gauge).to.have.been.calledWith('runtime.node.heap.size.by.space')
expect(client.gauge).to.have.been.calledWith('runtime.node.heap.used_size.by.space')
expect(client.gauge).to.have.been.calledWith('runtime.node.heap.available_size.by.space')
expect(client.gauge).to.have.been.calledWith('runtime.node.heap.physical_size.by.space')

expect(client.flush).to.have.been.called
setImmediate(() => setImmediate(() => { // Wait for GC observer to trigger.
clock.tick(10000)

done()
})
try {
expect(client.gauge).to.have.been.calledWith('runtime.node.cpu.user')
expect(client.gauge).to.have.been.calledWith('runtime.node.cpu.system')
expect(client.gauge).to.have.been.calledWith('runtime.node.cpu.total')

expect(client.gauge).to.have.been.calledWith('runtime.node.mem.rss')
expect(client.gauge).to.have.been.calledWith('runtime.node.mem.heap_total')
expect(client.gauge).to.have.been.calledWith('runtime.node.mem.heap_used')

expect(client.gauge).to.have.been.calledWith('runtime.node.process.uptime')

expect(client.gauge).to.have.been.calledWith('runtime.node.heap.total_heap_size')
expect(client.gauge).to.have.been.calledWith('runtime.node.heap.total_heap_size_executable')
expect(client.gauge).to.have.been.calledWith('runtime.node.heap.total_physical_size')
expect(client.gauge).to.have.been.calledWith('runtime.node.heap.total_available_size')
expect(client.gauge).to.have.been.calledWith('runtime.node.heap.total_heap_size')
expect(client.gauge).to.have.been.calledWith('runtime.node.heap.heap_size_limit')

expect(client.gauge).to.have.been.calledWith('runtime.node.heap.malloced_memory')
expect(client.gauge).to.have.been.calledWith('runtime.node.heap.peak_malloced_memory')

expect(client.gauge).to.have.been.calledWith('runtime.node.event_loop.delay.max')
expect(client.gauge).to.have.been.calledWith('runtime.node.event_loop.delay.min')
expect(client.increment).to.have.been.calledWith('runtime.node.event_loop.delay.sum')
expect(client.gauge).to.have.been.calledWith('runtime.node.event_loop.delay.avg')
expect(client.gauge).to.have.been.calledWith('runtime.node.event_loop.delay.median')
expect(client.gauge).to.have.been.calledWith('runtime.node.event_loop.delay.95percentile')
expect(client.increment).to.have.been.calledWith('runtime.node.event_loop.delay.count')

expect(client.gauge).to.have.been.calledWith('runtime.node.event_loop.utilization')

expect(client.gauge).to.have.been.calledWith('runtime.node.gc.pause.max')
expect(client.gauge).to.have.been.calledWith('runtime.node.gc.pause.min')
expect(client.increment).to.have.been.calledWith('runtime.node.gc.pause.sum')
expect(client.gauge).to.have.been.calledWith('runtime.node.gc.pause.avg')
expect(client.gauge).to.have.been.calledWith('runtime.node.gc.pause.median')
expect(client.gauge).to.have.been.calledWith('runtime.node.gc.pause.95percentile')
expect(client.increment).to.have.been.calledWith('runtime.node.gc.pause.count')

expect(client.gauge).to.have.been.calledWith('runtime.node.gc.pause.by.type.max')
expect(client.gauge).to.have.been.calledWith('runtime.node.gc.pause.by.type.min')
expect(client.increment).to.have.been.calledWith('runtime.node.gc.pause.by.type.sum')
expect(client.gauge).to.have.been.calledWith('runtime.node.gc.pause.by.type.avg')
expect(client.gauge).to.have.been.calledWith('runtime.node.gc.pause.by.type.median')
expect(client.gauge).to.have.been.calledWith('runtime.node.gc.pause.by.type.95percentile')
expect(client.increment).to.have.been.calledWith('runtime.node.gc.pause.by.type.count')
expect(client.increment).to.have.been.calledWith(
'runtime.node.gc.pause.by.type.count', sinon.match.any, sinon.match(val => {
return val && /^gc_type:[a-z_]+$/.test(val[0])
})
)

expect(client.gauge).to.have.been.calledWith('runtime.node.heap.size.by.space')
expect(client.gauge).to.have.been.calledWith('runtime.node.heap.used_size.by.space')
expect(client.gauge).to.have.been.calledWith('runtime.node.heap.available_size.by.space')
expect(client.gauge).to.have.been.calledWith('runtime.node.heap.physical_size.by.space')

expect(client.flush).to.have.been.called

done()
} catch (e) {
done(e)
}
}))
})
})

Expand Down

0 comments on commit ddb1e6e

Please sign in to comment.