Repository navigation
config: fix a bug where the on demand subscription not works - #46216
Conversation
Signed-off-by: wbpcode <[email protected]>
Signed-off-by: wbpcode <[email protected]>
| if (options.use_namespace_matching_) { | ||
| // This is to prevent sending out of requests that contain prefixes instead of resource names | ||
| sub->second->sub_state_.updateSubscriptionInterest({}, {}); | ||
| } else { | ||
| sub->second->sub_state_.updateSubscriptionInterest(added_removed.added_, | ||
| added_removed.removed_); | ||
| } | ||
| sub->second->sub_state_.updateSubscriptionInterest(added_removed.added_, added_removed.removed_); |
There was a problem hiding this comment.
The use_namespace_matching_ here make it's impossible to subscribe other resource in the start() and update interest method because they all will be cleaned.
Now, we will always respect the resources set provided by the start() and updateResourceInterest() here, and use the accept() to customize the resource routing.
|
Also related to #44129 |
adisuissa
left a comment
There was a problem hiding this comment.
Thanks for raising the bug, and proposing a fix.
To the best of my understanding, w.r.t. 'append', the proposed design essentially introduces the on-demand concept into the GrpcMuxWatch, which may weaken the abstraction and encapsulation of the on-demand concept. I believe the proposed design leaks that concept into the GrpcMux (similar to how the namespace-matching is a leak of the watched resources, which as you are pointing out is a problem). Note that Envoy already supports multiple GrpcSubscription object over the same GrpcMux (so the watch is updated correctly while there are dynamic "additions" to the watched objects).
Assuming that on-demand is for a named resource, I believe the issue can also be solved by introducing multiple GrpcSubscription objects (for each VDHS resource that needs to be fetched), that will be fetched over the same GrpcMux.
W.r.t. 'accept' I agree that there is an issue with VHDS. I think the issue is even a bit more challenging, for example, say there are 2 routes '/shared/prefix/route_1', and '/shared/prefix', which subscriptions would a VHDS for the two different routes will be invoked once a response comes back. In general, this is a challenge with wildcard subscriptions and it would be good to get a good solution for this. I'm not sure if the proposed aliasing solution is the right thing to do, but it seems to be a bit more explicit - telling the xDS system, what to 'accept' by defining it in the resource the client subscribes to.
| [this]() { | ||
| subscription_->start( | ||
| {config_update_info_->protobufConfigurationCast().name()}); | ||
| // Start with no concrete subscription; virtual hosts are fetched on demand. |
There was a problem hiding this comment.
Is this a breaking change with the VHDS default wildcard subscription?
There was a problem hiding this comment.
Nope, this PR didn't change any behavior. The VHDS worked in a special way before.
It will specific a route configuration name (for example rc) in the start() But this rc will not be sent out because the use_namespace_matching won't add anything to the subscription state. See the #46216 (comment)
Then this rc will be used to match received resources based on prefix matching.
For control plane's perspective, nothing is changed.
Wouldn't this be much more expensive than just adding resources to the watch? we could be talking of many thousands of resources. |
Really depends on whether there's support for subscription removal or not. |
I don't think this is actual problem. Note, we have supported
Every GrpcSubscription for single resource (like a domain) is much more heavy if there are thousands resources. And if there are multiple resources/subscriptions, we still need to abstract a layer to manager all these subscriptions, like the I don't think multiple subscription is a bad idea. But with our current subscription and watch map's design, after this fix, a single subscription could manage a set of resource very well, and more efficient, easier to use. I guess there is no strong reason to use multiple subscriptions' solution.
Our current underlying subscription and watch map design have supported the resource removal well. To expose a In short conclusion, our current subscription and watch map are well designed for multiple resources in same subscription. And it match the actual requirement (one observer, multiple resources) very well. Fix it and enhance it should bring us more benefit rather than to deprecate it. |
In very long time, we still need to handle canonical xDS. So, I guess the
Basically, |
How does it handle a removal of a subscription from the watcher?
Why isn't there a requirement for removal? What happens if the listener that subscribed to the VHDS resource is removed?
The breaking of that abstraction is one of the things that caused issues with on-demand out-of-sync subscriptions. |
When a subscription is removed, it will be removed from the watch map. For specific resource, if the removed subscription is only one to subscribe the resource, the resource will be removed. If there are other subscriptions want this resource, resource will be kept. Yeah, watch map have tracked everything. Every subscription's resource list and every resource is subscribed by which subscriptions. |
Sorry, I meant to remove a specific resource from a subscription. Until now, no related requirements. All your referred are cases to remove whole subscription. For these cases, they will be removed correctly as I described in the #46216 (comment) And you are right, I only use VHDS as an example. This is general problem, and this PR is also a general fix for all xDS-types (i mean CDS/LDS/... and so on, not means file/rest/...). |
Sorry. I didn't get you here. Could you explain a little more about the |
|
BTW, to avoid there is any information gap, when I say |
|
After a rethinking and discuss with AI, did you mean the current design shouldn't leak the gRPC implementation detail like If you meant that, I guess it's too late to discuss that. GRPC is special from start. For example, the file xds even cannot support a the The next generation should is the xdstp, but it's another topic. |
|
/coverage |
|
Coverage for this Pull Request will be rendered here: For comparison, current coverage on The coverage results are (re-)rendered each time the CI |
Signed-off-by: wbpcode <[email protected]>
|
@wbpcode and @adisuissa what should we do next here? Is there agreement on the approach? |
|
Sorry, been busy with other stuff. I believe I've got an explicit example that shows something that is lacking with having multiple subscribed resources, that are not for a wildcard/collection subscription, multiplexed in the same GrpcSubscription. Consider what happens in the Envoy side when a subscribed resource isn't found/missing on the server. If one has multiple singleton (named) subscriptions over the same GrpcSubcription, there is no way to mark one of them as missing. In the case of VHDS, for example, I believe that currently there is a bug where waiting for an on-demand VHDS resource is without any limit, although there should be a timeout for waiting for that resource. Now one can add all the features that are supported for GrpcSubscription into the "updateOnDemand()" method and try to create multiple timers inside, but IMHO it is probably not the right way to go. |
|
Hello, @adisuissa , I agree all you said. It's not the perfect design and have obvious limit. But the design is not introduced by this PR. This PR's target also is not to provides a better design. The target here is only try to fix an existing bug of current implementation to make it works a little better. Because this design (canonical xds and We still could to construct our new on demand solution based on xdstp by create subscription for every new resource (like the new ondemand cds). But at same, to continuously evolve the canonical xDS is harmless anyway if it could meet our users's requirements. This PR is only a fix and will make the canonical xDS easier to support delta/ondemand (sure, under you refferred limit). It won't block the developement of better design with xdstp and it's another scope's discussion. |
My reading of this PR, and specifically the part that adds |
|
I see the disagreement now. Hmmm, I personally think this PR didn't change existing design but a bug fix only. It should won't actually make thing worse because we have provided the Note there have been So, I think it won't make the Or could you explain a little more in details about the BTW, I agree per resource/glob per subscription is more clear and addressed the limit you referred in the #46216 (comment). But I inclined to use that new design (per resource/glob per subscription) only for the xdstp and keep the canonical xDS works in the existing way for a while because the existing solution is lighter/simple to use and no users complain about the limits for now. |
Signed-off-by: code <[email protected]>
|
Also related to istio/istio#60149. Once we fixed this bug, it would be super easy to support on demand cluster discovery with existing canonical CDS directly (not the ODCDS, but pure CDS). And the Istio could support on demand cluster discovery in a much more easier way. |
|
/retest |
htuch
left a comment
There was a problem hiding this comment.
I spoke offline with @wbpcode and (paging all of this back in after a few years) the useful context here is the existing subscription : resource mapping for on-demand in the various DSes.
For now, just focusing on the bug fix, the issue is that VHDS and ODCDS (non-xdstp) already use a single Subscription for multiple resources. It seems reasonable to make small changes to fix the issue there around resource update rather than move to a per-resource subscription for ODCDS. VHDS already worked before (via hacks) and ODCDS is related in a sense to a glob CDS (which naturally would have a single subscription).
The discussion is really around ODCDS, which is a special on-demand CDS due to this glob/singleton duality of CDS (LDS would have a similar situation if it were on-demand).
I agree with @adisuissa on a single subscription for multiple resources having limitations (e.g. around missing resource handling). It might make sense to either move to per-resource subscriptions outside the bug fix or to enrich the subscription API for this further.
| * For legacy VHDS, should an xDS resource name be treated as <namespace>/<resource name>? This is | ||
| * incompatible with the use of xdstp:// naming. | ||
| */ | ||
| bool use_namespace_matching_{}; |
There was a problem hiding this comment.
As discussed offline, it might make review easier to separate this from the bug fix part. If the only consumer of the pattern based matching for now is VHDS, it seems there is less of an acute need to go making major changes here. I agree that is what is there today is a hack and could be done more cleanly, but it seems unrelated to the CDS portion where the bug exists.
There was a problem hiding this comment.
Yeah. I will split it out.
| // watch-map routing (so the response is delivered to our callbacks) and the subscription sent to | ||
| // the management server (so it is fetched). Without the watch-map update, a resource that was not | ||
| // named at start() time would match no watch and its update would be silently dropped. | ||
| watch_->append(for_update); |
There was a problem hiding this comment.
This seems the crux of the PR; would it work to refocus the PR around the bug fix and moving the non-xdstp parts of ODCDS to a single subscription model with multiple watched resources?
There was a problem hiding this comment.
Yeah. This is the core. And actually this is a fixed version of the previous grpc_mux_->requestOnDemandUpdate(type_url_, for_update);.
We removed the broken requestOnDemandUpdate and use the append to do the correct things.
|
FWIW, for singleton (named) resources we had a similar problem with OD-CDS, and this was solved by using a manager for these resources (see #40988 where the singleton manager was added and #41174 where the same subscription manager was used for non-xDSTP over ADS subscriptions). IMHO, and looking at the current design, going in a direction which adds another internal update will cause more confusion later on and increase tech-debt. I'm not against the proposed change, but I believe it will need to be cleaned up later. IMO the real problem with VHDS, which is not directly related with this change, is due to three features that currently only exist in VHDS:
These cause some subtle issues, such as: when two listeners use OD-VHDS, and they also must use wildcard VHDS, how would the config-source type know whether a received VHDS resource is for an on-demand-request of a specific listener or for a wildcard update that needs to be sent to the 2 listeners. I think this is a flaw in the design that stems from the question of "what should a wildcard subscription retrieve", and I'm not sure how to solve this problem without substantially impacting the current way the VHDS protocol is implemented. |
|
Regarding the concerns around per-resource subscription overhead vs. shared subscriptions, I ran some experiments with Claude Code to dig into this. The net result is that there is ~600 bytes additional memory usage when adding a subscription to the baseline per-resource tracking overhead of ~350 bytes. There are definitely opportunities to reduce that overhead further, e.g. 72 bytes of the overhead are stats which could arguably be coarser in situations like ODCDS. There are also some benefits we win from the overhead, as @adisuissa points out, the per-resource timer is something you probably want anyway. Realistically when we're dealing with xDS resource subscriptions the resource itself typically has a non-trivial memory resource costs. If we take the 47 KB Cluster size from , we're arguing over a pretty tiny ~1-1.5% memory overhead for the subscription, part of which is paying for something we want, and part of which is optimizable.So, I'm inclined to not view per-resource subscriptions as prohibitively costly or wasteful. |
|
After RDS warming work is done. I will back to refactor the PR to use a per subscription-per-resource version. |
|
This pull request has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in 7 days if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions! |
|
This pull request has been automatically closed because it has not had activity in the last 37 days. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions! |
|
Is thinking should pick this up again because I haven't figured out a way to migrate the VHDS and deprecate the requestOnDemandUpdate. |
… dev-fix-xds-on-demand-update
…43/wbpcode/envoy into dev-fix-xds-on-demand-update
… dev-fix-xds-on-demand-update
Signed-off-by: wbpcode <[email protected]>
|
So, I guess we still need to fix the bug to make the cc @htuch @botengyao |
|
I guess I'm still not convinced that per-subscription abstraction is wrong, since the VHDS example just points to naive control flow; the VHDS code should be doing some coalescing across update scopes. But in any case, I think this is all beyond the scope of this PR, which is to fix a real problem in ODCDS without boiling the ocean. I kind of feel a bit differently these days about tech debt as complex subsystems such as the GrpcMux and its in-treee consumers are more malleable. I just worry if you are taking a hard dependency out-of-tree and consider this a one-way door vs. two-way door. So, architecturally, as a bug fix, if we still consider this a two way door, I think we should just merge this. One thing I'd open up here, because I do think we want to do some extensive surgery on GrpcMux in the future, is how this and other parts of the GrpcMux architecutre can be safely changed at scale. What are your thoughts on us being able to build confidence in any major refactoring in the future? I don't trust existing tests, as Hyrum's Law has likely set in at this point. |
|
what is the status on this PR? |
… route (#48079) Commit Message: on_demand: continue to the router when the on-demand VHDS virtual host has no matching route. Additional Description: After #47183, onRouteConfigUpdateCompletion() re-runs decodeHeaders() once VHDS reports that the virtual host exists. route_exists only means the virtual host exists, not that one of its routes matches the request. If none match, decodeHeaders() requests the same virtual host again. Since #46216 that repeated request is not sent, so the request waits until the stream idle timeout. Before #46216 it was sent and answered again, so the request looped on VHDS. The legacy recreateStream() path has the same problem. This change re-checks route() after refreshing the route config snapshot. route_exists now means a route was found, as the scoped RDS callback already reports. If no route matches, the filter continues to the router, which replies with a 404. Tradeoff: a virtual host that only gains the matching route in a later VHDS update is no longer picked up while the request waits. Upstream never answered this case before: the request looped or waited until the stream idle timeout. Related PRs: - #48000 answers repeated VHDS requests locally. With that change, the decodeHeaders() re-run would get an immediate answer for the same virtual host and request it again. Continuing to the router when no route matches avoids that. - #44401 lets a VHDS virtual host replace an RDS virtual host with the same name. If the VHDS copy also has no route for the request, the request currently waits until the stream idle timeout. With this change it gets a 404. Risk Level: Low. Guarded, limited to on-demand VHDS. Testing: New unit tests in on_demand_filter_test cover both values of the new guard and of on_demand_vhds_no_recreate_stream. New integration tests in vhds_integration_test cover both on_demand_vhds_no_recreate_stream values. Without the fix, the new tests with the guard enabled fail and the integration requests time out waiting for a response. on_demand_filter_test, vhds_integration_test, odcds_integration_test and on_demand_integration_test pass. Docs Changes: N/A Release Notes: Added under changelogs/current/bug_fixes. Platform Specific Features: N/A Runtime guard: envoy.reloadable_features.on_demand_vhds_require_route_match (default true). Set it to false to restore the previous behavior. AI assistance: Cursor helped trace the issue and write the tests. I reviewed and understand all changes. Signed-off-by: William Dauchy <[email protected]>
Commit Message: config: fix a bug where the on demand subscription not works
Additional Description:
In the previous xds implementation, the
requestOnDemandUpdate()will update the resources in the discovery request but doesn't update the watch self which make the responded resource will be silently dropped.The VHDS works because it use a namespace matching to match all resource with same prefix. The
use_namespace_matchingself is subscription level option, but will be affected all subscriptions under the same type_url. So, it more like a hack.The ODCDS is a problem. The integration show it can never works correctly. 😞
Anyway, this PR fixed these problems by:
accept()method to replace theuse_namespace_matchingwhich is more clearly.Could close #46561
Risk Level: mid, core code change.
Testing: unit, integration.
Docs Changes: n/a.
Release Notes: added.
Platform Specific Features: n/a.