Skip to content

Commit c4580fa

Browse files
authored
Merge pull request #2929 from murgatroid99/grpc-js-xds_dependency_manager_watcher_updates
grpc-js-xds: Implement updated xds dependency manager watcher API
2 parents e6da4ad + 4a0f4cf commit c4580fa

File tree

2 files changed

+45
-25
lines changed

2 files changed

+45
-25
lines changed

packages/grpc-js-xds/src/resolver-xds.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -135,18 +135,12 @@ class XdsResolver implements Resolver {
135135
this.xdsClient = getSingletonXdsClient();
136136
}
137137
this.xdsConfigWatcher = {
138-
onUpdate: xdsConfig => {
139-
this.handleXdsConfig(xdsConfig);
140-
},
141-
onError: (context, status) => {
142-
trace('Resolution error for target ' + uriToString(this.target) + ' due to xDS client transient error retrieving ' + context + ': ' + status.details);
143-
this.reportResolutionError(`Error retrieving resource ${context}: ${status.details}`);
144-
},
145-
onResourceDoesNotExist: context => {
146-
trace('Resolution error for target ' + uriToString(this.target) + ': ' + context + ' does not exist');
147-
/* Return an empty endpoint list and service config, to explicitly
148-
* invalidate any previously returned service config */
149-
this.listener(statusOrFromValue([]), {}, null, '');
138+
onUpdate: maybeXdsConfig => {
139+
if (maybeXdsConfig.ok) {
140+
this.handleXdsConfig(maybeXdsConfig.value);
141+
} else {
142+
this.listener(statusOrFromValue([]), {}, null, `Resolution error for target ${uriToString(this.target)}: ${maybeXdsConfig.error.details}`);
143+
}
150144
}
151145
}
152146
}

packages/grpc-js-xds/src/xds-dependency-manager.ts

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,7 @@ export interface XdsConfig {
8989
}
9090

9191
export interface XdsConfigWatcher {
92-
onUpdate(xdsConfig: XdsConfig): void;
93-
onError(context: string, status: StatusObject): void;
94-
onResourceDoesNotExist(context: string): void;
92+
onUpdate(xdsConfig: StatusOr<XdsConfig>): void;
9593
}
9694

9795
interface AggregateClusterInfo {
@@ -394,7 +392,13 @@ export class XdsDependencyManager {
394392
* not already provided a ServiceConfig for the upper layer to use */
395393
if (!this.latestListener) {
396394
this.trace('Resolution error due to xDS client transient error ' + error.details);
397-
this.watcher.onError(`Listener ${listenerResourceName}`, error);
395+
this.watcher.onUpdate({
396+
ok: false,
397+
error: {
398+
...error,
399+
details: `Listener ${listenerResourceName}: ${error.details}`
400+
}
401+
});
398402
}
399403
},
400404
onResourceDoesNotExist: () => {
@@ -408,11 +412,24 @@ export class XdsDependencyManager {
408412
},
409413
onError: (error: StatusObject) => {
410414
if (!this.latestRouteConfiguration) {
411-
this.watcher.onError(`RouteConfiguration ${this.latestRouteConfigName}`, error);
415+
this.watcher.onUpdate({
416+
ok: false,
417+
error: {
418+
...error,
419+
details: `RouteConfiguration ${this.latestRouteConfigName}: ${error.details}`
420+
}
421+
});
412422
}
413423
},
414424
onResourceDoesNotExist: () => {
415-
this.watcher.onResourceDoesNotExist(`RouteConfiguration ${this.latestRouteConfigName}`);
425+
this.watcher.onUpdate({
426+
ok: false,
427+
error: {
428+
code: status.UNAVAILABLE,
429+
details: `RouteConfiguration ${this.latestRouteConfigName} does not exist`,
430+
metadata: new Metadata()
431+
}
432+
});
416433
this.clusterRoots = [];
417434
this.pruneOrphanClusters();
418435
}
@@ -434,8 +451,14 @@ export class XdsDependencyManager {
434451
this.clusterRoots = [];
435452
this.pruneOrphanClusters();
436453
}
437-
this.watcher.onResourceDoesNotExist(`Listener ${this.listenerResourceName}`);
438-
454+
this.watcher.onUpdate({
455+
ok: false,
456+
error: {
457+
code: status.UNAVAILABLE,
458+
details: `Listener ${this.listenerResourceName} does not exist`,
459+
metadata: new Metadata()
460+
}
461+
});
439462
}
440463

441464
private maybeSendUpdate() {
@@ -491,7 +514,7 @@ export class XdsDependencyManager {
491514
});
492515
}
493516
}
494-
this.watcher.onUpdate(update);
517+
this.watcher.onUpdate({ok: true, value: update});
495518
}
496519

497520
private addCluster(clusterName: string) {
@@ -763,10 +786,13 @@ export class XdsDependencyManager {
763786
if (!virtualHost) {
764787
this.clusterRoots = [];
765788
this.pruneOrphanClusters();
766-
this.watcher.onError(`RouteConfiguration ${routeConfig.name}`, {
767-
code: status.UNAVAILABLE,
768-
details: `No matching route found for ${this.dataPlaneAuthority}`,
769-
metadata: new Metadata()
789+
this.watcher.onUpdate({
790+
ok: false,
791+
error: {
792+
code: status.UNAVAILABLE,
793+
details: `RouteConfiguration ${routeConfig.name}: No matching route found for ${this.dataPlaneAuthority}`,
794+
metadata: new Metadata()
795+
}
770796
});
771797
// Report error
772798
return;

0 commit comments

Comments
 (0)