Skip to content

Commit 0543b62

Browse files
committed
limit grpc loging info to a configurable char limit
1 parent 4880a57 commit 0543b62

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
@@ -40,6 +40,7 @@ var (
4040
runNodeService = flag.Bool("run-node-service", true, "If set to false then the CSI driver does not activate its node service (default: true)")
4141
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.")
4242
metricsPath = flag.String("metrics-path", "/metrics", "The HTTP path where prometheus metrics will be exposed. Default is `/metrics`.")
43+
grpcLogCharCap = flag.Int("grpc-log-char-cap", 10000, "The maximum amount of characters logged for every grpc responses")
4344

4445
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.")
4546
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).")
@@ -163,5 +164,5 @@ func handle() {
163164
gce.WaitForOpBackoff.Steps = *waitForOpBackoffSteps
164165
gce.WaitForOpBackoff.Cap = *waitForOpBackoffCap
165166

166-
gceDriver.Run(*endpoint)
167+
gceDriver.Run(*endpoint, *grpcLogCharCap)
167168
}

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

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

32+
var maxLogChar int
33+
3234
type GCEDriver struct {
3335
name string
3436
vendorVersion string
@@ -159,7 +161,9 @@ func NewControllerServer(gceDriver *GCEDriver, cloudProvider gce.GCECompute, err
159161
}
160162
}
161163

162-
func (gceDriver *GCEDriver) Run(endpoint string) {
164+
func (gceDriver *GCEDriver) Run(endpoint string, grpcLogCharCap int) {
165+
maxLogChar = grpcLogCharCap
166+
163167
klog.V(4).Infof("Driver: %v", gceDriver.name)
164168
//Start the nonblocking GRPC
165169
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: %v", 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
@@ -91,7 +91,7 @@ func TestSanity(t *testing.T) {
9191
}()
9292

9393
go func() {
94-
gceDriver.Run(endpoint)
94+
gceDriver.Run(endpoint, 10000)
9595
}()
9696

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

0 commit comments

Comments
 (0)