Skip to content

Commit

Permalink
refactor: Add TransportChannelProvider's endpoint to EndpointContext (#…
Browse files Browse the repository at this point in the history
…2294)

* refactor: Add transportchannelprovider's endpoint to EndpointContext

* chore: Add Endpoint tests for ClientContext

* chore: Resolve PR comments
  • Loading branch information
lqiu96 committed Dec 11, 2023
1 parent 4029fbd commit c0e03cd
Show file tree
Hide file tree
Showing 7 changed files with 179 additions and 21 deletions.
Expand Up @@ -430,6 +430,7 @@ private ManagedChannel createSingleChannel() throws IOException {
}

/** The endpoint to be used for the channel. */
@Override
public String getEndpoint() {
return endpoint;
}
Expand Down
Expand Up @@ -207,6 +207,7 @@ private HttpJsonTransportChannel createChannel() throws IOException, GeneralSecu
}

/** The endpoint to be used for the channel. */
@Override
public String getEndpoint() {
return endpoint;
}
Expand Down
6 changes: 6 additions & 0 deletions gax-java/gax/clirr-ignored-differences.xml
Expand Up @@ -19,4 +19,10 @@
<method>*setWaitTimeout*</method>
<to>com.google.api.gax.rpc.ServerStreamingCallSettings$Builder</to>
</difference>
<!-- Add a default Endpoint Getter -->
<difference>
<differenceType>7012</differenceType>
<className>com/google/api/gax/rpc/TransportChannelProvider</className>
<method>* getEndpoint()</method>
</difference>
</differences>
Expand Up @@ -203,6 +203,8 @@ public static ClientContext create(StubSettings settings) throws IOException {
EndpointContext endpointContext =
EndpointContext.newBuilder()
.setClientSettingsEndpoint(settings.getEndpoint())
.setTransportChannelProviderEndpoint(
settings.getTransportChannelProvider().getEndpoint())
.setMtlsEndpoint(settings.getMtlsEndpoint())
.setSwitchToMtlsEndpointAllowed(settings.getSwitchToMtlsEndpointAllowed())
.build();
Expand Down
Expand Up @@ -46,6 +46,13 @@ public abstract class EndpointContext {
@Nullable
public abstract String clientSettingsEndpoint();

/**
* TransportChannelProviderEndpoint is the endpoint value set via the TransportChannelProvider
* class.
*/
@Nullable
public abstract String transportChannelProviderEndpoint();

@Nullable
public abstract String mtlsEndpoint();

Expand All @@ -65,9 +72,13 @@ public static Builder newBuilder() {
@VisibleForTesting
void determineEndpoint() throws IOException {
MtlsProvider mtlsProvider = mtlsProvider() == null ? new MtlsProvider() : mtlsProvider();
String customEndpoint =
transportChannelProviderEndpoint() == null
? clientSettingsEndpoint()
: transportChannelProviderEndpoint();
resolvedEndpoint =
mtlsEndpointResolver(
clientSettingsEndpoint(), mtlsEndpoint(), switchToMtlsEndpointAllowed(), mtlsProvider);
customEndpoint, mtlsEndpoint(), switchToMtlsEndpointAllowed(), mtlsProvider);
}

// This takes in parameters because determineEndpoint()'s logic will be updated
Expand Down Expand Up @@ -111,6 +122,12 @@ public abstract static class Builder {
*/
public abstract Builder setClientSettingsEndpoint(String clientSettingsEndpoint);

/**
* TransportChannelProviderEndpoint is the endpoint value set via the TransportChannelProvider
* class.
*/
public abstract Builder setTransportChannelProviderEndpoint(String transportChannelEndpoint);

public abstract Builder setMtlsEndpoint(String mtlsEndpoint);

public abstract Builder setSwitchToMtlsEndpointAllowed(boolean switchToMtlsEndpointAllowed);
Expand Down
Expand Up @@ -142,4 +142,13 @@ public interface TransportChannelProvider {
* <p>This string can be used for identifying transports for switching logic.
*/
String getTransportName();

/**
* User set custom endpoint for the Transport Channel Provider
*
* <p>This is the unresolved endpoint used by GAPICs
*/
default String getEndpoint() {
return null;
}
}

0 comments on commit c0e03cd

Please sign in to comment.