-
Notifications
You must be signed in to change notification settings - Fork 152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clear the secrets from request for klog print in logGRPC()
#1462
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ import ( | |
"context" | ||
"errors" | ||
"fmt" | ||
"reflect" | ||
|
||
csi "github.com/container-storage-interface/spec/lib/go/csi" | ||
"google.golang.org/grpc" | ||
|
@@ -59,14 +60,30 @@ func NewNodeServiceCapability(cap csi.NodeServiceCapability_RPC_Type) *csi.NodeS | |
} | ||
} | ||
|
||
// Reflect magic below simply clears Secrets map from request. | ||
func clearSecrets(req interface{}) interface{} { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jsafrane how do you feel about putting this into csi-lib-utils as an alternative to protosanitizer so that it is not specific to a csi driver? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good to me, but with a huge warning that only field explicitly named |
||
v := reflect.ValueOf(&req).Elem() | ||
e := reflect.New(v.Elem().Type()).Elem() | ||
e.Set(v.Elem()) | ||
f := reflect.Indirect(e).FieldByName("Secrets") | ||
if f.IsValid() && f.CanSet() && f.Kind() == reflect.Map { | ||
f.Set(reflect.MakeMap(f.Type())) | ||
v.Set(e) | ||
} | ||
mpatlasov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return req | ||
} | ||
|
||
func logGRPC(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) { | ||
if info.FullMethod == ProbeCSIFullMethod { | ||
return handler(ctx, req) | ||
} | ||
// Note that secrets are not included in any RPC message. In the past protosanitizer and other log | ||
// Note that secrets may be included in some RPC messages | ||
// (https://github.com/kubernetes-sigs/gcp-compute-persistent-disk-csi-driver/issues/1372), | ||
// but the driver ignores them. In the past protosanitizer and other log | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you able to do a benchmark test to show that the reflect method does not signficantly increase CPU usage? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey @msau42 , I added a test to benchmark logGRPC. For 1M iterations, the reflect method increases execution time by only 1%:
|
||
// stripping was shown to cause a significant increase of CPU usage (see | ||
// https://github.com/kubernetes-sigs/gcp-compute-persistent-disk-csi-driver/issues/356#issuecomment-550529004). | ||
klog.V(4).Infof("%s called with request: %s", info.FullMethod, req) | ||
// That is why we use hand-crafted clearSecrets() below rather than protosanitizer. | ||
klog.V(4).Infof("%s called with request: %s", info.FullMethod, clearSecrets(req)) | ||
resp, err := handler(ctx, req) | ||
if err != nil { | ||
klog.Errorf("%s returned with error: %v", info.FullMethod, err.Error()) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to document all the assumptions about how secret fields are named in the csi spec.