Skip to content
This repository was archived by the owner on Apr 3, 2024. It is now read-only.

Commit 21ef3b2

Browse files
author
Matt Loring
committed
Allow for unlimited data capture size
1 parent 1f07e00 commit 21ef3b2

File tree

3 files changed

+90
-3
lines changed

3 files changed

+90
-3
lines changed

config.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,12 @@ module.exports = {
5151
// gathered on large object. A value of 0 disables the limit.
5252
maxProperties: 0,
5353

54-
// Total 'size' if data to gather. This is NOT the number of bytes of data
54+
// Total 'size' of data to gather. This is NOT the number of bytes of data
5555
// that are sent over the wire, but instead a very very coarse approximation
5656
// based on the length of names and values of the properties. This should
5757
// be somewhat proportional to the amount of processing needed to capture
58-
// the data and subsequently the network traffic.
58+
// the data and subsequently the network traffic. A value of 0 disables the
59+
// limit.
5960
maxDataSize: 20000,
6061

6162
// To limit the size of the buffer, we truncate long strings.

lib/state.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,9 @@ StateResolver.prototype.capture_ = function() {
145145

146146
// Now resolve the variables
147147
var index = MESSAGE_TABLE.length; // skip the sentinel values
148+
var noLimit = that.config_.capture.maxDataSize === 0;
148149
while (index < that.rawVariableTable_.length && // NOTE: length changes in loop
149-
that.totalSize_ < that.config_.capture.maxDataSize) {
150+
(that.totalSize_ < that.config_.capture.maxDataSize || noLimit)) {
150151
assert(!that.resolvedVariableTable_[index]); // shouldn't have it resolved yet
151152
that.resolvedVariableTable_[index] =
152153
that.resolveMirror_(that.rawVariableTable_[index]);
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*1* KEEP THIS CODE AT THE TOP TO AVOID LINE NUMBER CHANGES */
2+
/*2*/'use strict';
3+
/*3*/function foo(n) {
4+
/*4*/ var A = new Array(3); return n+42+A[0];
5+
/*5*/}
6+
/**
7+
* Copyright 2015 Google Inc. All Rights Reserved.
8+
*
9+
* Licensed under the Apache License, Version 2.0 (the "License");
10+
* you may not use this file except in compliance with the License.
11+
* You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS,
17+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
* See the License for the specific language governing permissions and
19+
* limitations under the License.
20+
*/
21+
22+
process.env.GCLOUD_DIAGNOSTICS_CONFIG = 'test/fixtures/test-config.js';
23+
24+
var assert = require('assert');
25+
var logModule = require('@google/cloud-diagnostics-common').logger;
26+
var v8debugapi = require('../../lib/v8debugapi.js');
27+
var scanner = require('../../lib/scanner.js');
28+
var config = require('../../config.js');
29+
var api;
30+
31+
var breakpointInFoo = {
32+
id: 'fake-id-123',
33+
location: { path: 'test-max-data-size.js', line: 4 }
34+
};
35+
36+
describe('maxDataSize', function() {
37+
before(function(done) {
38+
if (!api) {
39+
var logger = logModule.create(config.logLevel);
40+
scanner.scan(true, config.workingDirectory, function(err, fileStats, hash) {
41+
assert(!err);
42+
api = v8debugapi.create(logger, config, fileStats);
43+
done();
44+
});
45+
} else {
46+
done();
47+
}
48+
});
49+
50+
it('should limit data reported', function(done) {
51+
config.capture.maxDataSize = 5;
52+
// clone a clean breakpointInFoo
53+
var bp = {id: breakpointInFoo.id, location: breakpointInFoo.location};
54+
api.set(bp, function(err) {
55+
assert.ifError(err);
56+
api.wait(bp, function(err) {
57+
assert.ifError(err);
58+
assert(bp.variableTable.some(function(v) {
59+
return v.status.description.format === 'Max data size reached';
60+
}));
61+
api.clear(bp);
62+
done();
63+
});
64+
process.nextTick(function() {foo(2);});
65+
});
66+
});
67+
68+
it('should be unlimited if 0', function(done) {
69+
config.capture.maxDataSize = 0;
70+
// clone a clean breakpointInFoo
71+
var bp = {id: breakpointInFoo.id, location: breakpointInFoo.location};
72+
api.set(bp, function(err) {
73+
assert.ifError(err);
74+
api.wait(bp, function(err) {
75+
assert.ifError(err);
76+
assert(bp.variableTable.reduce(function(acc, elem) {
77+
return acc && elem.status.description.format !== 'Max data size reached';
78+
}), true);
79+
api.clear(bp);
80+
done();
81+
});
82+
process.nextTick(function() {foo(2);});
83+
});
84+
});
85+
});

0 commit comments

Comments
 (0)