Skip to content

Commit

Permalink
perf(spanner): use passthrough with emulator endpoint (#10947)
Browse files Browse the repository at this point in the history
  • Loading branch information
rahul2393 authored Oct 3, 2024
1 parent c67f964 commit 9e964dd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
4 changes: 3 additions & 1 deletion spanner/admin/database/apiv1/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package database
import (
"context"
"os"
"regexp"

"google.golang.org/api/option"
"google.golang.org/grpc"
Expand All @@ -27,8 +28,9 @@ import (
func init() {
newDatabaseAdminClientHook = func(ctx context.Context, p clientHookParams) ([]option.ClientOption, error) {
if emulator := os.Getenv("SPANNER_EMULATOR_HOST"); emulator != "" {
schemeRemoved := regexp.MustCompile("^(http://|https://|passthrough:///)").ReplaceAllString(emulator, "")
return []option.ClientOption{
option.WithEndpoint(emulator),
option.WithEndpoint("passthrough:///" + schemeRemoved),
option.WithGRPCDialOption(grpc.WithTransportCredentials(insecure.NewCredentials())),
option.WithoutAuthentication(),
}, nil
Expand Down
4 changes: 3 additions & 1 deletion spanner/admin/instance/apiv1/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package instance
import (
"context"
"os"
"regexp"

"google.golang.org/api/option"
"google.golang.org/grpc"
Expand All @@ -27,8 +28,9 @@ import (
func init() {
newInstanceAdminClientHook = func(ctx context.Context, p clientHookParams) ([]option.ClientOption, error) {
if emulator := os.Getenv("SPANNER_EMULATOR_HOST"); emulator != "" {
schemeRemoved := regexp.MustCompile("^(http://|https://|passthrough:///)").ReplaceAllString(emulator, "")
return []option.ClientOption{
option.WithEndpoint(emulator),
option.WithEndpoint("passthrough:///" + schemeRemoved),
option.WithGRPCDialOption(grpc.WithTransportCredentials(insecure.NewCredentials())),
option.WithoutAuthentication(),
}, nil
Expand Down
6 changes: 4 additions & 2 deletions spanner/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,9 @@ func createGCPMultiEndpoint(cfg *grpcgcp.GCPMultiEndpointOptions, config ClientC
}
// Append emulator options if SPANNER_EMULATOR_HOST has been set.
if emulatorAddr := os.Getenv("SPANNER_EMULATOR_HOST"); emulatorAddr != "" {
schemeRemoved := regexp.MustCompile("^(http://|https://|passthrough:///)").ReplaceAllString(emulatorAddr, "")
emulatorOpts := []option.ClientOption{
option.WithEndpoint(emulatorAddr),
option.WithEndpoint("passthrough:///" + schemeRemoved),
option.WithGRPCDialOption(grpc.WithTransportCredentials(insecure.NewCredentials())),
option.WithoutAuthentication(),
internaloption.SkipDialSettingsValidation(),
Expand Down Expand Up @@ -403,8 +404,9 @@ func newClientWithConfig(ctx context.Context, database string, config ClientConf

// Append emulator options if SPANNER_EMULATOR_HOST has been set.
if emulatorAddr := os.Getenv("SPANNER_EMULATOR_HOST"); emulatorAddr != "" {
schemeRemoved := regexp.MustCompile("^(http://|https://|passthrough:///)").ReplaceAllString(emulatorAddr, "")
emulatorOpts := []option.ClientOption{
option.WithEndpoint(emulatorAddr),
option.WithEndpoint("passthrough:///" + schemeRemoved),
option.WithGRPCDialOption(grpc.WithTransportCredentials(insecure.NewCredentials())),
option.WithoutAuthentication(),
internaloption.SkipDialSettingsValidation(),
Expand Down

0 comments on commit 9e964dd

Please sign in to comment.