-
Notifications
You must be signed in to change notification settings - Fork 306
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DI] Drop snapshot if JSON payload is too large (#4818)
The log track has a 1MB limit of the JSON payload. The client is not notified if the payload is too large, but it is simply never indexed. This is a very crude approach. In the future a more sophsticated algorithm will be implemented that reduces the size of the snapshot instead of removing it completely.
- Loading branch information
Showing
5 changed files
with
115 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
'use strict' | ||
|
||
const { assert } = require('chai') | ||
const { setup, getBreakpointInfo } = require('./utils') | ||
|
||
const { line } = getBreakpointInfo() | ||
|
||
describe('Dynamic Instrumentation', function () { | ||
const t = setup() | ||
|
||
describe('input messages', function () { | ||
describe('with snapshot', function () { | ||
beforeEach(t.triggerBreakpoint) | ||
|
||
it('should prune snapshot if payload is too large', function (done) { | ||
t.agent.on('debugger-input', ({ payload }) => { | ||
assert.isBelow(Buffer.byteLength(JSON.stringify(payload)), 1024 * 1024) // 1MB | ||
assert.deepEqual(payload['debugger.snapshot'].captures, { | ||
lines: { | ||
[line]: { | ||
locals: { | ||
notCapturedReason: 'Snapshot was too large', | ||
size: 6 | ||
} | ||
} | ||
} | ||
}) | ||
done() | ||
}) | ||
|
||
t.agent.addRemoteConfig(t.generateRemoteConfig({ | ||
captureSnapshot: true, | ||
capture: { | ||
// ensure we get a large snapshot | ||
maxCollectionSize: Number.MAX_SAFE_INTEGER, | ||
maxFieldCount: Number.MAX_SAFE_INTEGER, | ||
maxLength: Number.MAX_SAFE_INTEGER | ||
} | ||
})) | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
'use strict' | ||
|
||
require('dd-trace/init') | ||
|
||
const { randomBytes } = require('crypto') | ||
const Fastify = require('fastify') | ||
|
||
const fastify = Fastify() | ||
|
||
const TARGET_SIZE = 1024 * 1024 // 1MB | ||
const LARGE_STRING = randomBytes(1024).toString('hex') | ||
|
||
fastify.get('/:name', function handler (request) { | ||
// eslint-disable-next-line no-unused-vars | ||
const obj = generateObjectWithJSONSizeLargerThan1MB() | ||
|
||
return { hello: request.params.name } // BREAKPOINT | ||
}) | ||
|
||
fastify.listen({ port: process.env.APP_PORT }, (err) => { | ||
if (err) { | ||
fastify.log.error(err) | ||
process.exit(1) | ||
} | ||
process.send({ port: process.env.APP_PORT }) | ||
}) | ||
|
||
function generateObjectWithJSONSizeLargerThan1MB () { | ||
const obj = {} | ||
let i = 0 | ||
|
||
while (++i) { | ||
if (i % 100 === 0) { | ||
const size = JSON.stringify(obj).length | ||
if (size > TARGET_SIZE) break | ||
} | ||
obj[i] = LARGE_STRING | ||
} | ||
|
||
return obj | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters