Skip to content
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

core: Add Attributes.Key for authority in EquivalentAddressGroup (#4469) #6126

Merged
merged 3 commits into from Sep 12, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions api/src/main/java/io/grpc/EquivalentAddressGroup.java
Expand Up @@ -35,6 +35,12 @@
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1770")
public final class EquivalentAddressGroup {

/**
* The authority to be used when constructing Subchannels for this EquivalentAddressGroup.
*/
@Attr
Copy link
Member

Choose a reason for hiding this comment

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

Add an @ExperimentalApi annotation here. Create a new issue to stabilize the API, and include it as the value. You can look at other experimental apis to see the format.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

public static final Attributes.Key<String> ATTR_AUTHORITY_OVERRIDE =
Attributes.Key.create("io.grpc.grpclb.authorityOverride");
Copy link
Member

Choose a reason for hiding this comment

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

I think this is not related to io.grpc.grpclb. Maybe io.grpc.EquivalentAddressGroup.authorityOverride is a better name.

Copy link
Member

Choose a reason for hiding this comment

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

Done. I went ahead and made this change, since it was trivial.

private final List<SocketAddress> addrs;
private final Attributes attrs;

Expand Down
7 changes: 5 additions & 2 deletions core/src/main/java/io/grpc/internal/InternalSubchannel.java
Expand Up @@ -231,10 +231,13 @@ private void startNewTransport() {
address = proxiedAddr.getTargetAddress();
}

Attributes currentEagAttributes = addressIndex.getCurrentEagAttributes();
String eagChannelAuthority = currentEagAttributes
.get(EquivalentAddressGroup.ATTR_AUTHORITY_OVERRIDE);
ClientTransportFactory.ClientTransportOptions options =
new ClientTransportFactory.ClientTransportOptions()
.setAuthority(authority)
.setEagAttributes(addressIndex.getCurrentEagAttributes())
.setAuthority(eagChannelAuthority != null ? eagChannelAuthority : authority)
.setEagAttributes(currentEagAttributes)
.setUserAgent(userAgent)
.setHttpConnectProxiedSocketAddress(proxiedAddr);
TransportLogger transportLogger = new TransportLogger();
Expand Down
16 changes: 16 additions & 0 deletions core/src/test/java/io/grpc/internal/InternalSubchannelTest.java
Expand Up @@ -176,6 +176,22 @@ public void constructor_eagListWithNull_throws() {
isA(TransportLogger.class));
}

@Test public void eagAuthorityOverride_propagatesToTransport() {
SocketAddress addr = new SocketAddress() {};
String overriddenAuthority = "authority-override";
Attributes attr = Attributes.newBuilder()
.set(EquivalentAddressGroup.ATTR_AUTHORITY_OVERRIDE, overriddenAuthority).build();
createInternalSubchannel(new EquivalentAddressGroup(Arrays.asList(addr), attr));

// First attempt
assertNull(internalSubchannel.obtainActiveTransport());
assertEquals(CONNECTING, internalSubchannel.getState());
verify(mockTransportFactory).newClientTransport(
eq(addr),
eq(createClientTransportOptions().setAuthority(overriddenAuthority).setEagAttributes(attr)),
isA(TransportLogger.class));
}

@Test public void singleAddressReconnect() {
SocketAddress addr = mock(SocketAddress.class);
createInternalSubchannel(addr);
Expand Down