@@ -12,7 +12,6 @@ import (
12
12
"crypto/tls"
13
13
"errors"
14
14
"log"
15
- "os"
16
15
"strings"
17
16
18
17
"go.opencensus.io/plugin/ocgrpc"
@@ -138,9 +137,7 @@ func dial(ctx context.Context, insecure bool, o *internal.DialSettings) (*grpc.C
138
137
// * The endpoint is a host:port (or dns:///host:port).
139
138
// * Credentials are obtained via GCE metadata server, using the default
140
139
// service account.
141
- // * Opted in via GOOGLE_CLOUD_ENABLE_DIRECT_PATH environment variable.
142
- // For example, GOOGLE_CLOUD_ENABLE_DIRECT_PATH=spanner,pubsub
143
- if isDirectPathEnabled (endpoint ) && isTokenSourceDirectPathCompatible (creds .TokenSource ) {
140
+ if o .EnableDirectPath && checkDirectPathEndPoint (endpoint ) && isTokenSourceDirectPathCompatible (creds .TokenSource ) {
144
141
if ! strings .HasPrefix (endpoint , "dns:///" ) {
145
142
endpoint = "dns:///" + endpoint
146
143
}
@@ -189,7 +186,7 @@ func dial(ctx context.Context, insecure bool, o *internal.DialSettings) (*grpc.C
189
186
// point when isDirectPathEnabled will default to true, we guard it by
190
187
// the Directpath env var for now once we can introspect user defined
191
188
// dialer (https://github.com/grpc/grpc-go/issues/2795).
192
- if timeoutDialerOption != nil && isDirectPathEnabled (endpoint ) {
189
+ if timeoutDialerOption != nil && o . EnableDirectPath && checkDirectPathEndPoint (endpoint ) {
193
190
grpcOpts = append (grpcOpts , timeoutDialerOption )
194
191
}
195
192
@@ -250,8 +247,8 @@ func isTokenSourceDirectPathCompatible(ts oauth2.TokenSource) bool {
250
247
return true
251
248
}
252
249
253
- func isDirectPathEnabled (endpoint string ) bool {
254
- // Only host:port is supported, not other schemes (e.g., "tcp://" or "unix://").
250
+ func checkDirectPathEndPoint (endpoint string ) bool {
251
+ // Only [dns:///] host[ :port] is supported, not other schemes (e.g., "tcp://" or "unix://").
255
252
// Also don't try direct path if the user has chosen an alternate name resolver
256
253
// (i.e., via ":///" prefix).
257
254
//
@@ -261,15 +258,11 @@ func isDirectPathEnabled(endpoint string) bool {
261
258
return false
262
259
}
263
260
264
- // Only try direct path if the user has opted in via the environment variable.
265
- directPathAPIs := strings .Split (os .Getenv ("GOOGLE_CLOUD_ENABLE_DIRECT_PATH" ), "," )
266
- for _ , api := range directPathAPIs {
267
- // Ignore empty string since an empty env variable splits into [""]
268
- if api != "" && strings .Contains (endpoint , api ) {
269
- return true
270
- }
261
+ if endpoint == "" {
262
+ return false
271
263
}
272
- return false
264
+
265
+ return true
273
266
}
274
267
275
268
func processAndValidateOpts (opts []option.ClientOption ) (* internal.DialSettings , error ) {
0 commit comments