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 }
): 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(

View File

@ -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);
}

View File

@ -261,7 +261,6 @@ class EdsState implements XdsStreamState<ClusterLoadAssignment__Output> {
edsServiceName: string,
watcher: Watcher<ClusterLoadAssignment__Output>
): 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<ClusterLoadAssignment__Output> {
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<ClusterLoadAssignment__Output> {
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) {