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

Commit 2d07105

Browse files
authored
tune up configuration types (#300)
1 parent 9eb42e6 commit 2d07105

File tree

6 files changed

+94
-119
lines changed

6 files changed

+94
-119
lines changed

src/agent/config.ts

Lines changed: 42 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -14,207 +14,158 @@
1414
* limitations under the License.
1515
*/
1616

17-
/**
18-
* @typedef {object} DebugAgentConfig
19-
*/
20-
export interface DebugAgentConfig {
21-
/**
22-
* @property {?string}
23-
* @memberof DebugAgentConfig
24-
* @default
25-
*/
17+
import {AuthenticationConfig} from '../types/common-types';
18+
19+
export interface DebugAgentConfig extends AuthenticationConfig {
2620
workingDirectory: string|null;
2721

2822
/**
29-
* @property {?string} A user specified way of identifying the service
30-
* that the debug agent is monitoring.
31-
* @memberof DebugAgentConfig
32-
* @default
23+
* A user specified way of identifying the service
3324
*/
3425
description: string|null;
3526

3627
/**
37-
* @property {boolean} Whether or not it is permitted to evaluate expressions.
28+
* Whether or not it is permitted to evaluate expressions.
3829
* Locals and arguments are not displayed and watch expressions and
3930
* conditions are dissallowed when this is `false`.
40-
* @memberof DebugAgentConfig
41-
* @default
4231
*/
4332
allowExpressions: boolean;
4433

4534
/**
46-
* @property {object} Identifies the context of the running service -
35+
* Identifies the context of the running service -
4736
* [ServiceContext](https://cloud.google.com/error-reporting/reference/rest/v1beta1/ServiceContext?authuser=2).
4837
* This information is utilized in the UI to identify all the running
4938
* instances of your service. This is discovered automatically when your
5039
* application is running on Google Cloud Platform. You may optionally
5140
* choose to provide this information yourself to identify your service
5241
* differently from the default mechanism.
53-
* @memberof DebugAgentConfig
54-
* @default
5542
*/
5643
serviceContext: {
5744
/**
58-
* @property {?string} the service name
59-
* @default
45+
* The service name.
6046
*/
6147
service: string | null;
6248

6349
/**
64-
* @property {?string} the service version
65-
* @default
50+
* The service version.
6651
*/
6752
version: string | null;
6853

6954
/**
70-
* @property {?string} a unique deployment identifier. This is used
71-
* internally only.
72-
* @private
55+
* A unique deployment identifier. This is used internally only.
7356
*/
7457
minorVersion_: string | null;
7558
};
7659

7760
/**
78-
* @property {?string} The path within your repository to the directory
61+
* The path within your repository to the directory
7962
* containing the package.json for your deployed application. This should
8063
* be provided if your deployed application appears as a subdirectory of
8164
* your repository. Usually this is unnecessary, but may be useful in
8265
* cases where the debug agent is unable to resolve breakpoint locations
8366
* unambiguously.
84-
* @memberof DebugAgentConfig
85-
* @default
8667
*/
8768
appPathRelativeToRepository: string|null;
8869

8970
/**
90-
* @property {number} agent log level 0-disabled, 1-error, 2-warn, 3-info,
91-
* 4-debug
92-
* @memberof DebugAgentConfig
93-
* @default
71+
* agent log level 0-disabled, 1-error, 2-warn, 3-info, 4-debug
9472
*/
9573
logLevel: number;
9674

9775
/**
98-
* @property {number} How frequently should the list of breakpoints be
99-
* refreshed from the cloud debug server.
100-
* @memberof DebugAgentConfig
101-
* @default
76+
* How frequently should the list of breakpoints be refreshed from the cloud
77+
* debug server.
10278
*/
10379
breakpointUpdateIntervalSec: number;
10480

10581
/**
106-
* @property {number} breakpoints and logpoints older than this number of
107-
* seconds will be expired on the server.
108-
* @memberof DebugAgentConfig
109-
* @default
82+
* breakpoints and logpoints older than this number of seconds will be expired
83+
* on the server.
11084
*/
11185
breakpointExpirationSec: number;
11286

11387
/**
114-
* @property {object} configuration options on what is captured on a
115-
* snapshot.
116-
* @memberof DebugAgentConfig
88+
* configuration options on what is captured on a snapshot.
11789
*/
11890
capture: {
11991
/**
120-
* @property {boolean} Whether to include details about stack frames
121-
* belonging to node-core.
122-
* @default
92+
* Whether to include details about stack frames belonging to node-core.
12393
*/
12494
includeNodeModules: boolean;
12595

126-
12796
/**
128-
* @property {number} Maximum number of stack frames to capture data for.
129-
* The limit is aimed to reduce overall capture time.
130-
* @default
97+
* Maximum number of stack frames to capture data for. The limit is aimed to
98+
* reduce overall capture time.
13199
*/
132100
maxFrames: number;
133101

134102
/**
135-
* @property {number} We collect locals and arguments on a few top frames.
136-
* For the rest only collect the source location
137-
* @default
103+
* We collect locals and arguments on a few top frames. For the rest only
104+
* collect the source location
138105
*/
139106
maxExpandFrames: number;
140107

141108
/**
142-
* @property {number} To reduce the overall capture time, limit the number
143-
* of properties gathered on large objects. A value of 0 disables the
144-
* limit.
145-
* @default
109+
* To reduce the overall capture time, limit the number of properties
110+
* gathered on large objects. A value of 0 disables the limit.
146111
*/
147112
maxProperties: number;
148113

149114
/**
150-
* @property {number} Total 'size' of data to gather. This is NOT the
151-
* number of bytes of data that are sent over the wire, but instead a
152-
* very very coarse approximation based on the length of names and
153-
* values of the properties. This should be somewhat proportional to the
154-
* amount of processing needed to capture the data and subsequently the
155-
* network traffic. A value of 0 disables the limit.
156-
* @default
115+
* Total 'size' of data to gather. This is NOT the number of bytes of data
116+
* that are sent over the wire, but instead a very very coarse approximation
117+
* based on the length of names and values of the properties. This should be
118+
* somewhat proportional to the amount of processing needed to capture the
119+
* data and subsequently the network traffic. A value of 0 disables the
120+
* limit.
157121
*/
158122
maxDataSize: number;
159123

160124
/**
161-
* @property {number} To limit the size of the buffer, we truncate long
162-
* strings. A value of 0 disables truncation.
163-
* @default
125+
* To limit the size of the buffer, we truncate long strings. A value of 0
126+
* disables truncation.
164127
*/
165128
maxStringLength: number;
166129
};
167130

168131
/**
169-
* @property {object} options affecting log points.
170-
* @memberof DebugAgentConfig
132+
* options affecting log points.
171133
*/
172134
log: {
173135
/**
174-
* @property {number} The maximum number of logs to record per second per
175-
* logpoint.
176-
* @memberof DebugAgentConfig
177-
* @default
136+
* The maximum number of logs to record per second per logpoint.
178137
*/
179138
maxLogsPerSecond: number;
180139

181140
/**
182-
* @property {number} Number of seconds to wait after the
183-
* `maxLogsPerSecond` rate is hit before logging resumes per logpoint.
184-
* @default
141+
* Number of seconds to wait after the `maxLogsPerSecond` rate is hit before
142+
* logging resumes per logpoint.
185143
*/
186144
logDelaySeconds: number;
187145
};
188146

189147
/**
190-
* @property {object} These configuration options are for internal
191-
* experimentation only.
192-
* @memberof DebugAgentConfig
193-
* @private
148+
* These configuration options are for internal experimentation only.
194149
*/
195150
internal: {
196-
// TODO: Determine if clang-format can be configured to place
197-
// a newline between these two statements.
198151
registerDelayOnFetcherErrorSec: number; maxRegistrationRetryDelay: number;
199152
};
200153

201154
/**
202-
* @property {boolean} Used by tests to force loading of a new agent if one
203-
* exists already
204-
* @memberof DebugAgentConfig
205-
* @private
155+
* Used by tests to force loading of a new agent if one exists already
206156
*/
207157
forceNewAgent_: boolean;
208158

209159
/**
210-
* @property {boolean} Uses by tests to cause the start() function to return
211-
* the debuglet.
212-
* @memberof DebugAgentConfig
213-
* @private
160+
* Uses by tests to cause the start() function to return the debuglet.
214161
*/
215162
testMode_: boolean;
216163
}
217164

165+
export interface StackdriverConfig extends AuthenticationConfig {
166+
debug?: DebugAgentConfig;
167+
}
168+
218169
const defaultConfig: DebugAgentConfig = {
219170
// FIXME(ofrobots): presently this is dependent what cwd() is at the time this
220171
// file is first required. We should make the default config static.

src/agent/debuglet.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,8 @@ export class Debuglet extends EventEmitter {
392392
// named `response`) is not used.
393393
metadata.project(
394394
'project-id',
395-
function(err: Error, _res: http.ServerResponse, metadataProject: string) {
395+
function(
396+
err: Error, _res: http.ServerResponse, metadataProject: string) {
396397
// We should get an error if we are not on GCP.
397398
const onGCP = !err;
398399

src/agent/scanner.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,13 @@ function findFiles(
207207
return;
208208
});
209209

210-
find.on('directory', function(dir: string, _ignore: fs.Stats, stop: () => void) {
211-
const base = path.basename(dir);
212-
if (base === '.git' || base === 'node_modules') {
213-
stop(); // do not descend
214-
}
215-
});
210+
find.on(
211+
'directory', function(dir: string, _ignore: fs.Stats, stop: () => void) {
212+
const base = path.basename(dir);
213+
if (base === '.git' || base === 'node_modules') {
214+
stop(); // do not descend
215+
}
216+
});
216217

217218
find.on('file', function(file: string) {
218219
if (regex.test(file)) {

src/debug.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
* limitations under the License.
1515
*/
1616

17-
import {AuthOptions, Common} from './types/common-types';
17+
import {AuthenticationConfig, Common} from './types/common-types';
1818
export const common: Common = require('@google-cloud/common');
1919

2020
export class Debug extends common.Service {
21-
options: AuthOptions;
21+
options: AuthenticationConfig;
2222

2323
/**
2424
* <p class="notice">
@@ -41,9 +41,9 @@ export class Debug extends common.Service {
4141
* @resource [What is Stackdriver Debug]{@link
4242
* https://cloud.google.com/debug/}
4343
*
44-
* @param {object} options - [Configuration object](#/docs)
44+
* @param options - [Authentication options](#/docs)
4545
*/
46-
constructor(options: AuthOptions) {
46+
constructor(options: AuthenticationConfig) {
4747
if (new.target !== Debug) {
4848
options = common.util.normalizeArguments(null, options);
4949
return new Debug(options);

src/index.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@
1414
* limitations under the License.
1515
*/
1616

17-
import {DebugAgentConfig} from './agent/config';
17+
import {DebugAgentConfig, StackdriverConfig} from './agent/config';
1818
import {Debuglet} from './agent/debuglet';
1919
import {Debug} from './debug';
20-
import {AuthOptions} from './types/common-types';
2120

2221
// Singleton.
2322
let debuglet: Debuglet;
@@ -26,31 +25,26 @@ let debuglet: Debuglet;
2625
* Start the Debug agent that will make your application available for debugging
2726
* with Stackdriver Debug.
2827
*
29-
* @param {object=} options - Options
30-
* @param {object=} options.debugAgent - Debug agent configuration
31-
* TODO: add an optional callback function.
28+
* @param options - Authentication and agent configuration.
3229
*
3330
* @resource [Introductory video]{@link
3431
* https://www.youtube.com/watch?v=tyHcK_kAOpw}
3532
*
3633
* @example
3734
* debug.startAgent();
3835
*/
39-
export function start(options: DebugAgentConfig|
40-
{debug?: DebugAgentConfig}): Debuglet|undefined {
36+
export function start(options: DebugAgentConfig|StackdriverConfig): Debuglet|
37+
undefined {
4138
options = options || {};
42-
// TODO: Update the documentation to specify that the options object
43-
// contains a `debug` attribute and not a `debugAgent` object.
44-
// TODO: Determine how to remove this cast to `any`.
45-
const agentConfig = (options as any).debug || options;
39+
const agentConfig: DebugAgentConfig =
40+
(options as StackdriverConfig).debug || (options as DebugAgentConfig);
4641

4742
// forceNewAgent_ is for testing purposes only.
4843
if (debuglet && !agentConfig.forceNewAgent_) {
4944
throw new Error('Debug Agent has already been started');
5045
}
5146

52-
// TODO: Determine how to remove this cast to `AuthOptions`.
53-
const debug = new Debug(options as AuthOptions);
47+
const debug = new Debug(options);
5448
debuglet = new Debuglet(debug, agentConfig);
5549
debuglet.start();
5650

0 commit comments

Comments
 (0)