diff --git a/packages/grpc-js/src/load-balancer-cds.ts b/packages/grpc-js/src/load-balancer-cds.ts index 71a72c89..15c55ed8 100644 --- a/packages/grpc-js/src/load-balancer-cds.ts +++ b/packages/grpc-js/src/load-balancer-cds.ts @@ -111,14 +111,14 @@ export class CdsLoadBalancer implements LoadBalancer { attributes: { [key: string]: unknown } ): void { 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; } if (!(attributes.xdsClient instanceof XdsClient)) { trace('Discarding address list update missing xdsClient attribute'); return; } - trace('Received update with config ' + JSON.stringify(lbConfig)); + trace('Received update with config ' + JSON.stringify(lbConfig, undefined, 2)); this.xdsClient = attributes.xdsClient; this.latestAttributes = attributes; @@ -128,6 +128,7 @@ export class CdsLoadBalancer implements LoadBalancer { this.isWatcherActive && this.latestConfig?.cds.cluster !== lbConfig.cds.cluster ) { + trace('Removing old cluster watcher for cluster name ' + this.latestConfig!.cds.cluster); this.xdsClient.removeClusterWatcher( this.latestConfig!.cds.cluster, this.watcher @@ -143,6 +144,7 @@ export class CdsLoadBalancer implements LoadBalancer { this.latestConfig = lbConfig; if (!this.isWatcherActive) { + trace('Adding new cluster watcher for cluster name ' + lbConfig.cds.cluster); this.xdsClient.addClusterWatcher(lbConfig.cds.cluster, this.watcher); this.isWatcherActive = true; } @@ -154,6 +156,7 @@ export class CdsLoadBalancer implements LoadBalancer { this.childBalancer.resetBackoff(); } destroy(): void { + trace('Destroying load balancer with cluster name ' + this.latestConfig?.cds.cluster); this.childBalancer.destroy(); if (this.isWatcherActive) { this.xdsClient?.removeClusterWatcher( diff --git a/packages/grpc-js/src/load-balancer-eds.ts b/packages/grpc-js/src/load-balancer-eds.ts index 902b28b5..9080a2f4 100644 --- a/packages/grpc-js/src/load-balancer-eds.ts +++ b/packages/grpc-js/src/load-balancer-eds.ts @@ -401,7 +401,7 @@ export class EdsLoadBalancer implements LoadBalancer { trace('Discarding address list update missing xdsClient attribute'); return; } - trace('Received update with config: ' + JSON.stringify(lbConfig)); + trace('Received update with config: ' + JSON.stringify(lbConfig, undefined, 2)); this.lastestConfig = lbConfig; this.latestAttributes = attributes; 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 * one */ if (this.isWatcherActive && this.edsServiceName !== newEdsServiceName) { + trace('Removing old endpoint watcher for edsServiceName ' + this.edsServiceName) this.xdsClient.removeEndpointWatcher(this.edsServiceName!, this.watcher); /* Setting isWatcherActive to false here lets us have one code path for * calling addEndpointWatcher */ @@ -423,6 +424,7 @@ export class EdsLoadBalancer implements LoadBalancer { this.edsServiceName = newEdsServiceName; if (!this.isWatcherActive) { + trace('Adding new endpoint watcher for edsServiceName ' + this.edsServiceName); this.xdsClient.addEndpointWatcher(this.edsServiceName, this.watcher); this.isWatcherActive = true; } @@ -447,6 +449,7 @@ export class EdsLoadBalancer implements LoadBalancer { this.childBalancer.resetBackoff(); } destroy(): void { + trace('Destroying load balancer with edsServiceName ' + this.edsServiceName); if (this.edsServiceName) { this.xdsClient?.removeEndpointWatcher(this.edsServiceName, this.watcher); } diff --git a/packages/grpc-js/src/xds-client.ts b/packages/grpc-js/src/xds-client.ts index 8ca4cfa2..8b4d5d3b 100644 --- a/packages/grpc-js/src/xds-client.ts +++ b/packages/grpc-js/src/xds-client.ts @@ -261,7 +261,6 @@ class EdsState implements XdsStreamState { edsServiceName: string, watcher: Watcher ): void { - trace('Adding EDS watcher for edsServiceName ' + edsServiceName); let watchersEntry = this.watchers.get(edsServiceName); let addedServiceName = false; if (watchersEntry === undefined) { @@ -269,6 +268,7 @@ class EdsState implements XdsStreamState { watchersEntry = []; this.watchers.set(edsServiceName, watchersEntry); } + trace('Adding EDS watcher (' + watchersEntry.length + ' ->' + (watchersEntry.length + 1) + ') for edsServiceName ' + edsServiceName); watchersEntry.push(watcher); /* If we have already received an update for the requested edsServiceName, @@ -298,6 +298,7 @@ class EdsState implements XdsStreamState { if (watchersEntry !== undefined) { const entryIndex = watchersEntry.indexOf(watcher); if (entryIndex >= 0) { + trace('Removed EDS watcher (' + watchersEntry.length + ' -> ' + (watchersEntry.length - 1) + ') for edsServiceName ' + edsServiceName); watchersEntry.splice(entryIndex, 1); } if (watchersEntry.length === 0) {