Skip to content

balancer: expose endpoint weight and hostname as experimental APIs - #9074

Merged
easwars merged 13 commits into
grpc:masterfrom
hpathak01:hpathak01/issue-8971-expose-xds-attr
May 27, 2026
Merged

easwars merged 13 commits into
grpc:masterfrom
hpathak01:hpathak01/issue-8971-expose-xds-attr

Conversation

@hpathak01

@hpathak01 hpathak01 commented Apr 17, 2026

Copy link
Copy Markdown
Contributor

Description

This PR exposes two new experimental public APIs so that custom load balancing policies can access endpoint attributes that were previously only available via internal packages:

  • google.golang.org/grpc/balancer/weightSet, FromEndpoint, EndpointInfo
  • google.golang.org/grpc/balancer/hostnameSet, FromEndpoint, FromAddress

These attributes (especially weight) are required by custom balancers such as deterministic aperture / P2C that need EDS-provided endpoint details like weights etc.

Changes

  • New public package balancer/hostname with full experimental notices.
  • Moved internal/balancer/weight to public balancer/weight via git mv, added experimental notices.
  • Internal callers (ringhash, pickfirst, cdsbalancer, clusterimpl, xdsresource) updated to use the public packages directly.
  • Removed SetHostname and Hostname wrappers from xdsresource; callers now use hostname.Set and hostname.FromAddress directly.
  • Added table-driven unit tests for both new public packages.

Related Issues

Fixes #8971

Testing

  • All tests pass (go test -count=1 ./...)

Notes for Reviewers

  • The new APIs follow the exact same experimental pattern used by resolver/ringhash.
  • The "Dependency Changes" check fails because this PR intentionally adds two new public packages (balancer/weight and balancer/hostname).

RELEASE NOTES: none

@linux-foundation-easycla

linux-foundation-easycla Bot commented Apr 17, 2026

Copy link
Copy Markdown

CLA Signed

The committers listed above are authorized under a signed CLA.

@codecov

codecov Bot commented Apr 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.14%. Comparing base (06fc26a) to head (565012e).
⚠️ Report is 30 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9074      +/-   ##
==========================================
+ Coverage   80.52%   83.14%   +2.62%     
==========================================
  Files         413      418       +5     
  Lines       33543    33649     +106     
==========================================
+ Hits        27012    27979     +967     
+ Misses       4316     4248      -68     
+ Partials     2215     1422     -793     
Files with missing lines Coverage Δ
balancer/pickfirst/pickfirst.go 89.76% <ø> (ø)
balancer/ringhash/ringhash.go 94.11% <ø> (ø)
experimental/balancer/hostname/hostname.go 100.00% <100.00%> (ø)
experimental/balancer/weight/weight.go 100.00% <ø> (ø)
internal/xds/balancer/cdsbalancer/configbuilder.go 91.11% <100.00%> (ø)
internal/xds/balancer/clusterimpl/clusterimpl.go 88.25% <100.00%> (ø)
...nternal/xds/xdsclient/xdsresource/unmarshal_eds.go 96.07% <100.00%> (+4.30%) ⬆️

... and 58 files with indirect coverage changes

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

…rpc#8971)

- Add new public packages balancer/weight and balancer/hostname
  with Set/FromEndpoint and Set/Hostname/HostnameFromAddress helpers.
- Mark all new APIs as # Experimental with the standard notice.
- Update internal callers (ringhash, pickfirst, cdsbalancer, xdsresource)
  to use the public packages.
- Remove dead hostnameKeyType from xdsresource and delegate legacy
  Hostname() to the public API (fixes Authority_Rewrite_Mismatch test).
- Keep deprecated internal/balancer/weight package for transition.
- Add tests for the new public packages.
- Verified end-to-end with custom DAPerture balancer.
@hpathak01
hpathak01 force-pushed the hpathak01/issue-8971-expose-xds-attr branch from 7e7f078 to 5ed3447 Compare April 17, 2026 08:39
@hpathak01
hpathak01 marked this pull request as ready for review April 20, 2026 03:45
@easwars easwars added the Type: Feature New features or improvements in behavior label Apr 20, 2026
@easwars easwars added this to the 1.82 Release milestone Apr 20, 2026
@easwars easwars added the Area: Resolvers/Balancers Includes LB policy & NR APIs, resolver/balancer/picker wrappers, LB policy impls and utilities. label Apr 20, 2026
@easwars easwars changed the title [balancer] expose endpoint weight and hostname as experimental APIs (… balancer: expose endpoint weight and hostname as experimental APIs Apr 20, 2026
@easwars

easwars commented Apr 20, 2026

Copy link
Copy Markdown
Contributor

The "Dependency Changes" check fails because this PR intentionally adds two new public packages (balancer/weight and balancer/hostname).

Yes, that is expected.

@easwars

easwars commented Apr 20, 2026

Copy link
Copy Markdown
Contributor

@Pranjali-2501 : Could you please do a first pass.

@Pranjali-2501 Pranjali-2501 left a comment

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.

Hi @hpathak01, thanks for raising the PR.
I have added some comments, please take a look.

Comment thread balancer/hostname/hostname.go Outdated
Comment thread balancer/hostname/hostname.go Outdated
Comment thread balancer/pickfirst/pickfirst_ext_test.go Outdated
Comment thread internal/balancer/weight/weight.go
Comment thread internal/balancer/weight/weight_test.go Outdated
Comment thread internal/xds/balancer/cdsbalancer/configbuilder_test.go Outdated
Comment thread internal/xds/xdsclient/xdsresource/unmarshal_eds.go Outdated
Comment thread internal/xds/xdsclient/xdsresource/unmarshal_eds.go
Comment thread internal/xds/xdsclient/xdsresource/unmarshal_eds.go
Comment thread internal/xds/xdsclient/xdsresource/unmarshal_eds_test.go Outdated
Comment thread internal/xds/xdsclient/xdsresource/unmarshal_eds.go Outdated
Comment thread balancer/hostname/hostname_test.go Outdated
@Pranjali-2501

Copy link
Copy Markdown
Contributor

@hpathak01

Copy link
Copy Markdown
Contributor Author

@Pranjali-2501 Pranjali-2501 left a comment

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.

LGTM.

Comment thread balancer/hostname/hostname.go Outdated
@Pranjali-2501 Pranjali-2501 assigned easwars and unassigned hpathak01 Apr 23, 2026
@Pranjali-2501
Pranjali-2501 requested a review from easwars April 23, 2026 05:04
@hpathak01

Copy link
Copy Markdown
Contributor Author

Hi @easwars , just checking in — I've addressed all the review comments. Would you have a chance to take a look when you get a moment? Thanks!

@easwars easwars left a comment

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.

Apologies for the delay in reviewing this.

Comment thread balancer/hostname/hostname.go Outdated
Comment thread experimental/balancer/hostname/hostname.go
Comment thread balancer/hostname/hostname_test.go Outdated
Comment thread balancer/hostname/hostname_test.go Outdated
Comment thread balancer/hostname/hostname.go Outdated
Comment thread experimental/balancer/weight/weight.go
Comment thread balancer/weight/weight.go Outdated
Comment thread balancer/weight/weight.go Outdated
Comment thread balancer/weight/weight.go Outdated
Comment thread internal/xds/xdsclient/xdsresource/unmarshal_eds.go
@easwars easwars assigned hpathak01 and unassigned easwars May 20, 2026
@easwars
easwars merged commit 429e6e0 into grpc:master May 27, 2026
13 of 14 checks passed
goingforstudying-ctrl added a commit to goingforstudying-ctrl/grpc-go that referenced this pull request Jun 21, 2026
…rpc#9074)

### Description
This PR exposes two new **experimental** public APIs so that custom load
balancing policies can access endpoint attributes that were previously
only available via internal packages:

- `google.golang.org/grpc/balancer/weight` — `Set`, `FromEndpoint`, `EndpointInfo`
- `google.golang.org/grpc/balancer/hostname` — `Set`, `FromEndpoint`

These attributes (especially `weight`) are required by custom balancers
such as deterministic aperture / P2C that need EDS-provided endpoint
details like weights etc.

Fixes grpc#8971

RELEASE NOTES:
- experimental/balancer/hostname: New APIs to access endpoint hostname attributes
- experimental/balancer/weight: New APIs to access endpoint weight attributes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Resolvers/Balancers Includes LB policy & NR APIs, resolver/balancer/picker wrappers, LB policy impls and utilities. Type: Feature New features or improvements in behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose custom metadata from EDS response to custom LB policies

3 participants