Skip to content

Commit dafbca2

Browse files
authored
perf(bigtable): use passthrough with emulator endpoint (#13739)
Fixes #10965 This change updates the Bigtable client to use the `passthrough:///` scheme when connecting to the emulator via `BIGTABLE_EMULATOR_HOST`. This ensures consistent behavior with other Google Cloud Go clients (e.g., Spanner #10947) and avoids potential gRPC name resolution issues by forcing the passthrough resolver. It handles `BIGTABLE_EMULATOR_HOST` values with or without an existing scheme (e.g. `localhost:9000` or `http://localhost:9000`).
1 parent 7d9d00c commit dafbca2

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

bigtable/internal/option/option.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"fmt"
2323
"log"
2424
"os"
25+
"regexp"
2526
"strconv"
2627
"strings"
2728
"time"
@@ -49,6 +50,8 @@ const (
4950
BigtableConnectionPoolEnvVar = "CBT_BIGTABLE_CONN_POOL"
5051
)
5152

53+
var schemeRegexp = regexp.MustCompile("^(http://|https://|passthrough:///)")
54+
5255
// mergeOutgoingMetadata returns a context populated by the existing outgoing
5356
// metadata merged with the provided mds.
5457
func mergeOutgoingMetadata(ctx context.Context, mds ...metadata.MD) context.Context {
@@ -108,7 +111,8 @@ func DefaultClientOptions(endpoint, mtlsEndpoint, scope, userAgent string) ([]op
108111
// Check the environment variables for the bigtable emulator.
109112
// Dial it directly and don't pass any credentials.
110113
if addr := os.Getenv("BIGTABLE_EMULATOR_HOST"); addr != "" {
111-
conn, err := grpc.Dial(addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
114+
schemeRemoved := schemeRegexp.ReplaceAllString(addr, "")
115+
conn, err := grpc.Dial("passthrough:///"+schemeRemoved, grpc.WithTransportCredentials(insecure.NewCredentials()))
112116
if err != nil {
113117
return nil, fmt.Errorf("emulator grpc.Dial: %w", err)
114118
}

0 commit comments

Comments
 (0)