Skip to content
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

PROF-9791: Recognize DD_PROFILING_ENABLED=auto as an alternative for SSI profiling #4375

Merged
merged 2 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
60 changes: 36 additions & 24 deletions integration-tests/profiler/profiler.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -500,53 +500,65 @@ describe('profiler', () => {

describe('does not trigger for', () => {
it('a short-lived app that creates no spans', () => {
return heuristicsDoesNotTriggerFor([], false)
return heuristicsDoesNotTriggerFor([], false, false)
})

it('a short-lived app that creates a span', () => {
return heuristicsDoesNotTriggerFor(['create-span'], true)
return heuristicsDoesNotTriggerFor(['create-span'], true, false)
})

it('a long-lived app that creates no spans', () => {
return heuristicsDoesNotTriggerFor(['long-lived'], false)
return heuristicsDoesNotTriggerFor(['long-lived'], false, false)
})

it('a short-lived app that creates no spans with the auto env var', () => {
return heuristicsDoesNotTriggerFor([], false, true)
})

it('a short-lived app that creates a span with the auto env var', () => {
return heuristicsDoesNotTriggerFor(['create-span'], true, true)
})

it('a long-lived app that creates no spans with the auto env var', () => {
return heuristicsDoesNotTriggerFor(['long-lived'], false, true)
})
})

it('triggers for long-lived span-creating app', () => {
return checkProfiles(agent,
forkSsi(['create-span', 'long-lived']),
timeout,
DEFAULT_PROFILE_TYPES,
false,
// Will receive 2 messages: first one is for the trace, second one is for the profile. We
// only need the assertions in checkProfiles to succeed for the one with the profile.
2)
return heuristicsTrigger(false)
})

it('triggers for long-lived span-creating app with the auto env var', () => {
return heuristicsTrigger(true)
})
})

function forkSsi (args) {
function forkSsi (args, whichEnv) {
const profilerEnablingEnv = whichEnv ? { DD_PROFILING_ENABLED: 'auto' } : { DD_INJECTION_ENABLED: 'profiler' }
return fork(ssiTestFile, args, {
cwd,
env: {
DD_TRACE_AGENT_PORT: agent.port,
DD_INJECTION_ENABLED: 'profiler',
DD_INTERNAL_PROFILING_LONG_LIVED_THRESHOLD: '1300'
DD_INTERNAL_PROFILING_LONG_LIVED_THRESHOLD: '1300',
...profilerEnablingEnv
}
})
}

function heuristicsDoesNotTriggerFor (args, allowTraceMessage) {
proc = fork(ssiTestFile, args, {
cwd,
env: {
DD_TRACE_AGENT_PORT: agent.port,
DD_INJECTION_ENABLED: 'profiler',
DD_INTERNAL_PROFILING_LONG_LIVED_THRESHOLD: '1300'
}
})
function heuristicsTrigger (whichEnv) {
return checkProfiles(agent,
forkSsi(['create-span', 'long-lived'], whichEnv),
timeout,
DEFAULT_PROFILE_TYPES,
false,
// Will receive 2 messages: first one is for the trace, second one is for the profile. We
// only need the assertions in checkProfiles to succeed for the one with the profile.
2)
}

function heuristicsDoesNotTriggerFor (args, allowTraceMessage, whichEnv) {
return Promise.all([
processExitPromise(proc, timeout, false),
processExitPromise(forkSsi(args, whichEnv), timeout, false),
expectTimeout(expectProfileMessagePromise(agent, 1500), allowTraceMessage)
])
}
Expand Down
4 changes: 2 additions & 2 deletions packages/dd-trace/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -664,9 +664,9 @@ class Config {
this._setBoolean(env, 'profiling.enabled', coalesce(DD_EXPERIMENTAL_PROFILING_ENABLED, DD_PROFILING_ENABLED))
this._setString(env, 'profiling.exporters', DD_PROFILING_EXPORTERS)
this._setBoolean(env, 'profiling.sourceMap', DD_PROFILING_SOURCE_MAP && !isFalse(DD_PROFILING_SOURCE_MAP))
if (DD_INJECTION_ENABLED) {
if (DD_PROFILING_ENABLED === 'auto' || DD_INJECTION_ENABLED) {
this._setBoolean(env, 'profiling.ssi', true)
if (DD_INJECTION_ENABLED.split(',').includes('profiler')) {
if (DD_PROFILING_ENABLED === 'auto' || DD_INJECTION_ENABLED.split(',').includes('profiler')) {
Copy link
Collaborator

@nsavoire nsavoire Jun 5, 2024

Choose a reason for hiding this comment

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

Is it profiler or profiling that must be present in DD_INJECTION_ENABLED ?
There is a profiling here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is 'profiler'. 'profiling' was a bug on my part. I can quickly fix it in this PR.

this._setBoolean(env, 'profiling.heuristicsEnabled', true)
}
if (DD_INTERNAL_PROFILING_LONG_LIVED_THRESHOLD) {
Expand Down
Loading