grpc-js-xds: Implement updated xds dependency manager watcher API

This commit is contained in:
Michael Lumish 2025-03-13 14:31:52 -07:00
parent 4f0610338f
commit 9e35cacfe5
2 changed files with 46 additions and 25 deletions

View File

@ -132,18 +132,13 @@ class XdsResolver implements Resolver {
this.xdsClient = getSingletonXdsClient(); this.xdsClient = getSingletonXdsClient();
} }
this.xdsConfigWatcher = { this.xdsConfigWatcher = {
onUpdate: xdsConfig => { onUpdate: maybeXdsConfig => {
this.handleXdsConfig(xdsConfig); if (maybeXdsConfig.success) {
}, this.handleXdsConfig(maybeXdsConfig.value);
onError: (context, status) => { } else {
trace('Resolution error for target ' + uriToString(this.target) + ' due to xDS client transient error retrieving ' + context + ': ' + status.details); // This should be in the resolution_note once that is implemented
this.reportResolutionError(`Error retrieving resource ${context}: ${status.details}`); this.reportResolutionError(`Resolution error for target ${uriToString(this.target)}: ${maybeXdsConfig.error.details}`);
}, }
onResourceDoesNotExist: context => {
trace('Resolution error for target ' + uriToString(this.target) + ': ' + context + ' does not exist');
/* Return an empty endpoint list and service config, to explicitly
* invalidate any previously returned service config */
this.listener.onSuccessfulResolution([], null, null, null, {});
} }
} }
} }

View File

@ -96,9 +96,7 @@ export interface XdsConfig {
} }
export interface XdsConfigWatcher { export interface XdsConfigWatcher {
onUpdate(xdsConfig: XdsConfig): void; onUpdate(xdsConfig: StatusOr<XdsConfig>): void;
onError(context: string, status: StatusObject): void;
onResourceDoesNotExist(context: string): void;
} }
interface AggregateClusterInfo { interface AggregateClusterInfo {
@ -401,7 +399,13 @@ export class XdsDependencyManager {
* not already provided a ServiceConfig for the upper layer to use */ * not already provided a ServiceConfig for the upper layer to use */
if (!this.latestListener) { if (!this.latestListener) {
this.trace('Resolution error due to xDS client transient error ' + error.details); this.trace('Resolution error due to xDS client transient error ' + error.details);
this.watcher.onError(`Listener ${listenerResourceName}`, error); this.watcher.onUpdate({
success: false,
error: {
...error,
details: `Listener ${listenerResourceName}: ${error.details}`
}
});
} }
}, },
onResourceDoesNotExist: () => { onResourceDoesNotExist: () => {
@ -415,11 +419,24 @@ export class XdsDependencyManager {
}, },
onError: (error: StatusObject) => { onError: (error: StatusObject) => {
if (!this.latestRouteConfiguration) { if (!this.latestRouteConfiguration) {
this.watcher.onError(`RouteConfiguration ${this.latestRouteConfigName}`, error); this.watcher.onUpdate({
success: false,
error: {
...error,
details: `RouteConfiguration ${this.latestRouteConfigName}: ${error.details}`
}
});
} }
}, },
onResourceDoesNotExist: () => { onResourceDoesNotExist: () => {
this.watcher.onResourceDoesNotExist(`RouteConfiguration ${this.latestRouteConfigName}`); this.watcher.onUpdate({
success: false,
error: {
code: status.UNAVAILABLE,
details: `RouteConfiguration ${this.latestRouteConfigName} does not exist`,
metadata: new Metadata()
}
});
this.clusterRoots = []; this.clusterRoots = [];
this.pruneOrphanClusters(); this.pruneOrphanClusters();
} }
@ -441,8 +458,14 @@ export class XdsDependencyManager {
this.clusterRoots = []; this.clusterRoots = [];
this.pruneOrphanClusters(); this.pruneOrphanClusters();
} }
this.watcher.onResourceDoesNotExist(`Listener ${this.listenerResourceName}`); this.watcher.onUpdate({
success: false,
error: {
code: status.UNAVAILABLE,
details: `Listener ${this.listenerResourceName} does not exist`,
metadata: new Metadata()
}
});
} }
private maybeSendUpdate() { private maybeSendUpdate() {
@ -498,7 +521,7 @@ export class XdsDependencyManager {
}); });
} }
} }
this.watcher.onUpdate(update); this.watcher.onUpdate({success: true, value: update});
} }
private addCluster(clusterName: string) { private addCluster(clusterName: string) {
@ -770,10 +793,13 @@ export class XdsDependencyManager {
if (!virtualHost) { if (!virtualHost) {
this.clusterRoots = []; this.clusterRoots = [];
this.pruneOrphanClusters(); this.pruneOrphanClusters();
this.watcher.onError(`RouteConfiguration ${routeConfig.name}`, { this.watcher.onUpdate({
code: status.UNAVAILABLE, success: false,
details: `No matching route found for ${this.dataPlaneAuthority}`, error: {
metadata: new Metadata() code: status.UNAVAILABLE,
details: `RouteConfiguration ${routeConfig.name}: No matching route found for ${this.dataPlaneAuthority}`,
metadata: new Metadata()
}
}); });
// Report error // Report error
return; return;