-
Notifications
You must be signed in to change notification settings - Fork 53
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
fix: Return resolved endpoint from StubSettings' Builder #2715
Changes from 3 commits
d184b42
0aff73a
946c403
03d6b1e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -266,6 +266,7 @@ public abstract static class Builder< | |
@Nonnull private ApiTracerFactory tracerFactory; | ||
private boolean deprecatedExecutorProviderSet; | ||
private String universeDomain; | ||
private final EndpointContext endpointContext; | ||
|
||
/** | ||
* Indicate when creating transport whether it is allowed to use mTLS endpoint instead of the | ||
|
@@ -300,6 +301,9 @@ protected Builder(StubSettings settings) { | |
this.switchToMtlsEndpointAllowed = | ||
settings.getEndpointContext().switchToMtlsEndpointAllowed(); | ||
this.universeDomain = settings.getEndpointContext().universeDomain(); | ||
// Store the EndpointContext that was already created. This is used to return the state | ||
// of the EndpointContext prior to any new modifications | ||
this.endpointContext = settings.getEndpointContext(); | ||
} | ||
|
||
/** Get Quota Project ID from Client Context * */ | ||
|
@@ -327,16 +331,22 @@ protected Builder(ClientContext clientContext) { | |
this.headerProvider = new NoHeaderProvider(); | ||
this.internalHeaderProvider = new NoHeaderProvider(); | ||
this.clock = NanoClock.getDefaultClock(); | ||
this.clientSettingsEndpoint = null; | ||
this.transportChannelProviderEndpoint = null; | ||
this.mtlsEndpoint = null; | ||
this.quotaProjectId = null; | ||
this.streamWatchdogProvider = InstantiatingWatchdogProvider.create(); | ||
this.streamWatchdogCheckInterval = Duration.ofSeconds(10); | ||
this.tracerFactory = BaseApiTracerFactory.getInstance(); | ||
this.deprecatedExecutorProviderSet = false; | ||
this.gdchApiAudience = null; | ||
|
||
this.clientSettingsEndpoint = null; | ||
this.transportChannelProviderEndpoint = null; | ||
this.mtlsEndpoint = null; | ||
this.switchToMtlsEndpointAllowed = false; | ||
this.universeDomain = null; | ||
// Attempt to create an empty, non-functioning EndpointContext by default. The client will | ||
// have | ||
// a valid EndpointContext with user configurations after the client has been initialized. | ||
this.endpointContext = EndpointContext.getDefaultInstance(); | ||
} else { | ||
ExecutorProvider fixedExecutorProvider = | ||
FixedExecutorProvider.create(clientContext.getExecutor()); | ||
|
@@ -365,6 +375,9 @@ protected Builder(ClientContext clientContext) { | |
this.switchToMtlsEndpointAllowed = | ||
clientContext.getEndpointContext().switchToMtlsEndpointAllowed(); | ||
this.universeDomain = clientContext.getEndpointContext().universeDomain(); | ||
// Store the EndpointContext that was already created. This is used to return the state | ||
// of the EndpointContext prior to any new modifications | ||
this.endpointContext = clientContext.getEndpointContext(); | ||
} | ||
} | ||
|
||
|
@@ -584,8 +597,13 @@ public ApiClock getClock() { | |
return clock; | ||
} | ||
|
||
/** | ||
* @return the resolved endpoint when the Builder was created. If other parameters are then set | ||
* in the builder, the resolved endpoint is not automatically updated. The resolved endpoint | ||
* will only be recomputed when the StubSettings is built again. | ||
*/ | ||
public String getEndpoint() { | ||
return clientSettingsEndpoint; | ||
return endpointContext.resolvedEndpoint(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A fully compatible solution might be
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, I think you are right. A valid StubSettings converted to a Builder will still be able to have the resolved endpoint. |
||
} | ||
|
||
public String getMtlsEndpoint() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be package private?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm using this inside GrpcCallContext (gax-grpc) and HttpJsonCallContext (gax-httpsjon) and can't access it otherwise.