Skip to content

Commit

Permalink
Profiler shouldn't retry some HTTP requests when sending profiles (#4823
Browse files Browse the repository at this point in the history
)
  • Loading branch information
szegedi authored Oct 28, 2024
1 parent 24e846e commit a872175
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 7 deletions.
12 changes: 7 additions & 5 deletions packages/dd-trace/src/profiling/exporters/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,13 @@ class AgentExporter {
})

sendRequest(options, form, (err, response) => {
if (operation.retry(err)) {
this._logger.error(`Error from the agent: ${err.message}`)
return
} else if (err) {
reject(err)
if (err) {
const { status } = err
if ((typeof status !== 'number' || status >= 500 || status === 429) && operation.retry(err)) {
this._logger.error(`Error from the agent: ${err.message}`)
} else {
reject(err)
}
return
}

Expand Down
41 changes: 39 additions & 2 deletions packages/dd-trace/test/profiling/exporters/agent.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ describe('exporters/agent', function () {
/^Adding wall profile to agent export:( [0-9a-f]{2})+$/,
/^Adding space profile to agent export:( [0-9a-f]{2})+$/,
/^Submitting profiler agent report attempt #1 to:/i,
/^Error from the agent: HTTP Error 400$/,
/^Error from the agent: HTTP Error 500$/,
/^Submitting profiler agent report attempt #2 to:/i,
/^Agent export response: ([0-9a-f]{2}( |$))*/
]
Expand Down Expand Up @@ -344,7 +344,7 @@ describe('exporters/agent', function () {
return
}
const data = Buffer.from(json)
res.writeHead(400, {
res.writeHead(500, {
'content-type': 'application/json',
'content-length': data.length
})
Expand All @@ -356,6 +356,43 @@ describe('exporters/agent', function () {
waitForResponse
])
})

it('should not retry on 4xx errors', async function () {
const exporter = newAgentExporter({ url, logger: { debug: () => {}, error: () => {} } })
const start = new Date()
const end = new Date()
const tags = { foo: 'bar' }

const [wall, space] = await Promise.all([
createProfile(['wall', 'microseconds']),
createProfile(['space', 'bytes'])
])

const profiles = {
wall,
space
}

let tries = 0
const json = JSON.stringify({ error: 'some error' })
app.post('/profiling/v1/input', upload.any(), (_, res) => {
tries++
const data = Buffer.from(json)
res.writeHead(400, {
'content-type': 'application/json',
'content-length': data.length
})
res.end(data)
})

try {
await exporter.export({ profiles, start, end, tags })
throw new Error('should have thrown')
} catch (err) {
expect(err.message).to.equal('HTTP Error 400')
}
expect(tries).to.equal(1)
})
})

describe('using ipv6', () => {
Expand Down

0 comments on commit a872175

Please sign in to comment.