From b89a553f207b05284f063806b824b359c755943e Mon Sep 17 00:00:00 2001 From: Michael Gao Date: Wed, 11 Oct 2017 15:48:01 -0700 Subject: [PATCH 1/7] Elaborate on async stack trace warning --- package-lock.json | 12 ++++++++++++ src/agent/debuglet.ts | 8 ++++++++ 2 files changed, 20 insertions(+) diff --git a/package-lock.json b/package-lock.json index 0c66f5c4..3b9fa4d8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1748,8 +1748,20 @@ "integrity": "sha1-yCYERJEt2M7szYOHYdVvRik3vQI=", "requires": { "async": "2.5.0", + "gcp-metadata": "0.2.0", "google-auth-library": "0.10.0", "request": "2.81.0" + }, + "dependencies": { + "gcp-metadata": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/gcp-metadata/-/gcp-metadata-0.2.0.tgz", + "integrity": "sha1-Ytr8pl86YxvIzi7Dt3Zh9fk4ego=", + "requires": { + "extend": "3.0.1", + "retry-request": "2.0.5" + } + } } }, "google-p12-pem": { diff --git a/src/agent/debuglet.ts b/src/agent/debuglet.ts index be18c8ac..b899aa18 100644 --- a/src/agent/debuglet.ts +++ b/src/agent/debuglet.ts @@ -205,6 +205,14 @@ export class Debuglet extends EventEmitter { * @private */ async start(): Promise { + process.on('warning', (warning) => { + if ((warning as any).code === + 'INSPECTOR_ASYNC_STACK_TRACES_NOT_AVAILABLE') { + console.log( + 'The current debug agent does not use Inspector async stack ' + + 'traces. The above warning will not affect the debug agent.'); + } + }); const that = this; const stat = promisify(fs.stat); From 89cf41cf0b2acdca422646fdb81cc225ca7576fb Mon Sep 17 00:00:00 2001 From: Michael Gao Date: Wed, 11 Oct 2017 17:14:26 -0700 Subject: [PATCH 2/7] Add test --- test/test-debuglet.ts | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/test/test-debuglet.ts b/test/test-debuglet.ts index e53275b3..cec72ce6 100644 --- a/test/test-debuglet.ts +++ b/test/test-debuglet.ts @@ -315,6 +315,43 @@ describe('Debuglet', function() { assert.deepEqual(mergedConfig, compareConfig); }); + it('should elaborate on inspector warning on 32 bit', function(done) { + let logText = ''; + const oldLog = console.log; + console.log = function(s: string) { + logText += s; + } + const projectId = '11020304f2934-a'; + const debug = new Debug( + {projectId: projectId, credentials: fakeCredentials}); + const debuglet = new Debuglet(debug, defaultConfig); + + nocks.projectId('project-via-metadata'); + const scope = nock(API) + .post(REGISTER_PATH) + .reply(200, {debuggee: {id: DEBUGGEE_ID}}); + + debuglet.once('registered', function(id: string) { + assert.equal(id, DEBUGGEE_ID); + // TODO: Handle the case where debuglet.debuggee is undefined + assert.equal((debuglet.debuggee_ as Debuggee).project, projectId); + console.log = oldLog; + const arch = process.arch; + if (arch === 'ia32' || arch === 'x86') { + assert(logText.includes('The current debug agent does not use ' + + 'Inspector async stack traces')); + } else { + assert(!logText.includes('The current debug agent does not use ' + + 'Inspector async stack traces')); + } + debuglet.stop(); + scope.done(); + done(); + }); + + debuglet.start(); + }); + it('should not start when projectId is not available', function(done) { const savedGetProjectId = Debuglet.getProjectId; Debuglet.getProjectId = () => { From e3ce1fb56d99cd208232bd13c8a159c74aac1c32 Mon Sep 17 00:00:00 2001 From: Michael Gao Date: Wed, 11 Oct 2017 17:18:45 -0700 Subject: [PATCH 3/7] Fix node 4/6 on windows --- src/agent/debuglet.ts | 1 + test/test-debuglet.ts | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/agent/debuglet.ts b/src/agent/debuglet.ts index b899aa18..2999f8f6 100644 --- a/src/agent/debuglet.ts +++ b/src/agent/debuglet.ts @@ -213,6 +213,7 @@ export class Debuglet extends EventEmitter { 'traces. The above warning will not affect the debug agent.'); } }); + const that = this; const stat = promisify(fs.stat); diff --git a/test/test-debuglet.ts b/test/test-debuglet.ts index cec72ce6..f12e6c28 100644 --- a/test/test-debuglet.ts +++ b/test/test-debuglet.ts @@ -17,6 +17,7 @@ import * as stackdriver from '../src/types/stackdriver'; import {DebugAgentConfig} from '../src/agent/config'; import {Debuggee} from '../src/debuggee'; +import * as semver from 'semver'; import * as _ from 'lodash'; import * as path from 'path'; @@ -337,12 +338,18 @@ describe('Debuglet', function() { assert.equal((debuglet.debuggee_ as Debuggee).project, projectId); console.log = oldLog; const arch = process.arch; - if (arch === 'ia32' || arch === 'x86') { - assert(logText.includes('The current debug agent does not use ' - + 'Inspector async stack traces')); + const nodeVersion = /v(\d+\.\d+\.\d+)/.exec(process.version); + if (!nodeVersion || nodeVersion.length < 2) { + (assert as any).fail(); + } else if (semver.satisfies(nodeVersion[1], '>=8') && + (arch === 'ia32' || arch === 'x86')) { + assert(logText.includes( + 'The current debug agent does not use ' + + 'Inspector async stack traces')); } else { - assert(!logText.includes('The current debug agent does not use ' - + 'Inspector async stack traces')); + assert(!logText.includes( + 'The current debug agent does not use ' + + 'Inspector async stack traces')); } debuglet.stop(); scope.done(); From a8b6729be9cd01ee13e336ae1d67cdc9fc93cf51 Mon Sep 17 00:00:00 2001 From: Michael Gao Date: Mon, 16 Oct 2017 13:13:27 -0700 Subject: [PATCH 4/7] respond to comments --- src/agent/debuglet.ts | 5 +++-- test/test-debuglet.ts | 37 ++++++++++++++++++++----------------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/src/agent/debuglet.ts b/src/agent/debuglet.ts index 2999f8f6..3ec691f5 100644 --- a/src/agent/debuglet.ts +++ b/src/agent/debuglet.ts @@ -209,8 +209,9 @@ export class Debuglet extends EventEmitter { if ((warning as any).code === 'INSPECTOR_ASYNC_STACK_TRACES_NOT_AVAILABLE') { console.log( - 'The current debug agent does not use Inspector async stack ' + - 'traces. The above warning will not affect the debug agent.'); + 'The Stackdriver debug agent does not use Inspector async stack ' + + 'traces. The INSPECTOR_ASYNC_STACK_TRACES_NOT_AVAILABLE warning ' + + 'does not impact Stackdriver debug agent and can be ignored.'); } }); diff --git a/test/test-debuglet.ts b/test/test-debuglet.ts index f12e6c28..370bcd24 100644 --- a/test/test-debuglet.ts +++ b/test/test-debuglet.ts @@ -290,16 +290,26 @@ describe('Debuglet', function() { }); describe('setup', function() { - before(function() { oldGP = process.env.GCLOUD_PROJECT; }); + before(function() { + oldGP = process.env.GCLOUD_PROJECT; + }); after(function() { process.env.GCLOUD_PROJECT = oldGP; }); - - beforeEach(function() { + let logText = ''; + let oldLog: any; + beforeEach(() => { delete process.env.GCLOUD_PROJECT; + oldLog = console.log; + console.log = function(s: string) { + logText += s; + } nocks.oauth2(); }); - afterEach(function() { nock.cleanAll(); }); + afterEach(() => { + console.log = oldLog; + nock.cleanAll(); + }); it('should merge config correctly', function() { const testValue = 2 * defaultConfig.capture.maxExpandFrames; @@ -316,12 +326,8 @@ describe('Debuglet', function() { assert.deepEqual(mergedConfig, compareConfig); }); - it('should elaborate on inspector warning on 32 bit', function(done) { - let logText = ''; - const oldLog = console.log; - console.log = function(s: string) { - logText += s; - } + it('should elaborate on inspector warning on 32 bit but not on 64 bit', + function(done) { const projectId = '11020304f2934-a'; const debug = new Debug( {projectId: projectId, credentials: fakeCredentials}); @@ -336,20 +342,17 @@ describe('Debuglet', function() { assert.equal(id, DEBUGGEE_ID); // TODO: Handle the case where debuglet.debuggee is undefined assert.equal((debuglet.debuggee_ as Debuggee).project, projectId); - console.log = oldLog; const arch = process.arch; const nodeVersion = /v(\d+\.\d+\.\d+)/.exec(process.version); + const message = 'The Stackdriver debug agent does not use Inspector async stack'; if (!nodeVersion || nodeVersion.length < 2) { + // TODO: Fix this invalid method signature. (assert as any).fail(); } else if (semver.satisfies(nodeVersion[1], '>=8') && (arch === 'ia32' || arch === 'x86')) { - assert(logText.includes( - 'The current debug agent does not use ' + - 'Inspector async stack traces')); + assert(logText.includes(message)); } else { - assert(!logText.includes( - 'The current debug agent does not use ' + - 'Inspector async stack traces')); + assert(!logText.includes(message)); } debuglet.stop(); scope.done(); From d41cf7532419a813f9c01d1ea96024575a58fa73 Mon Sep 17 00:00:00 2001 From: Michael Gao Date: Wed, 18 Oct 2017 18:33:43 -0700 Subject: [PATCH 5/7] use logger instead of console.log --- src/agent/debuglet.ts | 8 +++----- src/agent/util/utils.ts | 5 ++++- test/test-debuglet.ts | 17 ++++++++--------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/agent/debuglet.ts b/src/agent/debuglet.ts index 3ec691f5..6f9d84f2 100644 --- a/src/agent/debuglet.ts +++ b/src/agent/debuglet.ts @@ -30,6 +30,7 @@ import * as _ from 'lodash'; import * as path from 'path'; import * as semver from 'semver'; import * as util from 'util'; +import * as utils from './util/utils'; import * as http from 'http'; import {Controller} from './controller'; @@ -205,17 +206,14 @@ export class Debuglet extends EventEmitter { * @private */ async start(): Promise { + const that = this; process.on('warning', (warning) => { if ((warning as any).code === 'INSPECTOR_ASYNC_STACK_TRACES_NOT_AVAILABLE') { - console.log( - 'The Stackdriver debug agent does not use Inspector async stack ' + - 'traces. The INSPECTOR_ASYNC_STACK_TRACES_NOT_AVAILABLE warning ' + - 'does not impact Stackdriver debug agent and can be ignored.'); + that.logger_.info(utils.messages.ASYNC_TRACES_WARNING); } }); - const that = this; const stat = promisify(fs.stat); try { diff --git a/src/agent/util/utils.ts b/src/agent/util/utils.ts index b07cbcfe..fd0e1ca5 100644 --- a/src/agent/util/utils.ts +++ b/src/agent/util/utils.ts @@ -24,7 +24,10 @@ export const messages = { CAPTURE_BREAKPOINT_DATA: 'Error trying to capture snapshot data: ', INVALID_LINE_NUMBER: 'Invalid snapshot position: ', COULD_NOT_FIND_OUTPUT_FILE: - 'Could not determine the output file associated with the transpiled input file' + 'Could not determine the output file associated with the transpiled input file', + ASYNC_TRACES_WARNING: 'The Stackdriver debug agent does not use Inspector ' + + 'async stack traces. The INSPECTOR_ASYNC_STACK_TRACES_NOT_AVAILABLE ' + + 'warning does not impact Stackdriver debug agent and can be ignored.' }; export interface Listener { diff --git a/test/test-debuglet.ts b/test/test-debuglet.ts index 370bcd24..6179de9f 100644 --- a/test/test-debuglet.ts +++ b/test/test-debuglet.ts @@ -30,6 +30,7 @@ import * as dns from 'dns'; import * as extend from 'extend'; const metadata: {project: any, instance: any} = require('gcp-metadata'); import {Debug} from '../src/client/stackdriver/debug'; +import * as utils from '../src/agent/util/utils' const DEBUGGEE_ID = 'bar'; const API = 'https://clouddebugger.googleapis.com'; @@ -332,7 +333,10 @@ describe('Debuglet', function() { const debug = new Debug( {projectId: projectId, credentials: fakeCredentials}); const debuglet = new Debuglet(debug, defaultConfig); - + let logText = ''; + debuglet.logger_.info = function(s: string) { + logText += s; + }; nocks.projectId('project-via-metadata'); const scope = nock(API) .post(REGISTER_PATH) @@ -343,16 +347,11 @@ describe('Debuglet', function() { // TODO: Handle the case where debuglet.debuggee is undefined assert.equal((debuglet.debuggee_ as Debuggee).project, projectId); const arch = process.arch; - const nodeVersion = /v(\d+\.\d+\.\d+)/.exec(process.version); - const message = 'The Stackdriver debug agent does not use Inspector async stack'; - if (!nodeVersion || nodeVersion.length < 2) { - // TODO: Fix this invalid method signature. - (assert as any).fail(); - } else if (semver.satisfies(nodeVersion[1], '>=8') && + if (semver.satisfies(process.version, '>=8') && (arch === 'ia32' || arch === 'x86')) { - assert(logText.includes(message)); + assert(logText.includes(utils.messages.ASYNC_TRACES_WARNING)); } else { - assert(!logText.includes(message)); + assert(!logText.includes(utils.messages.ASYNC_TRACES_WARNING)); } debuglet.stop(); scope.done(); From 56c8dfeed206447dfa7fd7617d53f843c53b654b Mon Sep 17 00:00:00 2001 From: Michael Gao Date: Thu, 19 Oct 2017 14:03:58 -0700 Subject: [PATCH 6/7] remove dead code --- test/test-debuglet.ts | 7 ------- 1 file changed, 7 deletions(-) diff --git a/test/test-debuglet.ts b/test/test-debuglet.ts index 6179de9f..50870da4 100644 --- a/test/test-debuglet.ts +++ b/test/test-debuglet.ts @@ -296,19 +296,12 @@ describe('Debuglet', function() { }); after(function() { process.env.GCLOUD_PROJECT = oldGP; }); - let logText = ''; - let oldLog: any; beforeEach(() => { delete process.env.GCLOUD_PROJECT; - oldLog = console.log; - console.log = function(s: string) { - logText += s; - } nocks.oauth2(); }); afterEach(() => { - console.log = oldLog; nock.cleanAll(); }); From 01666c9fcb13e02dfa31abea9154ed4ec94696c2 Mon Sep 17 00:00:00 2001 From: Michael Gao Date: Fri, 20 Oct 2017 10:57:50 -0700 Subject: [PATCH 7/7] resolve comments --- src/agent/util/utils.ts | 5 +++-- test/test-debuglet.ts | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/agent/util/utils.ts b/src/agent/util/utils.ts index fd0e1ca5..3f0593c2 100644 --- a/src/agent/util/utils.ts +++ b/src/agent/util/utils.ts @@ -25,9 +25,10 @@ export const messages = { INVALID_LINE_NUMBER: 'Invalid snapshot position: ', COULD_NOT_FIND_OUTPUT_FILE: 'Could not determine the output file associated with the transpiled input file', - ASYNC_TRACES_WARNING: 'The Stackdriver debug agent does not use Inspector ' + + ASYNC_TRACES_WARNING: + 'The Stackdriver Debugger for Node.js does not require V8 Inspector ' + 'async stack traces. The INSPECTOR_ASYNC_STACK_TRACES_NOT_AVAILABLE ' + - 'warning does not impact Stackdriver debug agent and can be ignored.' + 'can be ignored.' }; export interface Listener { diff --git a/test/test-debuglet.ts b/test/test-debuglet.ts index 50870da4..f37defcc 100644 --- a/test/test-debuglet.ts +++ b/test/test-debuglet.ts @@ -296,12 +296,12 @@ describe('Debuglet', function() { }); after(function() { process.env.GCLOUD_PROJECT = oldGP; }); - beforeEach(() => { + beforeEach(function() { delete process.env.GCLOUD_PROJECT; nocks.oauth2(); }); - afterEach(() => { + afterEach(function() { nock.cleanAll(); }); @@ -340,7 +340,7 @@ describe('Debuglet', function() { // TODO: Handle the case where debuglet.debuggee is undefined assert.equal((debuglet.debuggee_ as Debuggee).project, projectId); const arch = process.arch; - if (semver.satisfies(process.version, '>=8') && + if (semver.satisfies(process.version, '>=8.5') && (arch === 'ia32' || arch === 'x86')) { assert(logText.includes(utils.messages.ASYNC_TRACES_WARNING)); } else {