Skip to content

resolver: Add resolver.EndpointMap.All() to iterate over keys and values#8867

Merged
easwars merged 5 commits into
grpc:masterfrom
Jille:iter-endpointmap
Feb 11, 2026
Merged

resolver: Add resolver.EndpointMap.All() to iterate over keys and values#8867
easwars merged 5 commits into
grpc:masterfrom
Jille:iter-endpointmap

Conversation

@Jille

@Jille Jille commented Jan 29, 2026

Copy link
Copy Markdown
Contributor

It's nicer than iterating over the keys and looking up their values.

RELEASE NOTES:

  • resolver: Add All() methods to AddressMap and EndpointMap that return iterators for efficient key-value pair traversal.

It's nicer than iterating over the keys and looking up their values.

RELEASE NOTES: N/A
@codecov

codecov Bot commented Jan 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.88889% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.04%. Comparing base (69b542a) to head (e783a46).
⚠️ Report is 16 commits behind head on master.

Files with missing lines Patch % Lines
resolver/map.go 63.63% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8867      +/-   ##
==========================================
+ Coverage   82.42%   83.04%   +0.62%     
==========================================
  Files         414      414              
  Lines       32750    32818      +68     
==========================================
+ Hits        26994    27255     +261     
- Misses       4096     4104       +8     
+ Partials     1660     1459     -201     
Files with missing lines Coverage Δ
balancer/base/balancer.go 43.80% <100.00%> (-6.20%) ⬇️
balancer/endpointsharding/endpointsharding.go 83.01% <100.00%> (-13.84%) ⬇️
balancer/leastrequest/leastrequest.go 88.65% <100.00%> (ø)
balancer/pickfirst/pickfirst.go 89.28% <100.00%> (-0.34%) ⬇️
balancer/ringhash/ringhash.go 94.11% <100.00%> (ø)
balancer/weightedroundrobin/balancer.go 83.27% <100.00%> (ø)
internal/xds/balancer/outlierdetection/balancer.go 89.46% <100.00%> (+0.46%) ⬆️
resolver/map.go 69.30% <63.63%> (-24.95%) ⬇️

... and 36 files with indirect coverage changes

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

@arjan-bal arjan-bal self-requested a review February 3, 2026 04:41
@arjan-bal arjan-bal self-assigned this Feb 3, 2026

@arjan-bal arjan-bal 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 @Jille, thanks for the contribution. In addition to being more ergonomic, the iterator approach is a nice optimization as it avoids allocating a slice for the return values.

Could you also update existing call sites of Keys() and Values() within the codebase to use the new iterator methods where it makes sense? This would help validate the new API and provide better coverage.

Comment thread resolver/map_test.go
@arjan-bal arjan-bal assigned Jille and unassigned arjan-bal Feb 3, 2026
@arjan-bal arjan-bal added Type: Feature New features or improvements in behavior Area: Resolvers/Balancers Includes LB policy & NR APIs, resolver/balancer/picker wrappers, LB policy impls and utilities. labels Feb 3, 2026
@arjan-bal arjan-bal added this to the 1.80 Release milestone Feb 3, 2026
@Jille

Jille commented Feb 4, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review @arjan-bal :)

@arjan-bal

Copy link
Copy Markdown
Contributor

/gemini review

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces a new All() method to AddressMapV2 and EndpointMap for iterating over key-value pairs, which is a great improvement for code clarity and efficiency. The refactoring to adopt this new method is mostly well-executed. However, I've identified a few instances where the new All() method isn't fully utilized, leading to redundant Get() calls that this PR aims to eliminate. My suggestions below address these points to better align the changes with the PR's goal.

Comment thread balancer/base/balancer.go Outdated
Comment thread balancer/base/balancer.go Outdated
Comment thread balancer/endpointsharding/endpointsharding.go Outdated

@arjan-bal arjan-bal 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! Adding a second reviewer. Please check the minor suggestions from Gemini.

@arjan-bal arjan-bal assigned Jille and easwars and unassigned arjan-bal Feb 5, 2026
@Jille

Jille commented Feb 6, 2026

Copy link
Copy Markdown
Contributor Author

I'd swear I checked whether I saw that pattern. Maybe I only checked for EndpointMap and not AddressMap.

Applying Gemini's changes broke the indentation, so I overwrote that.

Also, hey Easwar :)

@easwars

easwars commented Feb 6, 2026

Copy link
Copy Markdown
Contributor

Also, hey Easwar :)

Yes. Long time. Good to see you here.

@easwars

easwars commented Feb 6, 2026

Copy link
Copy Markdown
Contributor

@arjan-bal
Sorry, I forget, did we decide that we should deprecate the Keys() and Values() in favor of All()?

@easwars easwars assigned arjan-bal and unassigned Jille Feb 6, 2026
@arjan-bal

Copy link
Copy Markdown
Contributor

Yes, we discussed this in the gRPC Go maintainers group and decided to deprecate the Keys() and Values() methods, as the new All() method is more ergonomic and performant for all use cases. I had planned to handle this in a follow-up PR, but @Jille, if possible, could you add a deprecation notice to those functions now, suggesting users switch to All()?

@arjan-bal arjan-bal assigned Jille and unassigned arjan-bal Feb 9, 2026
Moved the comment from EndpointMap.Keys() to EndpointMap.All()
@Jille

Jille commented Feb 9, 2026

Copy link
Copy Markdown
Contributor Author

np. Done.

@easwars easwars merged commit e08fc36 into grpc:master Feb 11, 2026
14 checks passed
@easwars

easwars commented Feb 11, 2026

Copy link
Copy Markdown
Contributor

Thanks for your contribution, @Jille !

@Jille Jille deleted the iter-endpointmap branch February 11, 2026 07:37
mbissa pushed a commit to mbissa/grpc-go that referenced this pull request Feb 16, 2026
…ues (grpc#8867)

It's nicer than iterating over the keys and looking up their values.

RELEASE NOTES:
* resolver: Add `All()` methods to `AddressMap` and `EndpointMap` that
return iterators for efficient key-value pair traversal.
Pranjali-2501 pushed a commit to Pranjali-2501/grpc-go that referenced this pull request Feb 23, 2026
…ues (grpc#8867)

It's nicer than iterating over the keys and looking up their values.

RELEASE NOTES:
* resolver: Add `All()` methods to `AddressMap` and `EndpointMap` that
return iterators for efficient key-value pair traversal.
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.

3 participants