mirror of https://github.com/grpc/grpc-node.git
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:
commit
b46d0f1db5
|
@ -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, {})
|
||||
);
|
||||
|
|
|
@ -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, {})
|
||||
);
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue