Skip to content

xds: add internal ResourceNameFunc server option - #9288

Open
ran-su wants to merge 7 commits into
grpc:masterfrom
ran-su:xds-server-resource-name-func
Open

xds: add internal ResourceNameFunc server option#9288
ran-su wants to merge 7 commits into
grpc:masterfrom
ran-su:xds-server-resource-name-func

Conversation

@ran-su

@ran-su ran-su commented Aug 3, 2026

Copy link
Copy Markdown
Member

Adds an internal ResourceNameFunc server option that allows override the LDS listener resource name.

RELEASE NOTES: none

@codecov

codecov Bot commented Aug 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.11111% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.08%. Comparing base (a620350) to head (e9b5060).
⚠️ Report is 28 commits behind head on master.

Files with missing lines Patch % Lines
xds/server.go 82.60% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9288      +/-   ##
==========================================
+ Coverage   83.00%   83.08%   +0.08%     
==========================================
  Files         422      424       +2     
  Lines       35085    35252     +167     
==========================================
+ Hits        29121    29289     +168     
- Misses       4441     4448       +7     
+ Partials     1523     1515       -8     
Files with missing lines Coverage Δ
internal/xds/server/server_options.go 100.00% <100.00%> (ø)
xds/server_options.go 100.00% <100.00%> (ø)
xds/server.go 82.55% <82.60%> (ø)

... and 59 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Introduces `ResourceNameFunc` callback option to `NewGRPCServer` for overriding server listener resource name generation.
Exposes `UnderlyingServer()` method to retrieve the inner target server for chaining.
@ran-su
ran-su force-pushed the xds-server-resource-name-func branch from 726a5b4 to 5c0a214 Compare August 3, 2026 21:56
@easwars easwars added Area: xDS Includes everything xDS related, including LB policies used with xDS. Type: Feature New features or improvements in behavior labels Aug 4, 2026
@easwars easwars added this to the 1.84 Release milestone Aug 4, 2026
@eshitachandwani
eshitachandwani self-requested a review August 12, 2026 16:06
Comment thread xds/server_options.go Outdated
//
// Notice: This API is EXPERIMENTAL and may be changed or removed in a
// later release.
func ResourceNameFunc(f func(net.Addr) string) grpc.ServerOption {

@eshitachandwani eshitachandwani Aug 12, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Instead of providing an option for anyone to change the listener resource name for server, we only want it to be internal, so we have a few options here :

  1. Move the ResourceNameFunc option to an internal package.
  2. Pass a listener to the Serve method which has a function for the override and we can define an interface for it (or do it inline) and type check if the listener implements that interface , if it does, we use the provided function for populating the listener name.
  • Have a variable function , something like var CustomResourceTemplatePopulator func(template, target string) string inside a internal package , like internal/xds/bootstrap.
  • Then PopulateResourceTemplate can check if the variable is not nil, return the CustomResourceTemplatePopulator
  • For the cfg.ServerListenerResourceNameTemplate() == "" , we can do the check if CustomResourceTemplatePopulator is nil.

WDYT ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks, I think option 1 works better for us. I moved ResourceNameFunc to internal/xds/server as an internal grpc.ServerOption. We do want to keep the resource name override per-server and avoid changing the xds bootstrap as bootstrap could be shared. I also updated the test.

Comment thread xds/server.go Outdated
//
// Notice: This API is EXPERIMENTAL and may be changed or removed in a
// later release.
func (s *GRPCServer) UnderlyingServer() *grpc.Server {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should hold of on exposing the underlying server until we have a discussion and reach a conclusion on the best way to achieve this.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I moved underlying server part out of this PR. We can continue discuss and explore other options without blocking review/submission the resource name part.

@ran-su ran-su changed the title xds: add ResourceNameFunc server option and UnderlyingServer method xds: add internal ResourceNameFunc server option Aug 16, 2026
Comment thread internal/xds/server/server_options.go Outdated
Comment thread xds/server_test.go Outdated
Comment thread xds/server_test.go Outdated
Comment thread xds/server_test.go

@eshitachandwani eshitachandwani left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM modulo 2 comments. Adding @easwars for a second review.

Comment thread xds/server_options.go Outdated
type serverOptions struct {
modeCallback ServingModeCallbackFunc
clientPoolForTesting *xdsclient.Pool
resourceNameFunc func(net.Addr) string

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we change this resourceNameFunc variable here too...and everywhere else?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

done

Comment thread internal/xds/server/server_options.go Outdated
// OverrideListenerResourceNameFromServerOption returns the resource name
// function carried by opt, if opt was created by OverrideListenerResourceName.
func OverrideListenerResourceNameFromServerOption(opt grpc.ServerOption) (func(net.Addr) string, bool) {
o, ok := opt.(*overrideListenerResourceNameOption)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we change this to just return func(net.Addr) string and the user can check for nil value instead of returning an extra bool. WDYT ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

done

@eshitachandwani eshitachandwani assigned easwars and unassigned ran-su Aug 18, 2026
Comment thread xds/server_options.go
Comment on lines 30 to 33
type serverOptions struct {
modeCallback ServingModeCallbackFunc
clientPoolForTesting *xdsclient.Pool
modeCallback ServingModeCallbackFunc
clientPoolForTesting *xdsclient.Pool
overrideListenerResourceName func(net.Addr) string
}

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.

How about we move this whole struct to internal/xds/server? What this would mean is that the existing public server options' implementation would modify this ServerOptions struct defined in the internal package.

This would also unify the handling in xds/server.go where you currently have separate handling for the public server options and the newly added internal server option.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I made some changes. Could you please take a look and see if I understand it correctly? Thanks

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

Labels

Area: xDS Includes everything xDS related, including LB policies used with xDS. Type: Feature New features or improvements in behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants