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

Commit 9f0e2fd

Browse files
Add debuggee name to the re-register log message (#154)
* Add debuggee name to the re-register log message If an error occurs when re-registering a debuggee, the name of the debuggee is reported in the error message to aid in debugging why the re-registration failed. fixes #128 * Update debugletapi test code to use new init() api The debugletapi#init() method was updated to accept a callback of the form 'callback(err, project)' instead of 'callback(err)'. The test code for the class was updated so that callbacks now include the 'project' parameter. * Add test to validate setting debugletapi.project_ When the debugletapi.init() method calls its callback, the project ID reported in the callback should match the project ID stored in the debugletapi object. * Add more robust checking of project names The testing of the debugletapi#init() method was updated so that the project name given through the callback was the project name expected. * Cleaned up the test for the init() method Now the test for the debugletapi#init() method doesn't stub out the utils.getProjectNumber method because it is already being stubbed out earlier in the code. * Fix a bug involving the GCLOUD_PROJECT env var The tests in teh test-debugletapi.js file assumed the GCLOUD_PROJECT environment variable was not set, and would fail if this assumption wasn't valid. Now the GCLOUD_PROJECT environment variable is unset when running this file. * Now the project is passed to all init cb calls PR-URL: #154
1 parent 1b22490 commit 9f0e2fd

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

lib/debuglet.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ function Debuglet(config, logger) {
5858
/** @private {boolean} */
5959
this.running_ = false;
6060

61+
/** @private {string} */
62+
this.project_ = null;
63+
6164
/** @private {boolean} */
6265
this.fetcherActive_ = false;
6366

@@ -108,7 +111,7 @@ Debuglet.prototype.start = function() {
108111

109112
that.logger_.info('Unique ID for this Application: ' + id);
110113

111-
that.debugletApi_.init(id, that.logger_, function(err) {
114+
that.debugletApi_.init(id, that.logger_, function(err, project) {
112115
if (err) {
113116
that.logger_.error('Unable to initialize the debuglet api' +
114117
' -- disabling debuglet', err);
@@ -126,6 +129,7 @@ Debuglet.prototype.start = function() {
126129

127130
// We can register as a debuggee now.
128131
that.running_ = true;
132+
that.project_ = project;
129133
that.scheduleRegistration_(0 /* immediately */);
130134
that.emit('started');
131135
});
@@ -141,7 +145,8 @@ Debuglet.prototype.scheduleRegistration_ = function(seconds) {
141145
var that = this;
142146

143147
function onError(err) {
144-
that.logger_.error('Failed to re-register debuggee: ' + err);
148+
that.logger_.error('Failed to re-register debuggee ' +
149+
that.project_ + ': ' + err);
145150
that.scheduleRegistration_(Math.min((seconds + 1) * 2,
146151
that.config_.internal.maxRegistrationRetryDelay));
147152
}

lib/debugletapi.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ DebugletApi.prototype.init = function(uid, logger, callback) {
7171

7272
function complete(err, project) {
7373
if (err) {
74-
callback(err);
74+
callback(err, project);
7575
return;
7676
}
7777
that.project_ = project;
@@ -83,7 +83,7 @@ DebugletApi.prototype.init = function(uid, logger, callback) {
8383
logger.warn('Malformed source-context.json file.');
8484
// But we keep on going.
8585
}
86-
callback(null);
86+
callback(null, project);
8787
});
8888
}
8989

test/test-debugletapi.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ var request = require('request');
2121
var proxyquire = require('proxyquire');
2222
var agentVersion = require('../package.json').version;
2323

24+
// the tests in this file rely on the GCLOUD_PROJECT environment variable
25+
// not being set
26+
delete process.env.GCLOUD_PROJECT;
27+
2428
// require DebugletAPI while stubbing auth to bypass authentication
2529
//
2630
var utils = {
@@ -53,8 +57,12 @@ describe('Debuglet API', function() {
5357
});
5458

5559
it('should acquire the project number during init', function(done) {
56-
debugletapi.init('uid123', { warn: function() {} }, function(err) {
60+
debugletapi.init('uid123', { warn: function() {} }, function(err, project) {
5761
assert(!err);
62+
// make sure init() invokes the callback with the correct project name
63+
assert.equal(project, 'project123');
64+
// make sure the debugletapi is properly storing the project name
65+
assert.equal(debugletapi.project_, project);
5866
done();
5967
});
6068
});
@@ -84,9 +92,9 @@ describe('Debuglet API', function() {
8492
utils.getProjectNumber = function(callback) {
8593
callback(new Error(), null);
8694
};
87-
process.GCLOUD_PROJECT = 'project123';
95+
process.env.GCLOUD_PROJECT = 'project123';
8896
var debugletapi = new DebugletApi();
89-
debugletapi.init('uid1234', { warn: function() {} }, function(err) {
97+
debugletapi.init('uid1234', { warn: function() {} }, function(err, project) {
9098
var scope = nock(url)
9199
.post(api + '/debuggees/register', function (body) {
92100
return body.debuggee.agentVersion ===
@@ -101,7 +109,7 @@ describe('Debuglet API', function() {
101109
assert.equal(result.debuggee.id, 'fake-debuggee');
102110
assert.equal(debugletapi.debuggeeId_, 'fake-debuggee');
103111
scope.done();
104-
delete process.GCLOUD_PROJECT;
112+
delete process.env.GCLOUD_PROJECT;
105113
utils.getProjectNumber = oldProjNum;
106114
done();
107115
});

0 commit comments

Comments
 (0)