-
Notifications
You must be signed in to change notification settings - Fork 0
xds: Client watcher API changes #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
b1d0d6d
3fcff8d
bf905c2
4f5f3b3
494a75a
a5117ad
352ec9e
148f105
0c78954
b5571d1
c3a43b2
910b20b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -632,6 +632,9 @@ private abstract class XdsWatcherBase<T extends ResourceUpdate> | |
|
|
||
| @Nullable | ||
| private StatusOr<T> data; | ||
| @Nullable | ||
| @SuppressWarnings("unused") | ||
| private Status ambientError; | ||
|
|
||
|
|
||
| private XdsWatcherBase(XdsResourceType<T> type, String resourceName) { | ||
|
|
@@ -640,42 +643,39 @@ private XdsWatcherBase(XdsResourceType<T> type, String resourceName) { | |
| } | ||
|
|
||
| @Override | ||
| public void onError(Status error) { | ||
| checkNotNull(error, "error"); | ||
| public void onResourceChanged(StatusOr<T> update) { | ||
| if (cancelled) { | ||
| return; | ||
| } | ||
| // Don't update configuration on error, if we've already received configuration | ||
| if (!hasDataValue()) { | ||
| this.data = StatusOr.fromStatus(Status.UNAVAILABLE.withDescription( | ||
| String.format("Error retrieving %s: %s: %s", | ||
| toContextString(), error.getCode(), error.getDescription()))); | ||
| maybePublishConfig(); | ||
| } | ||
| } | ||
| ambientError = null; | ||
| if (update.hasValue()) { | ||
| data = update; | ||
| subscribeToChildren(update.getValue()); | ||
| } else { | ||
| Status status = update.getStatus(); | ||
| Status translatedStatus = Status.UNAVAILABLE.withDescription( | ||
| String.format("Error retrieving %s: %s. Details: %s%s", | ||
| toContextString(), | ||
| status.getCode(), | ||
| status.getDescription() != null ? status.getDescription() : "", | ||
| nodeInfo())); | ||
|
|
||
| @Override | ||
| public void onResourceDoesNotExist(String resourceName) { | ||
| if (cancelled) { | ||
| return; | ||
| data = StatusOr.fromStatus(translatedStatus); | ||
| } | ||
|
|
||
| checkArgument(this.resourceName.equals(resourceName), "Resource name does not match"); | ||
| this.data = StatusOr.fromStatus(Status.UNAVAILABLE.withDescription( | ||
| toContextString() + " does not exist" + nodeInfo())); | ||
| maybePublishConfig(); | ||
| } | ||
|
|
||
| @Override | ||
| public void onChanged(T update) { | ||
| checkNotNull(update, "update"); | ||
| public void onAmbientError(Status error) { | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @gemini-code-assist I want you to review the XdsDependencyManager and tell me the use of variable 'ambientError'. As per gRFC A88. Right now I'm only focused on implementing xds client watcher API changes. |
||
| if (cancelled) { | ||
| return; | ||
| } | ||
|
|
||
| this.data = StatusOr.fromValue(update); | ||
| subscribeToChildren(update); | ||
| maybePublishConfig(); | ||
| ambientError = error.withDescription( | ||
| String.format("Ambient error for %s: %s. Details: %s%s", | ||
| toContextString(), | ||
| error.getCode(), | ||
| error.getDescription() != null ? error.getDescription() : "", | ||
| nodeInfo())); | ||
| } | ||
|
|
||
| protected abstract void subscribeToChildren(T update); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,6 +42,7 @@ | |
| import io.grpc.ServerServiceDefinition; | ||
| import io.grpc.Status; | ||
| import io.grpc.StatusException; | ||
| import io.grpc.StatusOr; | ||
| import io.grpc.SynchronizationContext; | ||
| import io.grpc.SynchronizationContext.ScheduledHandle; | ||
| import io.grpc.internal.GrpcUtil; | ||
|
|
@@ -382,18 +383,38 @@ private DiscoveryState(String resourceName) { | |
| } | ||
|
|
||
| @Override | ||
| public void onChanged(final LdsUpdate update) { | ||
| public void onResourceChanged(final StatusOr<LdsUpdate> update) { | ||
| if (stopped) { | ||
| return; | ||
| } | ||
| logger.log(Level.FINEST, "Received Lds update {0}", update); | ||
| if (update.listener() == null) { | ||
| onResourceDoesNotExist("Non-API"); | ||
|
|
||
| if (!update.hasValue()) { | ||
| // This is a definitive resource error (e.g., NOT_FOUND). | ||
| // We must treat the resource as unavailable and tear down the server. | ||
| Status status = update.getStatus(); | ||
| StatusException statusException = Status.UNAVAILABLE.withDescription( | ||
| String.format("Listener %s unavailable: %s", resourceName, status.getDescription())) | ||
| .withCause(status.asException()) | ||
| .asException(); | ||
| handleConfigNotFoundOrMismatch(statusException); | ||
| return; | ||
| } | ||
|
|
||
| String ldsAddress = update.listener().address(); | ||
| if (ldsAddress == null || update.listener().protocol() != Protocol.TCP | ||
| // The original 'onChanged' logic starts here. | ||
| final LdsUpdate ldsUpdate = update.getValue(); | ||
| logger.log(Level.FINEST, "Received Lds update {0}", ldsUpdate); | ||
| if (ldsUpdate.listener() == null) { | ||
| handleConfigNotFoundOrMismatch( | ||
| Status.NOT_FOUND.withDescription("Listener is null in LdsUpdate").asException()); | ||
| return; | ||
| } | ||
|
|
||
| // This check is now covered by the '!update.hasValue()' block above. | ||
| // The original check was: if (update.listener() == null) | ||
|
|
||
| // The ipAddressesMatch function and its logic remain critical. | ||
| String ldsAddress = ldsUpdate.listener().address(); | ||
| if (ldsAddress == null || ldsUpdate.listener().protocol() != Protocol.TCP | ||
| || !ipAddressesMatch(ldsAddress)) { | ||
| handleConfigNotFoundOrMismatch( | ||
| Status.UNKNOWN.withDescription( | ||
|
|
@@ -402,21 +423,19 @@ public void onChanged(final LdsUpdate update) { | |
| listenerAddress, ldsAddress)).asException()); | ||
| return; | ||
| } | ||
|
|
||
| // The rest of the logic is a direct copy from the original onChanged method. | ||
| if (!pendingRds.isEmpty()) { | ||
| // filter chain state has not yet been applied to filterChainSelectorManager and there | ||
| // are two sets of sslContextProviderSuppliers, so we release the old ones. | ||
| releaseSuppliersInFlight(); | ||
| pendingRds.clear(); | ||
| } | ||
|
|
||
| filterChains = update.listener().filterChains(); | ||
| defaultFilterChain = update.listener().defaultFilterChain(); | ||
| // Filters are loaded even if the server isn't serving yet. | ||
| filterChains = ldsUpdate.listener().filterChains(); | ||
| defaultFilterChain = ldsUpdate.listener().defaultFilterChain(); | ||
| updateActiveFilters(); | ||
|
|
||
| List<FilterChain> allFilterChains = filterChains; | ||
| List<FilterChain> allFilterChains = new ArrayList<>(filterChains); | ||
| if (defaultFilterChain != null) { | ||
| allFilterChains = new ArrayList<>(filterChains); | ||
| allFilterChains.add(defaultFilterChain); | ||
| } | ||
|
||
|
|
||
|
|
@@ -450,43 +469,36 @@ public void onChanged(final LdsUpdate update) { | |
| } | ||
| } | ||
|
|
||
| private boolean ipAddressesMatch(String ldsAddress) { | ||
| HostAndPort ldsAddressHnP = HostAndPort.fromString(ldsAddress); | ||
| HostAndPort listenerAddressHnP = HostAndPort.fromString(listenerAddress); | ||
| if (!ldsAddressHnP.hasPort() || !listenerAddressHnP.hasPort() | ||
| || ldsAddressHnP.getPort() != listenerAddressHnP.getPort()) { | ||
| return false; | ||
| } | ||
| InetAddress listenerIp = InetAddresses.forString(listenerAddressHnP.getHost()); | ||
| InetAddress ldsIp = InetAddresses.forString(ldsAddressHnP.getHost()); | ||
| return listenerIp.equals(ldsIp); | ||
| } | ||
|
|
||
| @Override | ||
| public void onResourceDoesNotExist(final String resourceName) { | ||
| if (stopped) { | ||
| return; | ||
| } | ||
| StatusException statusException = Status.UNAVAILABLE.withDescription( | ||
| String.format("Listener %s unavailable, xDS node ID: %s", resourceName, | ||
| xdsClient.getBootstrapInfo().node().getId())).asException(); | ||
| handleConfigNotFoundOrMismatch(statusException); | ||
| } | ||
|
|
||
| @Override | ||
| public void onError(final Status error) { | ||
| public void onAmbientError(final Status error) { | ||
| if (stopped) { | ||
| return; | ||
| } | ||
| // This logic is preserved from the original 'onError' method. | ||
| String description = error.getDescription() == null ? "" : error.getDescription() + " "; | ||
| Status errorWithNodeId = error.withDescription( | ||
| description + "xDS node ID: " + xdsClient.getBootstrapInfo().node().getId()); | ||
| logger.log(Level.FINE, "Error from XdsClient", errorWithNodeId); | ||
|
|
||
| // If the server isn't serving yet, a transient error is a startup failure. | ||
| // If it is already serving, we ignore it to prevent an outage. | ||
| if (!isServing) { | ||
| listener.onNotServing(errorWithNodeId.asException()); | ||
| } | ||
| } | ||
|
|
||
| private boolean ipAddressesMatch(String ldsAddress) { | ||
| HostAndPort ldsAddressHnP = HostAndPort.fromString(ldsAddress); | ||
| HostAndPort listenerAddressHnP = HostAndPort.fromString(listenerAddress); | ||
| if (!ldsAddressHnP.hasPort() || !listenerAddressHnP.hasPort() | ||
| || ldsAddressHnP.getPort() != listenerAddressHnP.getPort()) { | ||
| return false; | ||
| } | ||
| InetAddress listenerIp = InetAddresses.forString(listenerAddressHnP.getHost()); | ||
| InetAddress ldsIp = InetAddresses.forString(ldsAddressHnP.getHost()); | ||
| return listenerIp.equals(ldsIp); | ||
| } | ||
|
|
||
| private void shutdown() { | ||
| stopped = true; | ||
| cleanUpRouteDiscoveryStates(); | ||
|
|
@@ -775,54 +787,45 @@ private RouteDiscoveryState(String resourceName) { | |
| } | ||
|
|
||
| @Override | ||
| public void onChanged(final RdsUpdate update) { | ||
| syncContext.execute(new Runnable() { | ||
| @Override | ||
| public void run() { | ||
| if (!routeDiscoveryStates.containsKey(resourceName)) { | ||
| return; | ||
| } | ||
| if (savedVirtualHosts == null && !isPending) { | ||
| logger.log(Level.WARNING, "Received valid Rds {0} configuration.", resourceName); | ||
| } | ||
| savedVirtualHosts = ImmutableList.copyOf(update.virtualHosts); | ||
| updateRdsRoutingConfig(); | ||
| maybeUpdateSelector(); | ||
| public void onResourceChanged(final StatusOr<RdsUpdate> update) { | ||
| syncContext.execute(() -> { | ||
| if (!routeDiscoveryStates.containsKey(resourceName)) { | ||
| return; // Watcher has been cancelled. | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| @Override | ||
| public void onResourceDoesNotExist(final String resourceName) { | ||
| syncContext.execute(new Runnable() { | ||
| @Override | ||
| public void run() { | ||
| if (!routeDiscoveryStates.containsKey(resourceName)) { | ||
| return; | ||
| if (update.hasValue()) { | ||
| // This is a successful update, taken from the original onChanged. | ||
| if (savedVirtualHosts == null && !isPending) { | ||
| logger.log(Level.WARNING, "Received valid Rds {0} configuration.", resourceName); | ||
| } | ||
| logger.log(Level.WARNING, "Rds {0} unavailable", resourceName); | ||
| savedVirtualHosts = ImmutableList.copyOf(update.getValue().virtualHosts); | ||
| } else { | ||
| // This is a definitive resource error, taken from onResourceDoesNotExist. | ||
| logger.log(Level.WARNING, "Rds {0} unavailable: {1}", | ||
| new Object[]{resourceName, update.getStatus()}); | ||
| savedVirtualHosts = null; | ||
| updateRdsRoutingConfig(); | ||
| maybeUpdateSelector(); | ||
| } | ||
| // In both cases, a change has occurred that requires a config update. | ||
| updateRdsRoutingConfig(); | ||
| maybeUpdateSelector(); | ||
| }); | ||
| } | ||
|
|
||
| @Override | ||
| public void onError(final Status error) { | ||
| syncContext.execute(new Runnable() { | ||
| @Override | ||
| public void run() { | ||
| if (!routeDiscoveryStates.containsKey(resourceName)) { | ||
| return; | ||
| } | ||
| String description = error.getDescription() == null ? "" : error.getDescription() + " "; | ||
| Status errorWithNodeId = error.withDescription( | ||
| description + "xDS node ID: " + xdsClient.getBootstrapInfo().node().getId()); | ||
| logger.log(Level.WARNING, "Error loading RDS resource {0} from XdsClient: {1}.", | ||
| new Object[]{resourceName, errorWithNodeId}); | ||
| maybeUpdateSelector(); | ||
| public void onAmbientError(final Status error) { | ||
| syncContext.execute(() -> { | ||
| if (!routeDiscoveryStates.containsKey(resourceName)) { | ||
| return; // Watcher has been cancelled. | ||
| } | ||
| // This is a transient error, taken from the original onError. | ||
| String description = error.getDescription() == null ? "" : error.getDescription() + " "; | ||
| Status errorWithNodeId = error.withDescription( | ||
| description + "xDS node ID: " + xdsClient.getBootstrapInfo().node().getId()); | ||
| logger.log(Level.WARNING, "Error loading RDS resource {0} from XdsClient: {1}.", | ||
| new Object[]{resourceName, errorWithNodeId}); | ||
|
|
||
| // Per gRFC A88, ambient errors should not trigger a configuration change. | ||
| // Therefore, we do NOT call maybeUpdateSelector() here. | ||
| }); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
Details:section of the error message includesnodeInfo()at the end. However, thenodeInfo()is already included in the overall error message. Consider removing the redundantnodeInfo()call to avoid repetition.