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

Commit c15872d

Browse files
Inspector only enabled when specified (#343)
As side effect cannot be guaranteed in runtime.getProperties, we will not enable v8 inspector by default. Instead, use will need to explicitly set GCLOUD_USE_INSPECTOR=true to run with v8 inspector.
1 parent 964cc31 commit c15872d

File tree

10 files changed

+65
-84
lines changed

10 files changed

+65
-84
lines changed

appveyor.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ install:
1919
test_script:
2020
# run tests
2121
- npm run build
22+
- SET GCLOUD_USE_INSPECTOR=
23+
- node_modules/.bin/mocha build/test --timeout 4000 --R
24+
- SET GCLOUD_USE_INSPECTOR=1
2225
- node_modules/.bin/mocha build/test --timeout 4000 --R
2326

2427
# Don't actually build using MSBuild

bin/run-test.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ function run {
3030
}
3131

3232
# Run test/coverage
33-
run build/test
33+
GCLOUD_USE_INSPECTOR= run build/test
34+
GCLOUD_USE_INSPECTOR=true run build/test
3435

3536
# Conditionally publish coverage
3637
if [ "$cover" ]; then

package-lock.json

Lines changed: 11 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"gulp-typescript": "^3.1.6",
4646
"istanbul": "^0.4.1",
4747
"merge2": "^1.0.3",
48-
"mocha": "^3.0.0",
48+
"mocha": "^3.5.3",
4949
"nock": "^9.0.0",
5050
"request": "^2.81.0",
5151
"source-map-support": "^0.4.15",

src/agent/util/utils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ export const messages = {
2828
ASYNC_TRACES_WARNING:
2929
'The Stackdriver Debugger for Node.js does not require V8 Inspector ' +
3030
'async stack traces. The INSPECTOR_ASYNC_STACK_TRACES_NOT_AVAILABLE ' +
31-
'can be ignored.'
31+
'can be ignored.',
32+
INSPECTOR_NOT_AVAILABLE:
33+
'The V8 Inspector protocol is only available in Node 8+'
3234
};
3335

3436
export interface Listener {

src/agent/v8/debugapi.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,9 @@ interface DebugApiConstructor {
4141
}
4242

4343
let debugApiConstructor: DebugApiConstructor;
44-
const nodeVersion = /v(\d+\.\d+\.\d+)/.exec(process.version);
4544

46-
if (!nodeVersion || nodeVersion.length < 2) {
47-
const dummyapi = require('./dummy-debugapi');
48-
debugApiConstructor = dummyapi.DummyDebugApi;
49-
} else if (semver.satisfies(nodeVersion[1], '>=8')) {
45+
if (semver.satisfies(process.version, '>=8') &&
46+
process.env.GCLOUD_USE_INSPECTOR) {
5047
const inspectorapi = require('./inspector-debugapi');
5148
debugApiConstructor = inspectorapi.InspectorDebugApi;
5249
} else {

src/agent/v8/dummy-debugapi.ts

Lines changed: 0 additions & 56 deletions
This file was deleted.

src/agent/v8/legacy-debugapi.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ export class V8DebugApi implements debugapi.DebugApi {
9090
this.logger.warn('Internal V8 error on breakpoint event: ' + e);
9191
}
9292
};
93+
if (process.env.GCLOUD_USE_INSPECTOR) {
94+
this.logger.warn(utils.messages.INSPECTOR_NOT_AVAILABLE);
95+
}
9396
if (this.usePermanentListener) {
9497
this.logger.info('activating v8 breakpoint listener (permanent)');
9598

test/test-debuglet.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,8 @@ describe('Debuglet', function() {
341341
assert.equal((debuglet.debuggee_ as Debuggee).project, projectId);
342342
const arch = process.arch;
343343
if (semver.satisfies(process.version, '>=8.5') &&
344-
(arch === 'ia32' || arch === 'x86')) {
344+
(arch === 'ia32' || arch === 'x86') &&
345+
process.env.GCLOUD_USE_INSPECTOR) {
345346
assert(logText.includes(utils.messages.ASYNC_TRACES_WARNING));
346347
} else {
347348
assert(!logText.includes(utils.messages.ASYNC_TRACES_WARNING));

test/test-v8debugapi.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,44 @@ function validateBreakpoint(breakpoint: stackdriver.Breakpoint): void {
110110
breakpoint.stackFrames.forEach(validateStackFrame);
111111
}
112112
}
113+
describe('debugapi selection', function() {
114+
const config: DebugAgentConfig = extend({}, defaultConfig, {
115+
workingDirectory: __dirname,
116+
forceNewAgent_: true
117+
});
118+
const logger = new common.logger({ levelLevel: config.logLevel } as any as LoggerOptions);
119+
let logText = '';
120+
logger.warn = function(s: string) {
121+
logText += s;
122+
}
123+
it('should use the correct debugapi and have appropriate warning', (done) => {
124+
let api: DebugApi;
125+
scanner.scan(true, config.workingDirectory as string, /.js$|.map$/)
126+
.then(function (fileStats) {
127+
const jsStats = fileStats.selectStats(/.js$/);
128+
const mapFiles = fileStats.selectFiles(/.map$/, process.cwd());
129+
SourceMapper.create(mapFiles, function (err, mapper) {
130+
assert(!err);
131+
// TODO: Handle the case when mapper is undefined.
132+
// TODO: Handle the case when v8debugapi.create returns null
133+
api = debugapi.create(logger, config, jsStats, mapper as SourceMapper.SourceMapper) as DebugApi;
134+
if (process.env.GCLOUD_USE_INSPECTOR && semver.satisfies(process.version, '>=8')) {
135+
const inspectorapi = require('../src/agent/v8/inspector-debugapi');
136+
assert.ok(api instanceof inspectorapi.InspectorDebugApi);
137+
} else {
138+
const v8debugapi = require('../src/agent/v8/legacy-debugapi');
139+
assert.ok(api instanceof v8debugapi.V8DebugApi);
140+
}
141+
if (process.env.GCLOUD_USE_INSPECTOR && semver.satisfies(process.version, '<8')) {
142+
assert(logText.includes(utils.messages.INSPECTOR_NOT_AVAILABLE));
143+
} else {
144+
assert(!logText.includes(utils.messages.INSPECTOR_NOT_AVAILABLE));
145+
}
146+
done();
147+
});
148+
});
149+
});
150+
});
113151

114152
describe('v8debugapi', function() {
115153
const config: DebugAgentConfig = extend({}, defaultConfig, {

0 commit comments

Comments
 (0)