grpc-js: xds: Add more logging around adding and removing eds and cds watchers

This commit is contained in:
Michael Lumish 2020-10-05 11:27:18 -07:00
parent a5cc154c8e
commit 73d3c307c9
3 changed files with 11 additions and 4 deletions

View File

@ -111,14 +111,14 @@ export class CdsLoadBalancer implements LoadBalancer {
attributes: { [key: string]: unknown } attributes: { [key: string]: unknown }
): void { ): void {
if (!isCdsLoadBalancingConfig(lbConfig)) { if (!isCdsLoadBalancingConfig(lbConfig)) {
trace('Discarding address list update with unrecognized config ' + JSON.stringify(lbConfig)); trace('Discarding address list update with unrecognized config ' + JSON.stringify(lbConfig, undefined, 2));
return; return;
} }
if (!(attributes.xdsClient instanceof XdsClient)) { if (!(attributes.xdsClient instanceof XdsClient)) {
trace('Discarding address list update missing xdsClient attribute'); trace('Discarding address list update missing xdsClient attribute');
return; return;
} }
trace('Received update with config ' + JSON.stringify(lbConfig)); trace('Received update with config ' + JSON.stringify(lbConfig, undefined, 2));
this.xdsClient = attributes.xdsClient; this.xdsClient = attributes.xdsClient;
this.latestAttributes = attributes; this.latestAttributes = attributes;
@ -128,6 +128,7 @@ export class CdsLoadBalancer implements LoadBalancer {
this.isWatcherActive && this.isWatcherActive &&
this.latestConfig?.cds.cluster !== lbConfig.cds.cluster this.latestConfig?.cds.cluster !== lbConfig.cds.cluster
) { ) {
trace('Removing old cluster watcher for cluster name ' + this.latestConfig!.cds.cluster);
this.xdsClient.removeClusterWatcher( this.xdsClient.removeClusterWatcher(
this.latestConfig!.cds.cluster, this.latestConfig!.cds.cluster,
this.watcher this.watcher
@ -143,6 +144,7 @@ export class CdsLoadBalancer implements LoadBalancer {
this.latestConfig = lbConfig; this.latestConfig = lbConfig;
if (!this.isWatcherActive) { if (!this.isWatcherActive) {
trace('Adding new cluster watcher for cluster name ' + lbConfig.cds.cluster);
this.xdsClient.addClusterWatcher(lbConfig.cds.cluster, this.watcher); this.xdsClient.addClusterWatcher(lbConfig.cds.cluster, this.watcher);
this.isWatcherActive = true; this.isWatcherActive = true;
} }
@ -154,6 +156,7 @@ export class CdsLoadBalancer implements LoadBalancer {
this.childBalancer.resetBackoff(); this.childBalancer.resetBackoff();
} }
destroy(): void { destroy(): void {
trace('Destroying load balancer with cluster name ' + this.latestConfig?.cds.cluster);
this.childBalancer.destroy(); this.childBalancer.destroy();
if (this.isWatcherActive) { if (this.isWatcherActive) {
this.xdsClient?.removeClusterWatcher( this.xdsClient?.removeClusterWatcher(

View File

@ -401,7 +401,7 @@ export class EdsLoadBalancer implements LoadBalancer {
trace('Discarding address list update missing xdsClient attribute'); trace('Discarding address list update missing xdsClient attribute');
return; return;
} }
trace('Received update with config: ' + JSON.stringify(lbConfig)); trace('Received update with config: ' + JSON.stringify(lbConfig, undefined, 2));
this.lastestConfig = lbConfig; this.lastestConfig = lbConfig;
this.latestAttributes = attributes; this.latestAttributes = attributes;
this.xdsClient = attributes.xdsClient; this.xdsClient = attributes.xdsClient;
@ -411,6 +411,7 @@ export class EdsLoadBalancer implements LoadBalancer {
/* If the name is changing, disable the old watcher before adding the new /* If the name is changing, disable the old watcher before adding the new
* one */ * one */
if (this.isWatcherActive && this.edsServiceName !== newEdsServiceName) { if (this.isWatcherActive && this.edsServiceName !== newEdsServiceName) {
trace('Removing old endpoint watcher for edsServiceName ' + this.edsServiceName)
this.xdsClient.removeEndpointWatcher(this.edsServiceName!, this.watcher); this.xdsClient.removeEndpointWatcher(this.edsServiceName!, this.watcher);
/* Setting isWatcherActive to false here lets us have one code path for /* Setting isWatcherActive to false here lets us have one code path for
* calling addEndpointWatcher */ * calling addEndpointWatcher */
@ -423,6 +424,7 @@ export class EdsLoadBalancer implements LoadBalancer {
this.edsServiceName = newEdsServiceName; this.edsServiceName = newEdsServiceName;
if (!this.isWatcherActive) { if (!this.isWatcherActive) {
trace('Adding new endpoint watcher for edsServiceName ' + this.edsServiceName);
this.xdsClient.addEndpointWatcher(this.edsServiceName, this.watcher); this.xdsClient.addEndpointWatcher(this.edsServiceName, this.watcher);
this.isWatcherActive = true; this.isWatcherActive = true;
} }
@ -447,6 +449,7 @@ export class EdsLoadBalancer implements LoadBalancer {
this.childBalancer.resetBackoff(); this.childBalancer.resetBackoff();
} }
destroy(): void { destroy(): void {
trace('Destroying load balancer with edsServiceName ' + this.edsServiceName);
if (this.edsServiceName) { if (this.edsServiceName) {
this.xdsClient?.removeEndpointWatcher(this.edsServiceName, this.watcher); this.xdsClient?.removeEndpointWatcher(this.edsServiceName, this.watcher);
} }

View File

@ -261,7 +261,6 @@ class EdsState implements XdsStreamState<ClusterLoadAssignment__Output> {
edsServiceName: string, edsServiceName: string,
watcher: Watcher<ClusterLoadAssignment__Output> watcher: Watcher<ClusterLoadAssignment__Output>
): void { ): void {
trace('Adding EDS watcher for edsServiceName ' + edsServiceName);
let watchersEntry = this.watchers.get(edsServiceName); let watchersEntry = this.watchers.get(edsServiceName);
let addedServiceName = false; let addedServiceName = false;
if (watchersEntry === undefined) { if (watchersEntry === undefined) {
@ -269,6 +268,7 @@ class EdsState implements XdsStreamState<ClusterLoadAssignment__Output> {
watchersEntry = []; watchersEntry = [];
this.watchers.set(edsServiceName, watchersEntry); this.watchers.set(edsServiceName, watchersEntry);
} }
trace('Adding EDS watcher (' + watchersEntry.length + ' ->' + (watchersEntry.length + 1) + ') for edsServiceName ' + edsServiceName);
watchersEntry.push(watcher); watchersEntry.push(watcher);
/* If we have already received an update for the requested edsServiceName, /* If we have already received an update for the requested edsServiceName,
@ -298,6 +298,7 @@ class EdsState implements XdsStreamState<ClusterLoadAssignment__Output> {
if (watchersEntry !== undefined) { if (watchersEntry !== undefined) {
const entryIndex = watchersEntry.indexOf(watcher); const entryIndex = watchersEntry.indexOf(watcher);
if (entryIndex >= 0) { if (entryIndex >= 0) {
trace('Removed EDS watcher (' + watchersEntry.length + ' -> ' + (watchersEntry.length - 1) + ') for edsServiceName ' + edsServiceName);
watchersEntry.splice(entryIndex, 1); watchersEntry.splice(entryIndex, 1);
} }
if (watchersEntry.length === 0) { if (watchersEntry.length === 0) {