Skip to content

xDS: adds a callback for resource unsubscription to the xDS config tracker#45898

Open
birenroy wants to merge 14 commits into
envoyproxy:mainfrom
birenroy:watch-resource-unsubscription
Open

xDS: adds a callback for resource unsubscription to the xDS config tracker#45898
birenroy wants to merge 14 commits into
envoyproxy:mainfrom
birenroy:watch-resource-unsubscription

Conversation

@birenroy

@birenroy birenroy commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

This conveys information about resources for which the Envoy takes client-side action to unsubscribe, and there is no server-side removal transmitted. This closes a small gap in xDS visibility for config tracker implementations.

I know the implementation in notifyUnsubscribedResources() is potentially expensive, but it is similar to the existing removeResourcesFromCache(), and only affects cases where xds_config_tracker_ is present. I have another PR in progress to improve the efficiency of both cases.

This PR was generated with the assistance of the Gemini AI model. I have read and understand the code diffs, and have made some manual tweaks.

Commit Message: adds a callback for resource unsubscription to the xDS config tracker
Additional Description:
Risk Level: low
Testing: ran unit and integration tests locally
Docs Changes:
Release Notes:
Platform Specific Features:

@repokitteh-read-only

Copy link
Copy Markdown

As a reminder, PRs marked as draft will not be automatically assigned reviewers,
or be handled by maintainer-oncall triage.

Please mark your PR as ready when you want it to be reviewed!

🐱

Caused by: #45898 was opened by birenroy.

see: more, trace.

@birenroy birenroy marked this pull request as ready for review June 30, 2026 14:35
@birenroy

Copy link
Copy Markdown
Contributor Author

/assign @adisuissa

return resource_name;
});
// Computes the removed resources.
std::set<std::string> removed_resources;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will it make sense to only compute the diffs if eds_resources_cache_ is used or there is an xds_config_tracker_ defined?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

return;
}
std::vector<absl::string_view> truly_removed;
for (const auto& resource_name : resources_to_remove) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a comment that this filtering is because some resources weren't subscribed to previously.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand the proposed comment. I thought this code is trying to determine the set of resources that are no longer present in any watch.

I believe the idea is that if our Envoy receives a SRDS removal, for example, then it will drop a corresponding RDS subscription. The RDS object was subscribed to, but as a "dependent" resource, removal happens on the client side, without the xDS server explicitly indicating a removal.

if (watch == this) {
continue;
}
if (watch->resources_.find(resource_name) != watch->resources_.end()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work for wildcard resources (say CDS)? IS there a test for it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added tests showing that wildcard resources don't get quite the same behavior. I think this is fine for now, unless someone needs the wildcard-derived resources tracked.


// 6. Verify tracker callback was called.
test_server_->waitForCounter("test_xds_tracker.on_resource_unsubscribed", Eq(1));
EXPECT_EQ(1, test_server_->counter("test_xds_tracker.on_resource_unsubscribed")->value());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be equal to 2 (one for the cluster and one for the endpoint)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cluster is explicitly removed (as per the comment for step 5). Explicit server-side removals are already visible to an xDS config tracker, and do not need to be communicated through onResourceUnsubscribed().

@birenroy birenroy left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review, please take another look.

return resource_name;
});
// Computes the removed resources.
std::set<std::string> removed_resources;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

return;
}
std::vector<absl::string_view> truly_removed;
for (const auto& resource_name : resources_to_remove) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand the proposed comment. I thought this code is trying to determine the set of resources that are no longer present in any watch.

I believe the idea is that if our Envoy receives a SRDS removal, for example, then it will drop a corresponding RDS subscription. The RDS object was subscribed to, but as a "dependent" resource, removal happens on the client side, without the xDS server explicitly indicating a removal.


// 6. Verify tracker callback was called.
test_server_->waitForCounter("test_xds_tracker.on_resource_unsubscribed", Eq(1));
EXPECT_EQ(1, test_server_->counter("test_xds_tracker.on_resource_unsubscribed")->value());

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cluster is explicitly removed (as per the comment for step 5). Explicit server-side removals are already visible to an xDS config tracker, and do not need to be communicated through onResourceUnsubscribed().

if (watch == this) {
continue;
}
if (watch->resources_.find(resource_name) != watch->resources_.end()) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added tests showing that wildcard resources don't get quite the same behavior. I think this is fine for now, unless someone needs the wildcard-derived resources tracked.

birenroy added 14 commits July 1, 2026 20:14
…legate

Add integration tests for XdsConfigTracker and XdsResourcesDelegate in
both SotW (GrpcMuxImpl) and Delta (NewGrpcMuxImpl) implementations.

Verify that:
- onConfigAccepted/onConfigRejected are called on XdsConfigTracker.
- getResources/onConfigUpdated/onResourceLoadFailed are called on XdsResourcesDelegate (SotW only).

TAG=agy
CONV=b942214e-2f01-4571-9478-b3eda0877a4c

Signed-off-by: Biren Roy <birenroy@google.com>
…d mocks

Move MockXdsConfigTracker and MockXdsResourcesDelegate from local test
files to test/mocks/config/mocks.h to allow reuse and avoid duplication.
Update BUILD dependencies accordingly.

TAG=agy
CONV=b942214e-2f01-4571-9478-b3eda0877a4c

Signed-off-by: Biren Roy <birenroy@google.com>
Signed-off-by: Biren Roy <birenroy@google.com>
Signed-off-by: Biren Roy <birenroy@google.com>
Signed-off-by: Biren Roy <birenroy@google.com>
Signed-off-by: Biren Roy <birenroy@google.com>
Signed-off-by: Biren Roy <birenroy@google.com>
Signed-off-by: Biren Roy <birenroy@google.com>
Signed-off-by: Biren Roy <birenroy@google.com>
Signed-off-by: Biren Roy <birenroy@google.com>
Signed-off-by: Biren Roy <birenroy@google.com>
Signed-off-by: Biren Roy <birenroy@google.com>
…tests

Signed-off-by: Biren Roy <birenroy@google.com>
…ption

Signed-off-by: Biren Roy <birenroy@google.com>
@birenroy

birenroy commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

Please review #45930 first; it adds some unit test coverage for existing code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants