Skip to content
Permalink
Browse files

fix(transport/grpc): check Compute Engine environment for DirectPath (#…

…781)

Add Compute Engine environment check since DirectPath can only be used on Compute Engine.
  • Loading branch information
mohanli-ml committed Dec 9, 2020
1 parent 9ec61b3 commit 89287b68a240f818e9ae70a6395b1d72e21ee236
Showing with 3 additions and 2 deletions.
  1. +3 −2 transport/grpc/dial.go
@@ -14,6 +14,7 @@ import (
"log"
"strings"

"cloud.google.com/go/compute/metadata"
"go.opencensus.io/plugin/ocgrpc"
"golang.org/x/oauth2"
"google.golang.org/api/internal"
@@ -137,7 +138,7 @@ func dial(ctx context.Context, insecure bool, o *internal.DialSettings) (*grpc.C
// * The endpoint is a host:port (or dns:///host:port).
// * Credentials are obtained via GCE metadata server, using the default
// service account.
if o.EnableDirectPath && checkDirectPathEndPoint(endpoint) && isTokenSourceDirectPathCompatible(creds.TokenSource) {
if o.EnableDirectPath && checkDirectPathEndPoint(endpoint) && isTokenSourceDirectPathCompatible(creds.TokenSource) && metadata.OnGCE() {
if !strings.HasPrefix(endpoint, "dns:///") {
endpoint = "dns:///" + endpoint
}
@@ -186,7 +187,7 @@ func dial(ctx context.Context, insecure bool, o *internal.DialSettings) (*grpc.C
// point when isDirectPathEnabled will default to true, we guard it by
// the Directpath env var for now once we can introspect user defined
// dialer (https://github.com/grpc/grpc-go/issues/2795).
if timeoutDialerOption != nil && o.EnableDirectPath && checkDirectPathEndPoint(endpoint) {
if timeoutDialerOption != nil && o.EnableDirectPath && checkDirectPathEndPoint(endpoint) && metadata.OnGCE() {
grpcOpts = append(grpcOpts, timeoutDialerOption)
}

0 comments on commit 89287b6

Please sign in to comment.