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,
|
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, {})
|
||||||
);
|
);
|
||||||
|
|
|
@ -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, {})
|
||||||
);
|
);
|
||||||
|
|
|
@ -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
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -516,7 +525,7 @@ export class Subchannel {
|
||||||
ref() {
|
ref() {
|
||||||
trace(
|
trace(
|
||||||
this.subchannelAddressString +
|
this.subchannelAddressString +
|
||||||
' callRefcount ' +
|
' refcount ' +
|
||||||
this.refcount +
|
this.refcount +
|
||||||
' -> ' +
|
' -> ' +
|
||||||
(this.refcount + 1)
|
(this.refcount + 1)
|
||||||
|
@ -527,7 +536,7 @@ export class Subchannel {
|
||||||
unref() {
|
unref() {
|
||||||
trace(
|
trace(
|
||||||
this.subchannelAddressString +
|
this.subchannelAddressString +
|
||||||
' callRefcount ' +
|
' refcount ' +
|
||||||
this.refcount +
|
this.refcount +
|
||||||
' -> ' +
|
' -> ' +
|
||||||
(this.refcount - 1)
|
(this.refcount - 1)
|
||||||
|
|
Loading…
Reference in New Issue