-
Notifications
You must be signed in to change notification settings - Fork 4k
api: Summarize EquivalentAddressGroup toString #12600
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
|
||
| /** Unit tests for {@link CallOptions}. */ | ||
| @RunWith(JUnit4.class) | ||
| public class CallOptionsTest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes in this test seem unrelated to the PR description. Can you move it to a separate PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback. I’ve reverted the CallOptionsTest refactor in this PR since it’s unrelated to the change. I can follow up with a separate PR if we still want that refactor.
| */ | ||
| @ExperimentalApi("https://github.com/grpc/grpc-java/issues/1770") | ||
| public final class EquivalentAddressGroup { | ||
| private static final int MAX_ADDRESSES_TO_STRING = 100; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just make it package-private and access it directly from the tests without the use of reflection.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kannanjgithub Thanks for the suggestion. I’ve made MAX_ADDRESSES_TO_STRING package-private and updated the tests to access it directly, removing the reflection helper.
ejona86
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this change will actually do anything in practice.
It is very rare to have more than 2 addresses in an EAG. When there are many addresses, that is a list of EAGs. Did you actually test this improves the situation for whatever you were seeing?
Hi, thanks for the thoughtful feedback. I agree that in the xDS path it’s uncommon to have more than two addresses in a single EquivalentAddressGroup, and that large endpoint sets are usually represented as a list of EAGs. My understanding, though, is that EquivalentAddressGroup is used more broadly than just xDS. For example, in the grpclb path or in some DNS- or proxy-based NameResolver implementations, a single EAG may contain multiple addresses, in which case toString() could still produce very large log lines. Please let me know if this understanding is off or if there are important constraints I’m missing. With that in mind, this change is not meant to target xDS specifically, but rather to explore a small improvement to EAG logging robustness in more general or atypical cases. To help make this concrete, I added a small test that constructs an EAG with a larger number of addresses, mainly to make the before/after toString() behavior easier to observe. Thanks again for the review and the helpful questions. |
I was agreeing it could contain multiple, but like "two." The point of multiple addresses in an EAG is for addresses to the same machine, like IPv4 and IPv6. I'd love people to use it for local-link IPv6 addresses, and potentially multiple public IPv6 addresses, but we're still talking relatively few. Back when the TODO was added, the pick first policy would combine all the EAGs into a single large EAG. But we stopped doing that later that year. So I think the TODO should just be deleted. |
ae4217e to
e136990
Compare
Background
EquivalentAddressGroup.toString() currently prints the full address list, which can become extremely large and noisy for big address sets. This makes logs and test output hard to read and can obscure useful information.
Changes
This PR adds a hard cap to the number of addresses rendered in toString() and summarizes the remainder (e.g., “... N more”). It also adds focused unit tests to validate the large-list and boundary behaviors, and refactors related CallOptionsTest assertions using a small Truth subject for clearer equivalence checks.
Purpose
Keep toString() output readable even with very large address lists
Ensure the summarization behavior is covered by unit tests
Improve clarity of CallOptions equivalence assertions in tests
Note
The summary threshold is defined as a private constant and is only used for output formatting. It does not change the underlying address data or behavior—only the string representation.
Fixes #12593