Skip to content

Commit 41af246

Browse files
authored
Merge pull request #1085 from leiyiz/logLimit
limit grpc logging info to a configurable character limit
2 parents 0bbb000 + f7af69f commit 41af246

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

cmd/gce-pd-csi-driver/main.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ var (
4242
runNodeService = flag.Bool("run-node-service", true, "If set to false then the CSI driver does not activate its node service (default: true)")
4343
httpEndpoint = flag.String("http-endpoint", "", "The TCP network address where the prometheus metrics endpoint will listen (example: `:8080`). The default is empty string, which means metrics endpoint is disabled.")
4444
metricsPath = flag.String("metrics-path", "/metrics", "The HTTP path where prometheus metrics will be exposed. Default is `/metrics`.")
45+
grpcLogCharCap = flag.Int("grpc-log-char-cap", 10000, "The maximum amount of characters logged for every grpc responses")
4546

4647
errorBackoffInitialDurationMs = flag.Int("backoff-initial-duration-ms", 200, "The amount of ms for the initial duration of the backoff condition for controller publish/unpublish CSI operations. Default is 200.")
4748
errorBackoffMaxDurationMs = flag.Int("backoff-max-duration-ms", 300000, "The amount of ms for the max duration of the backoff condition for controller publish/unpublish CSI operations. Default is 300000 (5m).")
@@ -165,5 +166,5 @@ func handle() {
165166
gce.WaitForOpBackoff.Steps = *waitForOpBackoffSteps
166167
gce.WaitForOpBackoff.Cap = *waitForOpBackoffCap
167168

168-
gceDriver.Run(*endpoint)
169+
gceDriver.Run(*endpoint, *grpcLogCharCap)
169170
}

pkg/gce-pd-csi-driver/gce-pd-driver.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import (
3030
mountmanager "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/mount-manager"
3131
)
3232

33+
var maxLogChar int
34+
3335
type GCEDriver struct {
3436
name string
3537
vendorVersion string
@@ -160,7 +162,9 @@ func NewControllerServer(gceDriver *GCEDriver, cloudProvider gce.GCECompute, err
160162
}
161163
}
162164

163-
func (gceDriver *GCEDriver) Run(endpoint string) {
165+
func (gceDriver *GCEDriver) Run(endpoint string, grpcLogCharCap int) {
166+
maxLogChar = grpcLogCharCap
167+
164168
klog.V(4).Infof("Driver: %v", gceDriver.name)
165169
//Start the nonblocking GRPC
166170
s := NewNonBlockingGRPCServer()

pkg/gce-pd-csi-driver/utils.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,11 @@ func logGRPC(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, h
6969
if err != nil {
7070
klog.Errorf("%s returned with error: %w", info.FullMethod, err)
7171
} else {
72-
klog.V(4).Infof("%s returned with response: %s", info.FullMethod, resp)
72+
cappedStr := fmt.Sprintf("%v", resp)
73+
if len(cappedStr) > maxLogChar {
74+
cappedStr = cappedStr[:maxLogChar] + fmt.Sprintf(" [response body too large, log capped to %d chars]", maxLogChar)
75+
}
76+
klog.V(4).Infof("%s returned with response: %s", info.FullMethod, cappedStr)
7377
}
7478
return resp, err
7579
}

test/sanity/sanity_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func TestSanity(t *testing.T) {
9292
}()
9393

9494
go func() {
95-
gceDriver.Run(endpoint)
95+
gceDriver.Run(endpoint, 10000)
9696
}()
9797

9898
// TODO(#818): Fix failing tests and remove test skip flag.

0 commit comments

Comments
 (0)