Skip to content

Commit a5cf5d3

Browse files
authored
chore: reduce runtime metric flakiness and remove type warnings (#6867)
The runtime metric uptime check could in about 1 out of 1000 times end up with a wrong number due to a millisecond too much being used in the test. In addition, the bigint type was corrected. It had no negative impact due to being reassigned to number before being used. Further drive-by fix is to reduce type warnings where the type is either difficult to define or unknown. Also activate the tests for non-native on windows. Those may run since these will only use Node.js own methods.
1 parent 51b35cf commit a5cf5d3

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

packages/dd-trace/src/runtime_metrics/runtime_metrics.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ let nativeMetrics = null
2222
let gcObserver = null
2323
let interval = null
2424
let client = null
25-
let lastTime = 0n
25+
let lastTime = 0
2626
let lastCpuUsage = null
2727
let eventLoopDelayObserver = null
2828

@@ -103,7 +103,6 @@ module.exports = {
103103
interval = null
104104

105105
client = null
106-
lastTime = 0n
107106
lastCpuUsage = null
108107

109108
gcObserver?.disconnect()
@@ -339,6 +338,7 @@ function startGCObserver () {
339338

340339
gcObserver = new PerformanceObserver(list => {
341340
for (const entry of list.getEntries()) {
341+
// @ts-expect-error - entry.detail?.kind and entry.kind are not typed
342342
const type = gcType(entry.detail?.kind || entry.kind)
343343
const duration = entry.duration * 1_000_000
344344

packages/dd-trace/test/runtime_metrics.spec.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ function createGarbage (count = 50) {
2323

2424
for (let i = 0; i < count; i++) {
2525
last.next = { circular: obj, last, obj: { a: 1, b: 2, c: true } }
26+
// @ts-expect-error - Difficult to define type
2627
last = last.next
28+
// @ts-expect-error - Difficult to define type
2729
last.map = new Map([['a', 1], ['b', 2], ['c', true]])
2830
obj[i] = last
2931
}
@@ -133,7 +135,7 @@ function createGarbage (count = 50) {
133135
expect(runtimeMetrics.decrement).to.not.have.been.called
134136
expect(runtimeMetrics.stop).to.have.been.calledOnce
135137
})
136-
}, { skip: isWindows })
138+
}, { skip: isWindows && !nativeMetrics })
137139

138140
describe('runtimeMetrics', () => {
139141
let runtimeMetrics
@@ -260,7 +262,7 @@ function createGarbage (count = 50) {
260262

261263
// Wait for GC observer to trigger.
262264
const startTime = Date.now()
263-
const waitTime = 200
265+
const waitTime = 200 + (nativeMetrics ? 0 : 200)
264266
let iterations = 0
265267
while (Date.now() - startTime < waitTime) {
266268
// Need ticks for the event loop delay
@@ -582,7 +584,7 @@ function createGarbage (count = 50) {
582584
)
583585
client.gauge.resetHistory()
584586

585-
const nowStub3 = sinon.stub(performance, 'now').returns(startPerformanceNow + 20_001)
587+
const nowStub3 = sinon.stub(performance, 'now').returns(startPerformanceNow + 20_000)
586588
clock.tick(10000) // Advance another 10 seconds
587589
nowStub3.restore()
588590

@@ -782,6 +784,6 @@ function createGarbage (count = 50) {
782784
})
783785
})
784786
})
785-
}, { skip: isWindows })
787+
}, { skip: isWindows && !nativeMetrics })
786788
})
787789
})

0 commit comments

Comments
 (0)