Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions packages/grpc-js/src/backoff-timeout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,18 @@ export class BackoffTimeout {
this.maxDelay = options.maxDelay;
}
}
this.trace('constructed initialDelay=' + this.initialDelay + ' multiplier=' + this.multiplier + ' jitter=' + this.jitter + ' maxDelay=' + this.maxDelay);
if (this.traceEnabled) {
this.trace(
'constructed initialDelay=' +
this.initialDelay +
' multiplier=' +
this.multiplier +
' jitter=' +
this.jitter +
' maxDelay=' +
this.maxDelay
);
}
this.nextDelay = this.initialDelay;
this.timerId = setTimeout(() => {}, 0);
clearTimeout(this.timerId);
Expand All @@ -119,12 +130,24 @@ export class BackoffTimeout {
return this.nextId++;
}

private get traceEnabled(): boolean {
return logging.isTracerEnabled(TRACER_NAME);
}

private trace(text: string) {
logging.trace(LogVerbosity.DEBUG, TRACER_NAME, '{' + this.id + '} ' + text);
if (this.traceEnabled) {
logging.trace(
LogVerbosity.DEBUG,
TRACER_NAME,
'{' + this.id + '} ' + text
);
}
}

private runTimer(delay: number) {
this.trace('runTimer(delay=' + delay + ')');
if (this.traceEnabled) {
this.trace('runTimer(delay=' + delay + ')');
}
this.endTime = this.startTime;
this.endTime.setMilliseconds(
this.endTime.getMilliseconds() + delay
Expand Down Expand Up @@ -172,7 +195,9 @@ export class BackoffTimeout {
* retroactively apply that reset to the current timer.
*/
reset() {
this.trace('reset() running=' + this.running);
if (this.traceEnabled) {
this.trace('reset() running=' + this.running);
}
this.nextDelay = this.initialDelay;
if (this.running) {
const now = new Date();
Expand Down
114 changes: 71 additions & 43 deletions packages/grpc-js/src/internal-channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,12 +443,14 @@ export class InternalChannel {
this.filterStackFactory = new FilterStackFactory([
new CompressionFilterFactory(this, this.options),
]);
this.trace(
'Channel constructed with options ' +
JSON.stringify(options, undefined, 2)
);
const error = new Error();
if (isTracerEnabled('channel_stacktrace')){
if (this.traceEnabled) {
this.trace(
'Channel constructed with options ' +
JSON.stringify(options, undefined, 2)
);
}
if (isTracerEnabled('channel_stacktrace')) {
const error = new Error();
trace(
LogVerbosity.DEBUG,
'channel_stacktrace',
Expand All @@ -462,12 +464,18 @@ export class InternalChannel {
this.lastActivityTimestamp = new Date();
}

private get traceEnabled(): boolean {
return isTracerEnabled('channel');
}

private trace(text: string, verbosityOverride?: LogVerbosity) {
trace(
verbosityOverride ?? LogVerbosity.DEBUG,
'channel',
'(' + this.channelzRef.id + ') ' + uriToString(this.target) + ' ' + text
);
if (this.traceEnabled) {
trace(
verbosityOverride ?? LogVerbosity.DEBUG,
'channel',
'(' + this.channelzRef.id + ') ' + uriToString(this.target) + ' ' + text
);
}
}

private callRefTimerRef() {
Expand All @@ -476,25 +484,29 @@ export class InternalChannel {
}
// If the hasRef function does not exist, always run the code
if (!this.callRefTimer.hasRef?.()) {
this.trace(
'callRefTimer.ref | configSelectionQueue.length=' +
this.configSelectionQueue.length +
' pickQueue.length=' +
this.pickQueue.length
);
if (this.traceEnabled) {
this.trace(
'callRefTimer.ref | configSelectionQueue.length=' +
this.configSelectionQueue.length +
' pickQueue.length=' +
this.pickQueue.length
);
}
this.callRefTimer.ref?.();
}
}

private callRefTimerUnref() {
// If the timer or the hasRef function does not exist, always run the code
if (!this.callRefTimer?.hasRef || this.callRefTimer.hasRef()) {
this.trace(
'callRefTimer.unref | configSelectionQueue.length=' +
this.configSelectionQueue.length +
' pickQueue.length=' +
this.pickQueue.length
);
if (this.traceEnabled) {
this.trace(
'callRefTimer.unref | configSelectionQueue.length=' +
this.configSelectionQueue.length +
' pickQueue.length=' +
this.pickQueue.length
);
}
this.callRefTimer?.unref?.();
}
}
Expand Down Expand Up @@ -681,20 +693,27 @@ export class InternalChannel {
method: string,
host: string,
credentials: CallCredentials,
deadline: Deadline
deadline: Deadline,
callNumber?: number
): LoadBalancingCall {
const callNumber = getNextCallNumber();
this.trace(
'createLoadBalancingCall [' + callNumber + '] method="' + method + '"'
);
const finalCallNumber = callNumber ?? getNextCallNumber();
if (this.traceEnabled) {
this.trace(
'createLoadBalancingCall [' +
finalCallNumber +
'] method="' +
method +
'"'
);
}
return new LoadBalancingCall(
this,
callConfig,
method,
host,
credentials,
deadline,
callNumber
finalCallNumber
);
}

Expand All @@ -703,20 +722,27 @@ export class InternalChannel {
method: string,
host: string,
credentials: CallCredentials,
deadline: Deadline
deadline: Deadline,
callNumber?: number
): RetryingCall {
const callNumber = getNextCallNumber();
this.trace(
'createRetryingCall [' + callNumber + '] method="' + method + '"'
);
const finalCallNumber = callNumber ?? getNextCallNumber();
if (this.traceEnabled) {
this.trace(
'createRetryingCall [' +
finalCallNumber +
'] method="' +
method +
'"'
);
}
return new RetryingCall(
this,
callConfig,
method,
host,
credentials,
deadline,
callNumber,
finalCallNumber,
this.retryBufferTracker,
RETRY_THROTTLER_MAP.get(this.getTarget())
);
Expand All @@ -730,14 +756,16 @@ export class InternalChannel {
propagateFlags: number | null | undefined
): ResolvingCall {
const callNumber = getNextCallNumber();
this.trace(
'createResolvingCall [' +
callNumber +
'] method="' +
method +
'", deadline=' +
deadlineToString(deadline)
);
if (this.traceEnabled) {
this.trace(
'createResolvingCall [' +
callNumber +
'] method="' +
method +
'", deadline=' +
deadlineToString(deadline)
);
}
const finalOptions: CallStreamOptions = {
deadline: deadline,
flags: propagateFlags ?? Propagate.DEFAULTS,
Expand Down
Loading