Skip to content

Commit

Permalink
Add experimental API label and drop hostname from authorityOverrideHo…
Browse files Browse the repository at this point in the history
…stname.
  • Loading branch information
kannanjgithub committed Oct 30, 2024
1 parent 2435395 commit 2769441
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
22 changes: 12 additions & 10 deletions api/src/main/java/io/grpc/LoadBalancer.java
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ public static final class PickResult {
private final Status status;
// True if the result is created by withDrop()
private final boolean drop;
@Nullable private final String authorityOverrideHostname;
@Nullable private final String authorityOverride;

private PickResult(
@Nullable Subchannel subchannel, @Nullable ClientStreamTracer.Factory streamTracerFactory,
Expand All @@ -561,17 +561,17 @@ private PickResult(
this.streamTracerFactory = streamTracerFactory;
this.status = checkNotNull(status, "status");
this.drop = drop;
this.authorityOverrideHostname = null;
this.authorityOverride = null;
}

private PickResult(
@Nullable Subchannel subchannel, @Nullable ClientStreamTracer.Factory streamTracerFactory,
Status status, boolean drop, @Nullable String authorityOverrideHostname) {
Status status, boolean drop, @Nullable String authorityOverride) {
this.subchannel = subchannel;
this.streamTracerFactory = streamTracerFactory;
this.status = checkNotNull(status, "status");
this.drop = drop;
this.authorityOverrideHostname = authorityOverrideHostname;
this.authorityOverride = authorityOverride;
}

/**
Expand Down Expand Up @@ -655,12 +655,13 @@ public static PickResult withSubchannel(
* Same as {@code withSubchannel(subchannel, streamTracerFactory)} but with an authority name
* to override in the host header.
*/
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/11656")
public static PickResult withSubchannel(
Subchannel subchannel, @Nullable ClientStreamTracer.Factory streamTracerFactory,
@Nullable String authorityOverrideHostname) {
@Nullable String authorityOverride) {
return new PickResult(
checkNotNull(subchannel, "subchannel"), streamTracerFactory, Status.OK,
false, authorityOverrideHostname);
false, authorityOverride);
}

/**
Expand Down Expand Up @@ -706,10 +707,11 @@ public static PickResult withNoResult() {
return NO_RESULT;
}

/** Returns the authority override hostname if any. */
/** Returns the authority override if any. */
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/11656")
@Nullable
public String getAuthorityOverrideHostname() {
return authorityOverrideHostname;
public String getAuthorityOverride() {
return authorityOverride;
}

/**
Expand Down Expand Up @@ -766,7 +768,7 @@ public String toString() {
.add("streamTracerFactory", streamTracerFactory)
.add("status", status)
.add("drop", drop)
.add("authority-override", authorityOverrideHostname)
.add("authority-override", authorityOverride)
.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ public final ClientStream newStream(
callOptions = args.getCallOptions();
// User code provided authority takes precedence over the LB provided one.
if (callOptions.getAuthority() == null
&& pickResult.getAuthorityOverrideHostname() != null) {
callOptions = callOptions.withAuthority(pickResult.getAuthorityOverrideHostname());
&& pickResult.getAuthorityOverride() != null) {
callOptions = callOptions.withAuthority(pickResult.getAuthorityOverride());
}
ClientTransport transport = GrpcUtil.getTransportFromPickResult(pickResult,
callOptions.isWaitForReady());
Expand Down Expand Up @@ -288,8 +288,8 @@ final void reprocess(@Nullable SubchannelPicker picker) {
PickResult pickResult = picker.pickSubchannel(stream.args);
CallOptions callOptions = stream.args.getCallOptions();
// User code provided authority takes precedence over the LB provided one.
if (callOptions.getAuthority() == null && pickResult.getAuthorityOverrideHostname() != null) {
stream.setAuthority(pickResult.getAuthorityOverrideHostname());
if (callOptions.getAuthority() == null && pickResult.getAuthorityOverride() != null) {
stream.setAuthority(pickResult.getAuthorityOverride());
}
final ClientTransport transport = GrpcUtil.getTransportFromPickResult(pickResult,
callOptions.isWaitForReady());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ public void endpointAddressesAttachedWithClusterName() {
TestMethodDescriptors.voidMethod(), new Metadata(),
CallOptions.DEFAULT.withOption(AUTO_HOST_REWRITE_KEY, true), detailsConsumer);
PickResult result = currentPicker.pickSubchannel(pickSubchannelArgs);
assertThat(result.getAuthorityOverrideHostname()).isEqualTo("authority-host-name");
assertThat(result.getAuthorityOverride()).isEqualTo("authority-host-name");
} finally {
System.clearProperty("GRPC_EXPERIMENTAL_XDS_AUTHORITY_REWRITE");
}
Expand Down Expand Up @@ -847,7 +847,7 @@ public void endpointAddressesAttachedWithClusterName() {
pickSubchannelArgs = new PickSubchannelArgsImpl(
TestMethodDescriptors.voidMethod(), new Metadata(), CallOptions.DEFAULT, detailsConsumer);
PickResult result = currentPicker.pickSubchannel(pickSubchannelArgs);
assertThat(result.getAuthorityOverrideHostname()).isNull();
assertThat(result.getAuthorityOverride()).isNull();
}

@Test
Expand Down

0 comments on commit 2769441

Please sign in to comment.