Skip to content

feat: add gRPC-GCP channel pool as an option #1227

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

Merged
merged 18 commits into from
Jun 29, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add gRPC-GCP extension options to SpannerOptions
  • Loading branch information
nimf committed Jun 1, 2021
commit 76332de4a45901626c80b3326c850052f6e94267
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.google.grpc.gcp.GcpManagedChannelOptions;
import com.google.spanner.v1.ExecuteSqlRequest;
import com.google.spanner.v1.ExecuteSqlRequest.QueryOptions;
import com.google.spanner.v1.SpannerGrpc;
Expand Down Expand Up @@ -104,6 +105,7 @@ public class SpannerOptions extends ServiceOptions<Spanner, SpannerOptions> {
private final DatabaseAdminStubSettings databaseAdminStubSettings;
private final Duration partitionedDmlTimeout;
private final boolean useGrpcGcpExtension;
private final GcpManagedChannelOptions grpcGcpOptions;
private final boolean autoThrottleAdministrativeRequests;
private final boolean trackTransactionStarter;
/**
Expand Down Expand Up @@ -559,6 +561,7 @@ private SpannerOptions(Builder builder) {
}
partitionedDmlTimeout = builder.partitionedDmlTimeout;
useGrpcGcpExtension = builder.useGrpcGcpExtension;
grpcGcpOptions = builder.grpcGcpOptions;
autoThrottleAdministrativeRequests = builder.autoThrottleAdministrativeRequests;
trackTransactionStarter = builder.trackTransactionStarter;
defaultQueryOptions = builder.defaultQueryOptions;
Expand Down Expand Up @@ -638,7 +641,8 @@ public static class Builder
private DatabaseAdminStubSettings.Builder databaseAdminStubSettingsBuilder =
DatabaseAdminStubSettings.newBuilder();
private Duration partitionedDmlTimeout = Duration.ofHours(2L);
private boolean useGrpcGcpExtension = true;
private boolean useGrpcGcpExtension = false;
private GcpManagedChannelOptions grpcGcpOptions;
private boolean autoThrottleAdministrativeRequests = false;
private boolean trackTransactionStarter = false;
private Map<DatabaseId, QueryOptions> defaultQueryOptions = new HashMap<>();
Expand Down Expand Up @@ -686,7 +690,8 @@ private Builder() {
this.instanceAdminStubSettingsBuilder = options.instanceAdminStubSettings.toBuilder();
this.databaseAdminStubSettingsBuilder = options.databaseAdminStubSettings.toBuilder();
this.partitionedDmlTimeout = options.partitionedDmlTimeout;
this.useGrpcGcpExtension = useGrpcGcpExtension;
this.useGrpcGcpExtension = options.useGrpcGcpExtension;
this.grpcGcpOptions = options.grpcGcpOptions;
this.autoThrottleAdministrativeRequests = options.autoThrottleAdministrativeRequests;
this.trackTransactionStarter = options.trackTransactionStarter;
this.defaultQueryOptions = options.defaultQueryOptions;
Expand Down Expand Up @@ -1003,11 +1008,26 @@ public Builder setHost(String host) {
return this;
}

/**
* Sets the preference for gRPC-GCP extension (default: false). When enabled the gRPC-GCP
* channel pool will be used.
*/
public Builder setUseGrpcGcpExtension(boolean useGrpcGcpExtension) {
this.useGrpcGcpExtension = useGrpcGcpExtension;
return this;
}

/**
* Sets the options for gRPC-GCP extension. The metric registry and default Spanner metric
* labels will be added automatically.
*
* <p>Note that gRPC-GCP extension must be enabled first with {@code setUseGrpcGcpExtension}.
*/
public Builder setGrpcGcpOptions(GcpManagedChannelOptions options) {
this.grpcGcpOptions = options;
return this;
}

/**
* Sets the host of an emulator to use. By default the value is read from an environment
* variable. If the environment variable is not set, this will be <code>null</code>.
Expand Down Expand Up @@ -1112,6 +1132,10 @@ public boolean isUseGrpcGcpExtension() {
return useGrpcGcpExtension;
}

public GcpManagedChannelOptions getGrpcGcpOptions() {
return grpcGcpOptions;
}

public boolean isAutoThrottleAdministrativeRequests() {
return autoThrottleAdministrativeRequests;
}
Expand Down