@@ -19,6 +19,7 @@ package connection
19
19
import (
20
20
"context"
21
21
"errors"
22
+ "fmt"
22
23
"io/ioutil"
23
24
"net"
24
25
"strings"
@@ -40,6 +41,15 @@ const (
40
41
41
42
const terminationLogPath = "/dev/termination-log"
42
43
44
+ var maxLogChar int = - 1
45
+
46
+ // SetMaxGRPCLogLength set the maximum character count for GRPC logging.
47
+ // If characterCount is set to anything smaller than or equal to 0 then there's no limit on log length.
48
+ // The default log length limit is unlimited.
49
+ func SetMaxGRPCLogLength (characterCount int ) {
50
+ maxLogChar = characterCount
51
+ }
52
+
43
53
// Connect opens insecure gRPC connection to a CSI driver. Address must be either absolute path to UNIX domain socket
44
54
// file or have format '<protocol>://', following gRPC name resolution mechanism at
45
55
// https://github.com/grpc/grpc/blob/master/doc/naming.md.
@@ -183,7 +193,11 @@ func LogGRPC(ctx context.Context, method string, req, reply interface{}, cc *grp
183
193
klog .V (5 ).Infof ("GRPC call: %s" , method )
184
194
klog .V (5 ).Infof ("GRPC request: %s" , protosanitizer .StripSecrets (req ))
185
195
err := invoker (ctx , method , req , reply , cc , opts ... )
186
- klog .V (5 ).Infof ("GRPC response: %s" , protosanitizer .StripSecrets (reply ))
196
+ cappedStr := fmt .Sprintf ("%s" , protosanitizer .StripSecrets (reply ))
197
+ if maxLogChar > 0 && len (cappedStr ) > maxLogChar {
198
+ cappedStr = cappedStr [:maxLogChar ] + fmt .Sprintf (" [response body too large, log capped to %d chars]" , maxLogChar )
199
+ }
200
+ klog .V (5 ).Infof ("GRPC response: %s" , cappedStr )
187
201
klog .V (5 ).Infof ("GRPC error: %v" , err )
188
202
return err
189
203
}
0 commit comments