-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat(Datastore): Swap the default transport from HttpJson to gRPC #12977
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -35,6 +35,7 @@ | |||||||||
| import com.google.cloud.grpc.GrpcTransportOptions; | ||||||||||
| import com.google.cloud.http.HttpTransportOptions; | ||||||||||
| import com.google.common.base.MoreObjects; | ||||||||||
| import com.google.common.base.Preconditions; | ||||||||||
| import com.google.common.collect.ImmutableSet; | ||||||||||
| import java.io.IOException; | ||||||||||
| import java.lang.reflect.Method; | ||||||||||
|
|
@@ -129,7 +130,10 @@ public static class Builder extends ServiceOptions.Builder<Datastore, DatastoreO | |||||||||
| private String databaseId; | ||||||||||
| private TransportChannelProvider channelProvider = null; | ||||||||||
| private String host; | ||||||||||
| private TransportOptions transportOptions; | ||||||||||
|
|
||||||||||
| @Nonnull | ||||||||||
| private TransportOptions transportOptions = | ||||||||||
| new DatastoreDefaults().getDefaultTransportOptions(); | ||||||||||
|
|
||||||||||
| @Nullable private DatastoreOpenTelemetryOptions openTelemetryOptions = null; | ||||||||||
|
|
||||||||||
|
|
@@ -141,13 +145,35 @@ private Builder(DatastoreOptions options) { | |||||||||
| this.databaseId = options.databaseId; | ||||||||||
| this.openTelemetryOptions = options.openTelemetryOptions; | ||||||||||
| this.channelProvider = validateChannelProvider(options.channelProvider); | ||||||||||
| this.host = options.getHost(); | ||||||||||
| this.transportOptions = options.getTransportOptions(); | ||||||||||
|
Comment on lines
147
to
+149
Contributor
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. These assignments are redundant and potentially introduce a bug. The
Suggested change
References
|
||||||||||
| } | ||||||||||
|
|
||||||||||
| private TransportChannelProvider validateChannelProvider( | ||||||||||
| TransportChannelProvider channelProvider) { | ||||||||||
| Preconditions.checkNotNull(channelProvider, "TransportChannelProvider cannot be null"); | ||||||||||
| if (!(channelProvider instanceof InstantiatingGrpcChannelProvider)) { | ||||||||||
| throw new IllegalArgumentException( | ||||||||||
| "Only GRPC channels are allowed for " + API_SHORT_NAME + "."); | ||||||||||
| } | ||||||||||
| return channelProvider; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * Sets the transport options. | ||||||||||
| * | ||||||||||
| * @param transportOptions the transport options to set, must be {@link HttpTransportOptions} or | ||||||||||
| * {@link GrpcTransportOptions} | ||||||||||
| * @return the builder | ||||||||||
| * @throws IllegalArgumentException if the transport options are not supported | ||||||||||
| */ | ||||||||||
| @Override | ||||||||||
| public Builder setTransportOptions(TransportOptions transportOptions) { | ||||||||||
| if (!(transportOptions instanceof HttpTransportOptions)) { | ||||||||||
| public Builder setTransportOptions(@Nonnull TransportOptions transportOptions) { | ||||||||||
| Preconditions.checkNotNull(transportOptions, "TransportOptions cannot be null"); | ||||||||||
| if (!(transportOptions instanceof HttpTransportOptions) | ||||||||||
| && !(transportOptions instanceof GrpcTransportOptions)) { | ||||||||||
| throw new IllegalArgumentException( | ||||||||||
| "Only http transport is allowed for " + API_SHORT_NAME + "."); | ||||||||||
| "Only http and grpc transport are allowed for " + API_SHORT_NAME + "."); | ||||||||||
| } | ||||||||||
| this.transportOptions = transportOptions; | ||||||||||
| return super.setTransportOptions(transportOptions); | ||||||||||
|
Comment on lines
178
to
179
Contributor
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 assignment
Suggested change
|
||||||||||
|
|
@@ -185,10 +211,28 @@ public Builder setChannelProvider(TransportChannelProvider channelProvider) { | |||||||||
| return this; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * Builds the {@link DatastoreOptions} instance. | ||||||||||
| * | ||||||||||
| * <p>If the host is not explicitly set, it defaults to the transport-specific default host: | ||||||||||
| * | ||||||||||
| * <ul> | ||||||||||
| * <li>gRPC: {@code datastore.googleapis.com:443} | ||||||||||
| * <li>HTTP: {@code https://datastore.googleapis.com} | ||||||||||
| * </ul> | ||||||||||
| * | ||||||||||
| * @return the {@link DatastoreOptions} instance | ||||||||||
| */ | ||||||||||
| @Override | ||||||||||
| public DatastoreOptions build() { | ||||||||||
| if (this.host == null && this.transportOptions instanceof GrpcTransportOptions) { | ||||||||||
| this.setHost(DatastoreSettings.getDefaultEndpoint()); | ||||||||||
| if (this.host == null) { | ||||||||||
| // Use whatever host value the user passes in, otherwise use the transport specific default | ||||||||||
| // host values | ||||||||||
| if (this.transportOptions instanceof GrpcTransportOptions) { | ||||||||||
| this.setHost(DatastoreSettings.getDefaultEndpoint()); | ||||||||||
| } else if (this.transportOptions instanceof HttpTransportOptions) { | ||||||||||
| this.setHost(com.google.datastore.v1.client.DatastoreFactory.DEFAULT_HOST); | ||||||||||
| } | ||||||||||
| } | ||||||||||
| return new DatastoreOptions(this); | ||||||||||
| } | ||||||||||
|
|
@@ -218,15 +262,6 @@ public Builder setOpenTelemetryOptions( | |||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| private static TransportChannelProvider validateChannelProvider( | ||||||||||
| TransportChannelProvider channelProvider) { | ||||||||||
| if (channelProvider != null && !(channelProvider instanceof InstantiatingGrpcChannelProvider)) { | ||||||||||
| throw new IllegalArgumentException( | ||||||||||
| "Only GRPC channels are allowed for " + API_SHORT_NAME + "."); | ||||||||||
| } | ||||||||||
| return channelProvider; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| private DatastoreOptions(Builder builder) { | ||||||||||
| super(DatastoreFactory.class, DatastoreRpcFactory.class, builder, new DatastoreDefaults()); | ||||||||||
|
|
||||||||||
|
|
@@ -310,8 +345,8 @@ public TransportOptions getDefaultTransportOptions() { | |||||||||
| return TRANSPORT_OPTIONS; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| public static HttpTransportOptions.Builder getDefaultTransportOptionsBuilder() { | ||||||||||
| return HttpTransportOptions.newBuilder(); | ||||||||||
| public static GrpcTransportOptions.Builder getDefaultTransportOptionsBuilder() { | ||||||||||
| return GrpcTransportOptions.newBuilder(); | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
|
|
||||||||||
Uh oh!
There was an error while loading. Please reload this page.