Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
szegedi committed Oct 31, 2024
1 parent 67e4ef2 commit 629fda4
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
3 changes: 2 additions & 1 deletion integration-tests/profiler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ function busyWait (ms) {
})
}

setImmediate(async () => busyWait(500))
const durationMs = Number.parseInt(process.env.TEST_DURATION_MS ?? '500')
setImmediate(async () => busyWait(durationMs))
65 changes: 65 additions & 0 deletions integration-tests/profiler/profiler.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,71 @@ describe('profiler', () => {
})
})

context('Profiler API telemetry', () => {
beforeEach(async () => {
agent = await new FakeAgent().start()
})

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

it('sends profiler API telemetry', () => {
proc = fork(profilerTestFile, {
cwd,
env: {
DD_TRACE_AGENT_PORT: agent.port,
DD_PROFILING_ENABLED: 1,
DD_PROFILING_UPLOAD_PERIOD: 1,
TEST_DURATION_MS: 2500
}
})

let requestCount = 0
let pointsCount = 0

const checkMetrics = agent.assertTelemetryReceived(({ _, payload }) => {
const pp = payload.payload
assert.equal(pp.namespace, 'profilers')
const series = pp.series
assert.lengthOf(series, 2)
assert.equal(series[0].metric, 'profile_api.requests')
assert.equal(series[0].type, 'count')
// There's a race between metrics and on-shutdown profile, so metric
// value will be between 2 and 3
assert.isAtLeast(series[0].points[0][1], 2)
assert.isAtMost(series[0].points[0][1], 3)

assert.equal(series[1].metric, 'profile_api.responses')
assert.equal(series[1].type, 'count')
assert.include(series[1].tags, 'status_code:200')

// Same number of requests and responses
requestCount = series[0].points[0][1]
assert.equal(series[1].points[0][1], requestCount)
}, timeout, 'generate-metrics')

const checkDistributions = agent.assertTelemetryReceived(({ _, payload }) => {
const pp = payload.payload
assert.equal(pp.namespace, 'profilers')
const series = pp.series
assert.lengthOf(series, 2)
assert.equal(series[0].metric, 'profile_api.bytes')
assert.equal(series[1].metric, 'profile_api.ms')

// Same number of points
pointsCount = series[0].points.length
assert.equal(pointsCount, series[1].points.length)
}, timeout, 'distributions')

return Promise.all([checkProfiles(agent, proc, timeout), checkMetrics, checkDistributions]).then(() => {
// Same number of requests and points
assert.equal(requestCount, pointsCount)
})
})
})

function forkSsi (args, whichEnv) {
const profilerEnablingEnv = whichEnv ? { DD_PROFILING_ENABLED: 'auto' } : { DD_INJECTION_ENABLED: 'profiler' }
return fork(ssiTestFile, args, {
Expand Down

0 comments on commit 629fda4

Please sign in to comment.