-
Notifications
You must be signed in to change notification settings - Fork 309
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
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
3 changed files
with
75 additions
and
1 deletion.
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,23 @@ | ||
'use strict' | ||
|
||
const { assert } = require('chai') | ||
const { setup } = require('./utils') | ||
|
||
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 | ||
done() | ||
}) | ||
|
||
t.agent.addRemoteConfig(t.generateRemoteConfig({ captureSnapshot: true })) | ||
}) | ||
}) | ||
}) | ||
}) |
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