Skip to content

Commit f7af69f

Browse files
committed
limit grpc loging info to a configurable char limit
1 parent 10ed92e commit f7af69f

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

4546
extraVolumeLabelsStr = flag.String("extra-labels", "", "Extra labels to attach to each PD created. It is a comma separated list of key value pairs like '<key1>=<value1>,<key2>=<value2>'. See https://cloud.google.com/compute/docs/labeling-resources for details")
4647

@@ -160,5 +161,5 @@ func handle() {
160161
gce.WaitForOpBackoff.Steps = *waitForOpBackoffSteps
161162
gce.WaitForOpBackoff.Cap = *waitForOpBackoffCap
162163

163-
gceDriver.Run(*endpoint)
164+
gceDriver.Run(*endpoint, *grpcLogCharCap)
164165
}

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

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

31+
var maxLogChar int
32+
3133
type GCEDriver struct {
3234
name string
3335
vendorVersion string
@@ -158,7 +160,9 @@ func NewControllerServer(gceDriver *GCEDriver, cloudProvider gce.GCECompute) *GC
158160
}
159161
}
160162

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

9292
go func() {
93-
gceDriver.Run(endpoint)
93+
gceDriver.Run(endpoint, 10000)
9494
}()
9595

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

0 commit comments

Comments
 (0)