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

Commit c7e1572

Browse files
author
Matt Loring
committed
Add config and more descriptive names on GCE/GKE
Allow for custom config files specified by the GCLOUD_DIAGNOSTICS_CONFIG environment variable. Also attach provided description to the debuggee so it is visible in the UI.
1 parent 3fcf3e8 commit c7e1572

File tree

12 files changed

+170
-58
lines changed

12 files changed

+170
-58
lines changed

config.js

Lines changed: 44 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -17,56 +17,60 @@
1717

1818
// Default configuration
1919
module.exports = {
20-
enabled: true,
21-
workingDirectory: process.cwd(),
20+
debug: {
21+
enabled: true,
22+
workingDirectory: process.cwd(),
2223

23-
// The path within your repository to the directory containing the
24-
// package.json for your deployed application. This should be provided
25-
// if your deployed application appears as a subdirectory of your repository.
26-
appPathRelativeToRepository: undefined,
24+
// An identifier for the current code deployment.
25+
description: undefined,
2726

28-
// Log levels: 0-disabled,1-error,2-warn,3-info,4-debug.
29-
logLevel: 1,
27+
// The path within your repository to the directory containing the
28+
// package.json for your deployed application. This should be provided
29+
// if your deployed application appears as a subdirectory of your repository.
30+
appPathRelativeToRepository: undefined,
3031

31-
// How frequently should the list of breakpoints be refreshed from the
32-
// cloud debug server.
33-
breakpointUpdateIntervalSec: 10,
32+
// Log levels: 0-disabled,1-error,2-warn,3-info,4-debug.
33+
logLevel: 1,
3434

35-
// We expire stale breakpoints on the server.
36-
breakpointExpirationSec: 60 * 60 * 24, // 24 hours
35+
// How frequently should the list of breakpoints be refreshed from the
36+
// cloud debug server.
37+
breakpointUpdateIntervalSec: 10,
3738

38-
capture: {
39-
// Whether to include details about stack frames belonging to node-core.
40-
includeNodeModules: false,
39+
// We expire stale breakpoints on the server.
40+
breakpointExpirationSec: 60 * 60 * 24, // 24 hours
4141

42-
// Maximum number of stack frames to capture data for. The limit is aimed
43-
// to reduce overall capture time
44-
maxFrames: 20,
42+
capture: {
43+
// Whether to include details about stack frames belonging to node-core.
44+
includeNodeModules: false,
4545

46-
// Only collect locals and arguments on a few top frames. For the rest
47-
// only collect the source location
48-
maxExpandFrames: 5,
46+
// Maximum number of stack frames to capture data for. The limit is aimed
47+
// to reduce overall capture time
48+
maxFrames: 20,
4949

50-
// To reduce the overall capture time, limit the number of properties
51-
// gathered on large object. A value of 0 disables the limit.
52-
maxProperties: 0,
50+
// Only collect locals and arguments on a few top frames. For the rest
51+
// only collect the source location
52+
maxExpandFrames: 5,
5353

54-
// Total 'size' of data to gather. This is NOT the number of bytes of data
55-
// that are sent over the wire, but instead a very very coarse approximation
56-
// based on the length of names and values of the properties. This should
57-
// be somewhat proportional to the amount of processing needed to capture
58-
// the data and subsequently the network traffic. A value of 0 disables the
59-
// limit.
60-
maxDataSize: 20000,
54+
// To reduce the overall capture time, limit the number of properties
55+
// gathered on large object. A value of 0 disables the limit.
56+
maxProperties: 0,
6157

62-
// To limit the size of the buffer, we truncate long strings.
63-
// A value of 0 disables truncation.
64-
maxStringLength: 0
65-
},
58+
// Total 'size' of data to gather. This is NOT the number of bytes of data
59+
// that are sent over the wire, but instead a very very coarse approximation
60+
// based on the length of names and values of the properties. This should
61+
// be somewhat proportional to the amount of processing needed to capture
62+
// the data and subsequently the network traffic. A value of 0 disables the
63+
// limit.
64+
maxDataSize: 20000,
6665

67-
// These configuration options are for internal experimentation only.
68-
internal: {
69-
registerDelayOnFetcherErrorSec: 300 // 5 minutes.
70-
}
66+
// To limit the size of the buffer, we truncate long strings.
67+
// A value of 0 disables truncation.
68+
maxStringLength: 0
69+
},
7170

71+
// These configuration options are for internal experimentation only.
72+
internal: {
73+
registerDelayOnFetcherErrorSec: 300 // 5 minutes.
74+
}
75+
}
7276
};

index.js

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,37 @@
1919
// NOTE: this file is on the critical path for the startup of the user's
2020
// application. The path-length here needs to be minimal.
2121

22-
var config = require('./config.js');
2322
var logger = require('@google/cloud-diagnostics-common').logger;
2423
var Debuglet = require('./lib/debuglet.js');
24+
var path = require('path');
25+
var _ = require('lodash');
26+
27+
var initConfig = function() {
28+
var config = {};
29+
if (process.env.hasOwnProperty('GCLOUD_DIAGNOSTICS_CONFIG')) {
30+
var c = require(path.resolve(process.env.GCLOUD_DIAGNOSTICS_CONFIG));
31+
if (c && c.debug) {
32+
_.defaultsDeep(config, c.debug);
33+
}
34+
}
35+
var defaults = require('./config.js').debug;
36+
_.defaultsDeep(config, defaults);
37+
if (process.env.hasOwnProperty('GCLOUD_DEBUG_LOGLEVEL')) {
38+
config.logLevel = process.env.GCLOUD_DEBUG_LOGLEVEL;
39+
}
40+
if (process.env.hasOwnProperty('GCLOUD_DEBUG_DISABLE')) {
41+
config.enabled = false;
42+
}
43+
if (process.env.hasOwnProperty('GCLOUD_DEBUG_REPO_APP_PATH')) {
44+
config.appPathRelativeToRepository =
45+
process.env.GCLOUD_DEBUG_REPO_APP_PATH;
46+
}
47+
return config;
48+
};
2549

2650
// exports is populated by the agent
2751
module.exports = {};
28-
if (process.env.hasOwnProperty('GCLOUD_DEBUG_LOGLEVEL')) {
29-
config.logLevel = process.env.GCLOUD_DEBUG_LOGLEVEL;
30-
}
31-
if (process.env.hasOwnProperty('GCLOUD_DEBUG_DISABLE')) {
32-
config.enabled = false;
33-
}
34-
if (process.env.hasOwnProperty('GCLOUD_DEBUG_REPO_APP_PATH')) {
35-
config.appPathRelativeToRepository =
36-
process.env.GCLOUD_DEBUG_REPO_APP_PATH;
37-
}
52+
var config = initConfig();
3853

3954
var log = logger.create(config.logLevel, '@google/cloud-debug');
4055

lib/debuglet.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ function Debuglet(config, logger) {
6565
this.logger_ = logger;
6666

6767
/** @private {DebugletApi} */
68-
this.debugletApi_ = new DebugletApi();
68+
this.debugletApi_ = new DebugletApi(config.description);
6969

7070
/** @private {Object.<string, Breakpoint>} */
7171
this.activeBreakpointMap_ = {};

lib/debugletapi.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ var SCOPES = [
4141
/**
4242
* @constructor
4343
*/
44-
function DebugletApi() {
44+
function DebugletApi(descriptor) {
4545
/** @private {Object} request style request object */
4646
this.request_ = utils.authorizedRequestFactory(SCOPES);
4747

@@ -50,6 +50,9 @@ function DebugletApi() {
5050

5151
/** @private {string} debuggee id provided by the server once registered */
5252
this.debuggeeId_ = null;
53+
54+
/** @private {string} a descriptor of the current code version */
55+
this.descriptor_ = descriptor;
5356
}
5457

5558
/**
@@ -151,6 +154,10 @@ DebugletApi.prototype.register_ = function(errorMessage, callback) {
151154
}
152155
}
153156

157+
if (that.descriptor_) {
158+
desc += ' description:' + that.descriptor_;
159+
}
160+
154161
if (process.env.GAE_MINOR_VERSION) {
155162
labels[DEBUGGEE_MINOR_VERSION_LABEL] = process.env.GAE_MINOR_VERSION;
156163
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"coffee-script": "^1.9.3",
6565
"findit": "^2.0.0",
6666
"google-auth-library": "^0.9.5",
67+
"lodash": "^4.12.0",
6768
"request": "^2.61.0",
6869
"semver": "^5.1.0",
6970
"source-map": "^0.5.1",

test/fixtures/test-config.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* Copyright 2015 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
'use strict';
17+
18+
// Default configuration
19+
module.exports = {
20+
debug: {
21+
enabled: true,
22+
23+
// An identifier for the current code deployment.
24+
description: 'test config',
25+
26+
// Log levels: 0-disabled,1-error,2-warn,3-info,4-debug.
27+
logLevel: 4,
28+
29+
capture: {
30+
// Whether to include details about stack frames belonging to node-core.
31+
includeNodeModules: true,
32+
},
33+
34+
// These configuration options are for internal experimentation only.
35+
internal: {
36+
registerDelayOnFetcherErrorSec: 300 // 5 minutes.
37+
}
38+
}
39+
};

test/standalone/test-debuglet.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
var assert = require('assert');
1919
var request = require('request');
2020
var logger = require('@google/cloud-diagnostics-common').logger;
21-
var config = require('../../config.js');
21+
var config = require('../../config.js').debug;
2222
var Debuglet = require('../../lib/debuglet.js');
2323

2424
var DEBUGGEE_ID = 'bar';

test/standalone/test-duplicate-expressions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ var breakpointInFoo = {
2929
var assert = require('assert');
3030
var v8debugapi = require('../../lib/v8debugapi.js');
3131
var logModule = require('@google/cloud-diagnostics-common').logger;
32-
var config = require('../../config.js');
32+
var config = require('../../config.js').debug;
3333
var scanner = require('../../lib/scanner.js');
3434
var path = require('path');
3535

test/standalone/test-env-config.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* Copyright 2015 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
'use strict';
18+
19+
process.env.GCLOUD_DIAGNOSTICS_CONFIG = 'test/fixtures/test-config.js';
20+
process.env.GCLOUD_DEBUG_LOGLEVEL = 4;
21+
22+
var assert = require('assert');
23+
24+
describe('should respect environment variables', function() {
25+
it('should respect GCLOUD_DIAGNOSTICS_CONFIG', function() {
26+
var agent = require('../..');
27+
var config = agent.private_.config_;
28+
// Set by env var
29+
assert.equal(config.logLevel, 4);
30+
// Set default + user config
31+
assert.equal(config.internal.registerDelayOnFetcherErrorSec, 300);
32+
// Set by user
33+
assert.equal(config.capture.includeNodeModules, true);
34+
// In sub config but not set by user
35+
assert.equal(config.capture.maxExpandFrames, 5);
36+
// In top level config set by user
37+
assert.equal(config.description, 'test config');
38+
// In top level config not set by user
39+
assert.equal(config.breakpointUpdateIntervalSec, 10);
40+
});
41+
42+
});

test/standalone/test-max-data-size.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ var assert = require('assert');
2525
var logModule = require('@google/cloud-diagnostics-common').logger;
2626
var v8debugapi = require('../../lib/v8debugapi.js');
2727
var scanner = require('../../lib/scanner.js');
28-
var config = require('../../config.js');
28+
var config = require('../../config.js').debug;
2929
var api;
3030

3131
var breakpointInFoo = {

0 commit comments

Comments
 (0)