Skip to content

Add a fake agent for all profiler integration tests #5667

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 23 additions & 20 deletions integration-tests/profiler/profiler.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ class NetworkEventProcessor extends TimelineEventProcessor {
}
}

async function gatherNetworkTimelineEvents (cwd, scriptFilePath, eventType, args) {
return gatherTimelineEvents(cwd, scriptFilePath, eventType, args, NetworkEventProcessor)
async function gatherNetworkTimelineEvents (cwd, scriptFilePath, agentPort, eventType, args) {
return gatherTimelineEvents(cwd, scriptFilePath, agentPort, eventType, args, NetworkEventProcessor)
}

class FilesystemEventProcessor extends TimelineEventProcessor {
Expand Down Expand Up @@ -201,18 +201,19 @@ class FilesystemEventProcessor extends TimelineEventProcessor {
}
}

async function gatherFilesystemTimelineEvents (cwd, scriptFilePath) {
return gatherTimelineEvents(cwd, scriptFilePath, 'fs', [], FilesystemEventProcessor)
async function gatherFilesystemTimelineEvents (cwd, scriptFilePath, agentPort) {
return gatherTimelineEvents(cwd, scriptFilePath, agentPort, 'fs', [], FilesystemEventProcessor)
}

async function gatherTimelineEvents (cwd, scriptFilePath, eventType, args, Processor) {
async function gatherTimelineEvents (cwd, scriptFilePath, agentPort, eventType, args, Processor) {
const procStart = BigInt(Date.now() * 1000000)
const proc = fork(path.join(cwd, scriptFilePath), args, {
cwd,
env: {
DD_PROFILING_EXPORTERS: 'file',
DD_PROFILING_ENABLED: 1,
DD_INTERNAL_PROFILING_TIMELINE_SAMPLING_ENABLED: 0 // capture all events
DD_INTERNAL_PROFILING_TIMELINE_SAMPLING_ENABLED: 0, // capture all events
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also disable remote config with DD_REMOTE_CONFIGURATION_ENABLED: 0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did, and that alone didn't help. Something else (maybe trace result posting) is still keeping the process alive for about 25-30 seconds.

DD_TRACE_AGENT_PORT: agentPort
}
})

Expand Down Expand Up @@ -312,6 +313,14 @@ describe('profiler', () => {
await sandbox.remove()
})

beforeEach(async () => {
agent = await new FakeAgent().start()
})

afterEach(async () => {
await agent.stop()
})

if (process.platform !== 'win32') {
it('code hotspots and endpoint tracing works', async function () {
// see comment on busyCycleTimeNs recomputation below. Ideally a single retry should be enough
Expand All @@ -323,7 +332,8 @@ describe('profiler', () => {
env: {
DD_PROFILING_EXPORTERS: 'file',
DD_PROFILING_ENABLED: 1,
BUSY_CYCLE_TIME: (busyCycleTimeNs | 0).toString()
BUSY_CYCLE_TIME: (busyCycleTimeNs | 0).toString(),
DD_TRACE_AGENT_PORT: agent.port
}
})

Expand Down Expand Up @@ -440,7 +450,7 @@ describe('profiler', () => {
})

it('fs timeline events work', async () => {
const fsEvents = await gatherFilesystemTimelineEvents(cwd, 'profiler/fstest.js')
const fsEvents = await gatherFilesystemTimelineEvents(cwd, 'profiler/fstest.js', agent.port)
assert.equal(fsEvents.length, 6)
const path = fsEvents[0].path
const fd = fsEvents[1].fd
Expand All @@ -456,7 +466,7 @@ describe('profiler', () => {
})

it('dns timeline events work', async () => {
const dnsEvents = await gatherNetworkTimelineEvents(cwd, 'profiler/dnstest.js', 'dns')
const dnsEvents = await gatherNetworkTimelineEvents(cwd, 'profiler/dnstest.js', agent.port, 'dns')
assert.sameDeepMembers(dnsEvents, [
{ operation: 'lookup', host: 'example.org' },
{ operation: 'lookup', host: 'example.com' },
Expand Down Expand Up @@ -494,7 +504,7 @@ describe('profiler', () => {
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)
const events = await gatherNetworkTimelineEvents(cwd, 'profiler/nettest.js', agent.port, 'net', args)
// The profiled program should have two TCP connection events to the two
// servers.
assert.sameDeepMembers(events, [
Expand All @@ -511,8 +521,7 @@ describe('profiler', () => {
}

context('shutdown', () => {
beforeEach(async () => {
agent = await new FakeAgent().start()
beforeEach(() => {
oomEnv = {
DD_TRACE_AGENT_PORT: agent.port,
DD_PROFILING_ENABLED: 1,
Expand All @@ -521,9 +530,8 @@ describe('profiler', () => {
}
})

afterEach(async () => {
afterEach(() => {
proc.kill()
await agent.stop()
})

it('records profile on process exit', () => {
Expand Down Expand Up @@ -641,13 +649,8 @@ describe('profiler', () => {
})

context('SSI heuristics', () => {
beforeEach(async () => {
agent = await new FakeAgent().start()
})

afterEach(async () => {
afterEach(() => {
proc.kill()
await agent.stop()
})

describe('does not trigger for', () => {
Expand Down