diff --git a/cmd/gce-pd-csi-driver/main.go b/cmd/gce-pd-csi-driver/main.go index a27d2b314..1b8ed5894 100644 --- a/cmd/gce-pd-csi-driver/main.go +++ b/cmd/gce-pd-csi-driver/main.go @@ -41,6 +41,7 @@ var ( runNodeService = flag.Bool("run-node-service", true, "If set to false then the CSI driver does not activate its node service (default: true)") 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.") metricsPath = flag.String("metrics-path", "/metrics", "The HTTP path where prometheus metrics will be exposed. Default is `/metrics`.") + grpcLogCharCap = flag.Int("grpc-log-char-cap", 10000, "The maximum amount of characters logged for every grpc responses") extraVolumeLabelsStr = flag.String("extra-labels", "", "Extra labels to attach to each PD created. It is a comma separated list of key value pairs like '=,='. See https://cloud.google.com/compute/docs/labeling-resources for details") @@ -160,5 +161,5 @@ func handle() { gce.WaitForOpBackoff.Steps = *waitForOpBackoffSteps gce.WaitForOpBackoff.Cap = *waitForOpBackoffCap - gceDriver.Run(*endpoint) + gceDriver.Run(*endpoint, *grpcLogCharCap) } diff --git a/pkg/gce-pd-csi-driver/gce-pd-driver.go b/pkg/gce-pd-csi-driver/gce-pd-driver.go index 473c7d424..af3129c6d 100644 --- a/pkg/gce-pd-csi-driver/gce-pd-driver.go +++ b/pkg/gce-pd-csi-driver/gce-pd-driver.go @@ -28,6 +28,8 @@ import ( mountmanager "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/mount-manager" ) +var maxLogChar int + type GCEDriver struct { name string vendorVersion string @@ -158,7 +160,9 @@ func NewControllerServer(gceDriver *GCEDriver, cloudProvider gce.GCECompute) *GC } } -func (gceDriver *GCEDriver) Run(endpoint string) { +func (gceDriver *GCEDriver) Run(endpoint string, grpcLogCharCap int) { + maxLogChar = grpcLogCharCap + klog.V(4).Infof("Driver: %v", gceDriver.name) //Start the nonblocking GRPC s := NewNonBlockingGRPCServer() diff --git a/pkg/gce-pd-csi-driver/utils.go b/pkg/gce-pd-csi-driver/utils.go index 4862613ab..a38ea2988 100644 --- a/pkg/gce-pd-csi-driver/utils.go +++ b/pkg/gce-pd-csi-driver/utils.go @@ -69,7 +69,11 @@ func logGRPC(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, h if err != nil { klog.Errorf("%s returned with error: %v", info.FullMethod, err) } else { - klog.V(4).Infof("%s returned with response: %s", info.FullMethod, resp) + cappedStr := fmt.Sprintf("%v", resp) + if len(cappedStr) > maxLogChar { + cappedStr = cappedStr[:maxLogChar] + fmt.Sprintf(" [response body too large, log capped to %d chars]", maxLogChar) + } + klog.V(4).Infof("%s returned with response: %s", info.FullMethod, cappedStr) } return resp, err } diff --git a/test/sanity/sanity_test.go b/test/sanity/sanity_test.go index d3ac9b36d..43c9a137b 100644 --- a/test/sanity/sanity_test.go +++ b/test/sanity/sanity_test.go @@ -90,7 +90,7 @@ func TestSanity(t *testing.T) { }() go func() { - gceDriver.Run(endpoint) + gceDriver.Run(endpoint, 10000) }() // TODO(#818): Fix failing tests and remove test skip flag.