Skip to content

Conversation

@stagegrowth
Copy link

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

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Jan 7, 2026

CLA Signed

The committers listed above are authorized under a signed CLA.


/** Unit tests for {@link CallOptions}. */
@RunWith(JUnit4.class)
public class CallOptionsTest {
Copy link
Contributor

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?

Copy link
Author

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.

@kannanjgithub kannanjgithub added the kokoro:run Add this label to a PR to tell Kokoro the code is safe and tests can be run label Jan 9, 2026
@grpc-kokoro grpc-kokoro removed the kokoro:run Add this label to a PR to tell Kokoro the code is safe and tests can be run label Jan 9, 2026
*/
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1770")
public final class EquivalentAddressGroup {
private static final int MAX_ADDRESSES_TO_STRING = 100;
Copy link
Contributor

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.

Copy link
Author

@stagegrowth stagegrowth Jan 12, 2026

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.

Copy link
Member

@ejona86 ejona86 left a 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?

@stagegrowth
Copy link
Author

stagegrowth commented Jan 12, 2026

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.

@ejona86
Copy link
Member

ejona86 commented Jan 12, 2026

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.

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.

@stagegrowth stagegrowth force-pushed the feat/summarize-eag-to-string branch from ae4217e to e136990 Compare January 12, 2026 23:54
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.

Summarize EquivalentAddressGroup.toString() output for large address lists

4 participants