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

fix(auth): add back DirectPath misconfiguration logging #11162

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions auth/grpctransport/directpath.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ package grpctransport

import (
"context"
"log"
"log/slog"
"net"
"os"
"strconv"
Expand Down Expand Up @@ -137,15 +137,15 @@ func logDirectPathMisconfig(endpoint string, creds *auth.Credentials, o *Options

// Case 1: does not enable DirectPath
if !isDirectPathEnabled(endpoint, o) {
log.Println("WARNING: DirectPath is disabled. To enable, please set the EnableDirectPath option along with the EnableDirectPathXds option.")
slog.Warn("DirectPath is disabled. To enable, please set the EnableDirectPath option along with the EnableDirectPathXds option.")
Copy link
Member

Choose a reason for hiding this comment

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

We now have a general logging pattern. Please access the logger via o.logger().

} else {
// Case 2: credential is not correctly set
if !isTokenProviderDirectPathCompatible(creds, o) {
log.Println("WARNING: DirectPath is disabled. Please make sure the token source is fetched from GCE metadata server and the default service account is used.")
slog.Warn("DirectPath is disabled. Please make sure the token source is fetched from GCE metadata server and the default service account is used.")
}
// Case 3: not running on GCE
if !compute.OnComputeEngine() {
log.Println("WARNING: DirectPath is disabled. DirectPath is only available in a GCE environment.")
slog.Warn("DirectPath is disabled. DirectPath is only available in a GCE environment.")
}
}
}
6 changes: 3 additions & 3 deletions auth/grpctransport/directpath_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func TestLogDirectPathMisconfigAttrempDirectPathNotSet(t *testing.T) {

logDirectPathMisconfig(endpoint, creds, opts)

wantedLog := "WARNING: DirectPath is disabled. To enable, please set the EnableDirectPath option along with the EnableDirectPathXds option."
wantedLog := "WARN DirectPath is disabled. To enable, please set the EnableDirectPath option along with the EnableDirectPathXds option."
if !strings.Contains(buf.String(), wantedLog) {
t.Fatalf("got: %v, want: %v", buf.String(), wantedLog)
}
Expand All @@ -135,7 +135,7 @@ func TestLogDirectPathMisconfigWrongCredential(t *testing.T) {

logDirectPathMisconfig(endpoint, creds, opts)

wantedLog := "WARNING: DirectPath is disabled. Please make sure the token source is fetched from GCE metadata server and the default service account is used."
wantedLog := "WARN DirectPath is disabled. Please make sure the token source is fetched from GCE metadata server and the default service account is used."
if !strings.Contains(buf.String(), wantedLog) {
t.Fatalf("got: %v, want: %v", buf.String(), wantedLog)
}
Expand All @@ -159,7 +159,7 @@ func TestLogDirectPathMisconfigNotOnGCE(t *testing.T) {
logDirectPathMisconfig(endpoint, creds, opts)

if !metadata.OnGCE() {
wantedLog := "WARNING: DirectPath is disabled. DirectPath is only available in a GCE environment."
wantedLog := "WARN DirectPath is disabled. DirectPath is only available in a GCE environment."
if !strings.Contains(buf.String(), wantedLog) {
t.Fatalf("got: %v, want: %v", buf.String(), wantedLog)
}
Expand Down