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

Commit

Permalink
fix: use debuglet's logger in the controller. (#1077)
Browse files Browse the repository at this point in the history
This will provide a consistent log level throughout the codebase.
  • Loading branch information
mctavish authored May 11, 2022
1 parent dd61d35 commit c236f35
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 21 deletions.
6 changes: 5 additions & 1 deletion src/agent/debuglet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,11 @@ export class Debuglet extends EventEmitter {
this.emit('initError', err);
return;
}
this.controller = new OnePlatformController(this.debug, this.config);
this.controller = new OnePlatformController(
this.debug,
this.config,
this.logger
);
}

if (
Expand Down
8 changes: 2 additions & 6 deletions src/agent/oneplatform-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import {ServiceObject} from '@google-cloud/common';
import * as assert from 'assert';
import * as consoleLogLevel from 'console-log-level';
import * as qs from 'querystring';
import * as t from 'teeny-request';

Expand Down Expand Up @@ -48,7 +47,7 @@ export class OnePlatformController extends ServiceObject implements Controller {
/**
* @constructor
*/
constructor(debug: Debug, config: ResolvedDebugAgentConfig) {
constructor(debug: Debug, config: ResolvedDebugAgentConfig, logger: Logger) {
super({parent: debug, baseUrl: '/controller'});

/** @private {string} */
Expand All @@ -61,10 +60,7 @@ export class OnePlatformController extends ServiceObject implements Controller {
this.running = true;

/** @private */
this.logger = consoleLogLevel({
stderr: true,
level: 'info',
});
this.logger = logger;

if (config && config.apiUrl) {
this.apiUrl = config.apiUrl + new URL(this.apiUrl).pathname;
Expand Down
8 changes: 5 additions & 3 deletions system-test/test-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {OnePlatformController} from '../src/agent/oneplatform-controller';
import {Debuggee} from '../src/debuggee';
import {Debug, PackageInfo} from '../src/client/stackdriver/debug';
import {defaultConfig as DEFAULT_CONFIG} from '../src/agent/config';
import {MockLogger} from '../test/mock-logger';

const packageInfo: PackageInfo = {
name: 'SomeName',
Expand All @@ -41,9 +42,10 @@ const debug = new Debug({}, packageInfo);

describe('Controller', function () {
this.timeout(60 * 1000);
const logger = new MockLogger();

it('should register successfully', done => {
const controller = new OnePlatformController(debug, DEFAULT_CONFIG);
const controller = new OnePlatformController(debug, DEFAULT_CONFIG, logger);
const debuggee = new Debuggee({
project: process.env.GCLOUD_PROJECT,
uniquifier: 'test-uid-' + Date.now(),
Expand All @@ -62,7 +64,7 @@ describe('Controller', function () {
});

it('should list breakpoints', done => {
const controller = new OnePlatformController(debug, DEFAULT_CONFIG);
const controller = new OnePlatformController(debug, DEFAULT_CONFIG, logger);
const debuggee = new Debuggee({
project: process.env.GCLOUD_PROJECT,
uniquifier: 'test-uid-' + Date.now(),
Expand All @@ -86,7 +88,7 @@ describe('Controller', function () {

it('should pass success on timeout', done => {
this.timeout(100000);
const controller = new OnePlatformController(debug, DEFAULT_CONFIG);
const controller = new OnePlatformController(debug, DEFAULT_CONFIG, logger);
const debuggee = new Debuggee({
project: process.env.GCLOUD_PROJECT,
uniquifier: 'test-uid-' + Date.now(),
Expand Down
63 changes: 52 additions & 11 deletions test/test-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {defaultConfig as DEFAULT_CONFIG} from '../src/agent/config';
import * as stackdriver from '../src/types/stackdriver';
import * as t from 'teeny-request'; // types only
import {teenyRequest} from 'teeny-request';
import {MockLogger} from './mock-logger';

// the tests in this file rely on the GCLOUD_PROJECT environment variable
// not being set
Expand All @@ -45,6 +46,8 @@ const api = '/v2/controller';
nock.disableNetConnect();

describe('Controller API', () => {
const logger = new MockLogger();

describe('register', () => {
it('should get a debuggeeId', done => {
const scope = nock(url)
Expand All @@ -59,7 +62,11 @@ describe('Controller API', () => {
description: 'unit test',
agentVersion,
});
const controller = new OnePlatformController(fakeDebug, DEFAULT_CONFIG);
const controller = new OnePlatformController(
fakeDebug,
DEFAULT_CONFIG,
logger
);
// TODO: Determine if this type signature is correct.
controller.register(debuggee, (err, result) => {
assert(!err, 'not expecting an error');
Expand All @@ -84,7 +91,11 @@ describe('Controller API', () => {
description: 'unit test',
agentVersion,
});
const controller = new OnePlatformController(fakeDebug, DEFAULT_CONFIG);
const controller = new OnePlatformController(
fakeDebug,
DEFAULT_CONFIG,
logger
);
// TODO: Determine if this type signature is correct.
controller.register(debuggee, (err, result) => {
assert(!err, 'not expecting an error');
Expand All @@ -108,7 +119,11 @@ describe('Controller API', () => {
description: 'unit test',
agentVersion,
});
const controller = new OnePlatformController(fakeDebug, DEFAULT_CONFIG);
const controller = new OnePlatformController(
fakeDebug,
DEFAULT_CONFIG,
logger
);
controller.register(debuggee, (err, result) => {
// TODO: Fix this incorrect method signature.
(assert as {ifError: Function}).ifError(err, 'not expecting an error');
Expand Down Expand Up @@ -136,7 +151,11 @@ describe('Controller API', () => {
description: 'unit test',
agentVersion,
});
const controller = new OnePlatformController(fakeDebug, DEFAULT_CONFIG);
const controller = new OnePlatformController(
fakeDebug,
DEFAULT_CONFIG,
logger
);
controller.register(debuggee, (err /*, result*/) => {
assert.ifError(err);
done();
Expand All @@ -149,7 +168,11 @@ describe('Controller API', () => {
.reply(200, {kind: 'whatever'});

const debuggee = {id: 'fake-debuggee'};
const controller = new OnePlatformController(fakeDebug, DEFAULT_CONFIG);
const controller = new OnePlatformController(
fakeDebug,
DEFAULT_CONFIG,
logger
);
// TODO: Fix debuggee to actually implement Debuggee
// TODO: Determine if the response parameter should be used.
controller.listBreakpoints(
Expand Down Expand Up @@ -179,7 +202,8 @@ describe('Controller API', () => {
const debuggee = {id: 'fake-debuggee'};
const controller = new OnePlatformController(
fakeDebug,
DEFAULT_CONFIG
DEFAULT_CONFIG,
logger
);
// TODO: Fix debuggee to actually implement Debuggee
// TODO: Determine if the response parameter should be used.
Expand All @@ -206,7 +230,11 @@ describe('Controller API', () => {
.reply(403);
// TODO: Fix debuggee to actually implement Debuggee
const debuggee: Debuggee = {id: 'fake-debuggee'} as Debuggee;
const controller = new OnePlatformController(fakeDebug, DEFAULT_CONFIG);
const controller = new OnePlatformController(
fakeDebug,
DEFAULT_CONFIG,
logger
);
// TODO: Determine if the response parameter should be used.
controller.listBreakpoints(debuggee, (err, response, result) => {
assert(err instanceof Error, 'expecting an error');
Expand All @@ -222,7 +250,11 @@ describe('Controller API', () => {
.reply(200, {waitExpired: true});
// TODO: Fix debuggee to actually implement Debuggee
const debuggee: Debuggee = {id: 'fake-debuggee'} as Debuggee;
const controller = new OnePlatformController(fakeDebug, DEFAULT_CONFIG);
const controller = new OnePlatformController(
fakeDebug,
DEFAULT_CONFIG,
logger
);
// TODO: Determine if the result parameter should be used.
controller.listBreakpoints(debuggee, (err, response) => {
// TODO: Fix this incorrect method signature.
Expand Down Expand Up @@ -257,7 +289,11 @@ describe('Controller API', () => {
description: 'unit test',
agentVersion,
});
const controller = new OnePlatformController(fakeDebug, DEFAULT_CONFIG);
const controller = new OnePlatformController(
fakeDebug,
DEFAULT_CONFIG,
logger
);
controller.register(debuggee, (err1 /*, response1*/) => {
assert.ifError(err1);
const debuggeeWithId: Debuggee = {id: 'fake-debuggee'} as Debuggee;
Expand Down Expand Up @@ -288,7 +324,8 @@ describe('Controller API', () => {
const debuggee: Debuggee = {id: 'fake-debuggee'} as Debuggee;
const controller = new OnePlatformController(
fakeDebug,
DEFAULT_CONFIG
DEFAULT_CONFIG,
logger
);
// TODO: Determine if the response parameter should be used.
controller.listBreakpoints(debuggee, (err, response, result) => {
Expand Down Expand Up @@ -328,7 +365,11 @@ describe('Controller API', () => {
});
// TODO: Fix debuggee to actually implement Debuggee
const debuggee: Debuggee = {id: 'fake-debuggee'} as Debuggee;
const controller = new OnePlatformController(fakeDebug, DEFAULT_CONFIG);
const controller = new OnePlatformController(
fakeDebug,
DEFAULT_CONFIG,
logger
);
controller.updateBreakpoint(
debuggee as Debuggee,
breakpoint,
Expand Down

0 comments on commit c236f35

Please sign in to comment.