Skip to content
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

feat(transport): Log DirectPath misconfiguration #2225

Merged
merged 9 commits into from
Nov 6, 2023
22 changes: 22 additions & 0 deletions transport/grpc/dial.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ func dial(ctx context.Context, insecure bool, o *internal.DialSettings) (*grpc.C
}
// TODO(cbro): add support for system parameters (quota project, request reason) via chained interceptor.
}
logDirectPathMisconfig(creds.TokenSource, o)
}

// Add tracing, but before the other options, so that clients can override the
Expand Down Expand Up @@ -296,6 +297,27 @@ func checkDirectPathEndPoint(endpoint string) bool {
return true
}

func logDirectPathMisconfig(ts oauth2.TokenSource, o *internal.DialSettings) {
isDirectPathOptionSet := o.EnableDirectPath
isDirectPathXdsEnvSet := strings.EqualFold(os.Getenv(enableDirectPathXds), "true")
isDirectPathXdsOptionSet := o.EnableDirectPathXds
if isDirectPathXdsEnvSet || isDirectPathXdsOptionSet {
// Case 1: does not enable DirectPath
if !isDirectPathOptionSet {
log.Print("WARNING: DirectPath is misconfigured. Please set the attemptDirectPath option along with the attemptDirectPathXds option.")
quartzmo marked this conversation as resolved.
Show resolved Hide resolved
quartzmo marked this conversation as resolved.
Show resolved Hide resolved
} else {
// Case 2: credential is not correctly set
if !isTokenSourceDirectPathCompatible(ts, o) {
log.Print("WARNING: DirectPath is misconfigured. Please make sure the token source is fetched from GCE metadata server and the default service account is used")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does a user do this correctly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GCS client should set the AllowNonDefaultServiceAccount option to true, https://github.com/googleapis/google-api-go-client/blob/main/transport/grpc/dial.go#L269, and customers do not need to worry about this.

}
// Case 3: not running on GCE
if !metadata.OnGCE() {
log.Print("WARNING: DirectPath is misconfigured. DirectPath is only available in a GCE environment.")
}
}
}
}

func processAndValidateOpts(opts []option.ClientOption) (*internal.DialSettings, error) {
var o internal.DialSettings
for _, opt := range opts {
Expand Down