grpc-js-xds: Refactor xDS stream state and add resource timer #2117
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The main goal of this change is to add the resource timer, which is described in this section of the xDS docs. Essentially, the protocol does not consistently tell us when a resource does not exist, so we assume that the server will respond to any request within 15 seconds, and if the client does not get the requested resource in that time, it assumes that it does not exist. Since the timer is watching server response latency, we only run it while we have an active ADS stream. The specific algorithm is as follows:
Some significant changes were needed to the watchers structure to implement this in a reasonable way, and the simplest way to do that was to refactor most of the logic into the new
BaseXdsStreamState
abstract class. This refactor ended up slightly modifying the nonexistent resource reporting for LDS and CDS, to account for whether we already have a cached response. Otherwise I think it should all be functionally the same.I also added a change to clear the nonce when the ADS stream ends, because apparently we're supposed to do that too. It's not really related to this change but I was touching that part of the code anyway and it's a quick change.