Skip to content

Commit

Permalink
Profiling code to presume at least Node 16 (#4335)
Browse files Browse the repository at this point in the history
  • Loading branch information
szegedi authored Nov 4, 2024
1 parent 6c1c075 commit 83fcef6
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 55 deletions.
97 changes: 47 additions & 50 deletions integration-tests/profiler/profiler.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const fsync = require('fs')
const net = require('net')
const zlib = require('zlib')
const { Profile } = require('pprof-format')
const semver = require('semver')

const DEFAULT_PROFILE_TYPES = ['wall', 'space']
if (process.platform !== 'win32') {
Expand Down Expand Up @@ -315,61 +314,59 @@ describe('profiler', () => {
assert.equal(endpoints.size, 3, encoded)
})

if (semver.gte(process.version, '16.0.0')) {
it('dns timeline events work', async () => {
const dnsEvents = await gatherNetworkTimelineEvents(cwd, 'profiler/dnstest.js', 'dns')
assert.sameDeepMembers(dnsEvents, [
{ name: 'lookup', host: 'example.org' },
{ name: 'lookup', host: 'example.com' },
{ name: 'lookup', host: 'datadoghq.com' },
{ name: 'queryA', host: 'datadoghq.com' },
{ name: 'lookupService', address: '13.224.103.60', port: 80 }
])
})
it('dns timeline events work', async () => {
const dnsEvents = await gatherNetworkTimelineEvents(cwd, 'profiler/dnstest.js', 'dns')
assert.sameDeepMembers(dnsEvents, [
{ name: 'lookup', host: 'example.org' },
{ name: 'lookup', host: 'example.com' },
{ name: 'lookup', host: 'datadoghq.com' },
{ name: 'queryA', host: 'datadoghq.com' },
{ name: 'lookupService', address: '13.224.103.60', port: 80 }
])
})

it('net timeline events work', async () => {
// Simple server that writes a constant message to the socket.
const msg = 'cya later!\n'
function createServer () {
const server = net.createServer((socket) => {
socket.end(msg, 'utf8')
}).on('error', (err) => {
throw err
})
return server
}
// Create two instances of the server
const server1 = createServer()
it('net timeline events work', async () => {
// Simple server that writes a constant message to the socket.
const msg = 'cya later!\n'
function createServer () {
const server = net.createServer((socket) => {
socket.end(msg, 'utf8')
}).on('error', (err) => {
throw err
})
return server
}
// Create two instances of the server
const server1 = createServer()
try {
const server2 = createServer()
try {
const server2 = createServer()
try {
// Have the servers listen on ephemeral ports
const p = new Promise(resolve => {
server1.listen(0, () => {
server2.listen(0, async () => {
resolve([server1.address().port, server2.address().port])
})
// Have the servers listen on ephemeral ports
const p = new Promise(resolve => {
server1.listen(0, () => {
server2.listen(0, async () => {
resolve([server1.address().port, server2.address().port])
})
})
const [port1, port2] = await p
const args = [String(port1), String(port2), msg]
// Invoke the profiled program, passing it the ports of the servers and
// the expected message.
const events = await gatherNetworkTimelineEvents(cwd, 'profiler/nettest.js', 'net', args)
// The profiled program should have two TCP connection events to the two
// servers.
assert.sameDeepMembers(events, [
{ name: 'connect', host: '127.0.0.1', port: port1 },
{ name: 'connect', host: '127.0.0.1', port: port2 }
])
} finally {
server2.close()
}
})
const [port1, port2] = await p
const args = [String(port1), String(port2), msg]
// Invoke the profiled program, passing it the ports of the servers and
// the expected message.
const events = await gatherNetworkTimelineEvents(cwd, 'profiler/nettest.js', 'net', args)
// The profiled program should have two TCP connection events to the two
// servers.
assert.sameDeepMembers(events, [
{ name: 'connect', host: '127.0.0.1', port: port1 },
{ name: 'connect', host: '127.0.0.1', port: port2 }
])
} finally {
server1.close()
server2.close()
}
})
}
} finally {
server1.close()
}
})
}

context('shutdown', () => {
Expand Down
5 changes: 0 additions & 5 deletions packages/dd-trace/test/profiling/exporters/agent.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const WallProfiler = require('../../../src/profiling/profilers/wall')
const SpaceProfiler = require('../../../src/profiling/profilers/space')
const logger = require('../../../src/log')
const { Profile } = require('pprof-format')
const semver = require('semver')
const version = require('../../../../../package.json').version

const RUNTIME_ID = 'a1b2c3d4-a1b2-a1b2-a1b2-a1b2c3d4e5f6'
Expand All @@ -26,10 +25,6 @@ const HOST = 'test-host'
const SERVICE = 'test-service'
const APP_VERSION = '1.2.3'

if (!semver.satisfies(process.version, '>=10.12')) {
describe = describe.skip // eslint-disable-line no-global-assign
}

function wait (ms) {
return new Promise((resolve, reject) => {
setTimeout(resolve, ms)
Expand Down

0 comments on commit 83fcef6

Please sign in to comment.