Fix a trace line, and add a few new ones

This commit is contained in:
murgatroid99 2020-02-18 17:17:19 -08:00
parent b68ffb20c6
commit 439263d4e1
3 changed files with 39 additions and 6 deletions

View File

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

View File

@ -34,7 +34,16 @@ import {
Subchannel, Subchannel,
ConnectivityStateListener, ConnectivityStateListener,
SubchannelAddress, SubchannelAddress,
subchannelAddressToString,
} from './subchannel'; } 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'; const TYPE_NAME = 'round_robin';
@ -147,6 +156,11 @@ export class RoundRobinLoadBalancer implements LoadBalancer {
} }
private updateState(newState: ConnectivityState, picker: Picker) { private updateState(newState: ConnectivityState, picker: Picker) {
trace(
ConnectivityState[this.currentState] +
' -> ' +
ConnectivityState[newState]
);
if (newState === ConnectivityState.READY) { if (newState === ConnectivityState.READY) {
this.currentReadyPicker = picker as RoundRobinPicker; this.currentReadyPicker = picker as RoundRobinPicker;
} else { } else {
@ -176,6 +190,10 @@ export class RoundRobinLoadBalancer implements LoadBalancer {
lbConfig: LoadBalancingConfig | null lbConfig: LoadBalancingConfig | null
): void { ): void {
this.resetSubchannelList(); this.resetSubchannelList();
trace(
'Connect to address list ' +
addressList.map(address => subchannelAddressToString(address))
);
this.subchannels = addressList.map(address => this.subchannels = addressList.map(address =>
this.channelControlHelper.createSubchannel(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 { export class Subchannel {
/** /**
* The subchannel's current connectivity state. Invariant: `session` === `null` * The subchannel's current connectivity state. Invariant: `session` === `null`
@ -231,11 +239,7 @@ export class Subchannel {
); );
} }
}, backoffOptions); }, backoffOptions);
if (isTcpSubchannelAddress(subchannelAddress)) { this.subchannelAddressString = subchannelAddressToString(subchannelAddress);
this.subchannelAddressString = `${subchannelAddress.host}:${subchannelAddress.port}`;
} else {
this.subchannelAddressString = `${subchannelAddress.path}`;
}
} }
/** /**
@ -390,6 +394,11 @@ export class Subchannel {
session.once('error', error => { session.once('error', error => {
/* Do nothing here. Any error should also trigger a close event, which is /* Do nothing here. Any error should also trigger a close event, which is
* where we want to handle that. */ * where we want to handle that. */
trace(
this.subchannelAddressString +
' connection closed with error ' +
(error as Error).message
);
}); });
} }