Skip to content

Commit 8bc9bd1

Browse files
authored
Merge pull request #1220 from percona/PBM-1608-gcs-debug-log-levels
PBM-1608: Add config option to enable debug for GCS storage
2 parents a749501 + a396766 commit 8bc9bd1

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

packaging/conf/pbm-conf-reference.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@
160160
## The maximum object size that will be stored on the storage
161161
# maxObjSizeGB: 5018
162162

163+
## Enable debug trace of HTTP communication
164+
# debugTrace: true
165+
166+
163167
#--------------------Filesystem Configuration---------------------------
164168
# type:
165169
# filesystem:

pbm/storage/gcs/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type Config struct {
1717
// https://pkg.go.dev/cloud.google.com/go/storage#Writer
1818
ChunkSize int `bson:"chunkSize,omitempty" json:"chunkSize,omitempty" yaml:"chunkSize,omitempty"`
1919
MaxObjSizeGB *float64 `bson:"maxObjSizeGB,omitempty" json:"maxObjSizeGB,omitempty" yaml:"maxObjSizeGB,omitempty"`
20+
DebugTrace bool `bson:"debugTrace,omitempty" json:"debugTrace,omitempty" yaml:"debugTrace,omitempty"`
2021

2122
Retryer *Retryer `bson:"retryer,omitempty" json:"retryer,omitempty" yaml:"retryer,omitempty"`
2223
}

pbm/storage/gcs/google_client.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"fmt"
77
"io"
8+
"log/slog"
89
"path"
910
"strings"
1011
"time"
@@ -49,7 +50,21 @@ func newGoogleClient(cfg *Config, l log.LogEvent) (*googleClient, error) {
4950
return nil, errors.Wrap(err, "marshal GCS credentials")
5051
}
5152

52-
cli, err := storagegcs.NewClient(ctx, option.WithCredentialsJSON(creds))
53+
clOpts := []option.ClientOption{
54+
option.WithCredentialsJSON(creds),
55+
}
56+
if cfg.DebugTrace {
57+
h := slog.NewTextHandler(l.GetLogger(), &slog.HandlerOptions{
58+
Level: slog.LevelDebug,
59+
})
60+
gcsLogger := slog.New(h)
61+
clOpts = append(clOpts, option.WithLogger(gcsLogger))
62+
}
63+
64+
cli, err := storagegcs.NewClient(
65+
ctx,
66+
clOpts...,
67+
)
5368
if err != nil {
5469
return nil, errors.Wrap(err, "new GCS client")
5570
}

0 commit comments

Comments
 (0)