Merge pull request #1267 from murgatroid99/grpc-js_tracing_improvements

grpc-js: Fix a trace line, and add a few new ones
This commit is contained in:
Michael Lumish 2020-02-20 10:30:30 -08:00 committed by GitHub
commit b46d0f1db5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 8 deletions

View File

@ -34,6 +34,7 @@ import {
Subchannel,
ConnectivityStateListener,
SubchannelAddress,
subchannelAddressToString,
} from './subchannel';
import * as logging from './logging';
import { LogVerbosity } from './constants';
@ -335,7 +336,12 @@ export class PickFirstLoadBalancer implements LoadBalancer {
*/
private connectToAddressList(): void {
this.resetSubchannelList();
trace('Connect to address list ' + this.latestAddressList);
trace(
'Connect to address list ' +
this.latestAddressList.map(address =>
subchannelAddressToString(address)
)
);
this.subchannels = this.latestAddressList.map(address =>
this.channelControlHelper.createSubchannel(address, {})
);

View File

@ -34,7 +34,16 @@ import {
Subchannel,
ConnectivityStateListener,
SubchannelAddress,
subchannelAddressToString,
} from './subchannel';
import * as logging from './logging';
import { LogVerbosity } from './constants';
const TRACER_NAME = 'round_robin';
function trace(text: string): void {
logging.trace(LogVerbosity.DEBUG, TRACER_NAME, text);
}
const TYPE_NAME = 'round_robin';
@ -147,6 +156,11 @@ export class RoundRobinLoadBalancer implements LoadBalancer {
}
private updateState(newState: ConnectivityState, picker: Picker) {
trace(
ConnectivityState[this.currentState] +
' -> ' +
ConnectivityState[newState]
);
if (newState === ConnectivityState.READY) {
this.currentReadyPicker = picker as RoundRobinPicker;
} else {
@ -176,6 +190,10 @@ export class RoundRobinLoadBalancer implements LoadBalancer {
lbConfig: LoadBalancingConfig | null
): void {
this.resetSubchannelList();
trace(
'Connect to address list ' +
addressList.map(address => subchannelAddressToString(address))
);
this.subchannels = addressList.map(address =>
this.channelControlHelper.createSubchannel(address, {})
);

View File

@ -112,6 +112,14 @@ export function subchannelAddressEqual(
}
}
export function subchannelAddressToString(address: SubchannelAddress): string {
if (isTcpSubchannelAddress(address)) {
return address.host + ':' + address.port;
} else {
return address.path;
}
}
export class Subchannel {
/**
* The subchannel's current connectivity state. Invariant: `session` === `null`
@ -231,11 +239,7 @@ export class Subchannel {
);
}
}, backoffOptions);
if (isTcpSubchannelAddress(subchannelAddress)) {
this.subchannelAddressString = `${subchannelAddress.host}:${subchannelAddress.port}`;
} else {
this.subchannelAddressString = `${subchannelAddress.path}`;
}
this.subchannelAddressString = subchannelAddressToString(subchannelAddress);
}
/**
@ -390,6 +394,11 @@ export class Subchannel {
session.once('error', error => {
/* Do nothing here. Any error should also trigger a close event, which is
* where we want to handle that. */
trace(
this.subchannelAddressString +
' connection closed with error ' +
(error as Error).message
);
});
}
@ -516,7 +525,7 @@ export class Subchannel {
ref() {
trace(
this.subchannelAddressString +
' callRefcount ' +
' refcount ' +
this.refcount +
' -> ' +
(this.refcount + 1)
@ -527,7 +536,7 @@ export class Subchannel {
unref() {
trace(
this.subchannelAddressString +
' callRefcount ' +
' refcount ' +
this.refcount +
' -> ' +
(this.refcount - 1)