From 2769441ebb7f96fb49fe9161ca2809591123edb0 Mon Sep 17 00:00:00 2001 From: Kannan J Date: Wed, 30 Oct 2024 07:20:32 +0000 Subject: [PATCH] Add experimental API label and drop hostname from authorityOverrideHostname. --- api/src/main/java/io/grpc/LoadBalancer.java | 22 ++++++++++--------- .../grpc/internal/DelayedClientTransport.java | 8 +++---- .../grpc/xds/ClusterImplLoadBalancerTest.java | 4 ++-- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/api/src/main/java/io/grpc/LoadBalancer.java b/api/src/main/java/io/grpc/LoadBalancer.java index 6f83e48f8a1..e1f2f17fd29 100644 --- a/api/src/main/java/io/grpc/LoadBalancer.java +++ b/api/src/main/java/io/grpc/LoadBalancer.java @@ -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, @@ -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; } /** @@ -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); } /** @@ -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; } /** @@ -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(); } diff --git a/core/src/main/java/io/grpc/internal/DelayedClientTransport.java b/core/src/main/java/io/grpc/internal/DelayedClientTransport.java index f5f213ddb13..ae173f4ac26 100644 --- a/core/src/main/java/io/grpc/internal/DelayedClientTransport.java +++ b/core/src/main/java/io/grpc/internal/DelayedClientTransport.java @@ -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()); @@ -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()); diff --git a/xds/src/test/java/io/grpc/xds/ClusterImplLoadBalancerTest.java b/xds/src/test/java/io/grpc/xds/ClusterImplLoadBalancerTest.java index 83c88e5715f..0d18af0b04a 100644 --- a/xds/src/test/java/io/grpc/xds/ClusterImplLoadBalancerTest.java +++ b/xds/src/test/java/io/grpc/xds/ClusterImplLoadBalancerTest.java @@ -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"); } @@ -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