This repository has been archived by the owner on Sep 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 119
feat: add an option to enable DirectPath xDS #1968
Closed
Closed
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -109,6 +109,7 @@ public final class InstantiatingGrpcChannelProvider implements TransportChannelP | |
@Nullable private final Credentials credentials; | ||
@Nullable private final ChannelPrimer channelPrimer; | ||
@Nullable private final Boolean attemptDirectPath; | ||
@Nullable private final Boolean useDirectPathXds; | ||
@Nullable private final Boolean allowNonDefaultServiceAccount; | ||
@VisibleForTesting final ImmutableMap<String, ?> directPathServiceConfig; | ||
@Nullable private final MtlsProvider mtlsProvider; | ||
|
@@ -134,6 +135,7 @@ private InstantiatingGrpcChannelProvider(Builder builder) { | |
this.credentials = builder.credentials; | ||
this.channelPrimer = builder.channelPrimer; | ||
this.attemptDirectPath = builder.attemptDirectPath; | ||
this.useDirectPathXds = builder.useDirectPathXds; | ||
this.allowNonDefaultServiceAccount = builder.allowNonDefaultServiceAccount; | ||
this.directPathServiceConfig = | ||
builder.directPathServiceConfig == null | ||
|
@@ -262,6 +264,20 @@ private boolean isDirectPathEnabled(String serviceAddress) { | |
return false; | ||
} | ||
|
||
private boolean isDirectPathXdsUsed() { | ||
// Method 1: Enable DirectPath xDS by env. | ||
String directPathXdsEnv = envProvider.getenv(DIRECT_PATH_ENV_ENABLE_XDS); | ||
boolean isDirectPathXdsEnv = Boolean.parseBoolean(directPathXdsEnv); | ||
if (isDirectPathXdsEnv) { | ||
return true; | ||
} | ||
// Method 2: Enable DirectPath xDS by option. | ||
if (useDirectPathXds != null) { | ||
BenWhitehead marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return useDirectPathXds; | ||
} | ||
return false; | ||
} | ||
|
||
private boolean isNonDefaultServiceAccountAllowed() { | ||
if (allowNonDefaultServiceAccount != null && allowNonDefaultServiceAccount) { | ||
return true; | ||
|
@@ -324,7 +340,7 @@ && isOnComputeEngine()) { | |
CallCredentials callCreds = MoreCallCredentials.from(credentials); | ||
ChannelCredentials channelCreds = | ||
GoogleDefaultChannelCredentials.newBuilder().callCredentials(callCreds).build(); | ||
isDirectPathXdsEnabled = Boolean.parseBoolean(envProvider.getenv(DIRECT_PATH_ENV_ENABLE_XDS)); | ||
isDirectPathXdsEnabled = isDirectPathXdsUsed(); | ||
if (isDirectPathXdsEnabled) { | ||
// google-c2p: CloudToProd(C2P) Directpath. This scheme is defined in | ||
// io.grpc.googleapis.GoogleCloudToProdNameResolverProvider. | ||
|
@@ -450,6 +466,7 @@ public static final class Builder { | |
@Nullable private ChannelPrimer channelPrimer; | ||
private ChannelPoolSettings channelPoolSettings; | ||
@Nullable private Boolean attemptDirectPath; | ||
@Nullable private Boolean useDirectPathXds; | ||
@Nullable private Boolean allowNonDefaultServiceAccount; | ||
@Nullable private ImmutableMap<String, ?> directPathServiceConfig; | ||
|
||
|
@@ -476,6 +493,7 @@ private Builder(InstantiatingGrpcChannelProvider provider) { | |
this.channelPrimer = provider.channelPrimer; | ||
this.channelPoolSettings = provider.channelPoolSettings; | ||
this.attemptDirectPath = provider.attemptDirectPath; | ||
this.useDirectPathXds = provider.useDirectPathXds; | ||
this.allowNonDefaultServiceAccount = provider.allowNonDefaultServiceAccount; | ||
this.directPathServiceConfig = provider.directPathServiceConfig; | ||
this.mtlsProvider = provider.mtlsProvider; | ||
|
@@ -684,6 +702,13 @@ public Builder setAllowNonDefaultServiceAccount(boolean allowNonDefaultServiceAc | |
return this; | ||
} | ||
|
||
/** Use DirectPath xDS. Only valid if DirectPath is attempted. */ | ||
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. Document that an environment variable could override this option. 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. The new API is used to enable DirectPath xDS, but not disable. So I removed the bool parameter. In this way, the environment can not override the option. |
||
@InternalApi("For internal use by google-cloud-java clients only") | ||
public Builder setUseDirectPathXds(boolean useDirectPathXds) { | ||
this.useDirectPathXds = useDirectPathXds; | ||
return this; | ||
} | ||
|
||
/** | ||
* Sets a service config for direct path. If direct path is not enabled, the provided service | ||
* config will be ignored. | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 we test this behavior in unit tests?
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.
Added.