Skip to content

Commit

Permalink
Update cinder csi rpc log with count number
Browse files Browse the repository at this point in the history
  • Loading branch information
jichenjc committed Jul 9, 2021
1 parent 291d04b commit 2be0c5a
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions pkg/csi/cinder/utils.go
Expand Up @@ -3,6 +3,7 @@ package cinder
import (
"fmt"
"strings"
"sync/atomic"

"github.com/container-storage-interface/spec/lib/go/csi"
"github.com/kubernetes-csi/csi-lib-utils/protosanitizer"
Expand All @@ -14,6 +15,10 @@ import (
"k8s.io/klog/v2"
)

var (
serverGRPCEndpointCallCounter uint64
)

func NewControllerServiceCapability(cap csi.ControllerServiceCapability_RPC_Type) *csi.ControllerServiceCapability {
return &csi.ControllerServiceCapability{
Type: &csi.ControllerServiceCapability_Rpc{
Expand Down Expand Up @@ -78,13 +83,16 @@ func ParseEndpoint(ep string) (string, string, error) {
}

func logGRPC(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
klog.V(3).Infof("GRPC call: %s", info.FullMethod)
klog.V(5).Infof("GRPC request: %+v", protosanitizer.StripSecrets(req))
callID := atomic.AddUint64(&serverGRPCEndpointCallCounter, 1)

klog.V(3).Infof("[ID:%d] GRPC call: %s", callID, info.FullMethod)
klog.V(5).Infof("[ID:%d] GRPC request: %s", callID, protosanitizer.StripSecrets(req))
resp, err := handler(ctx, req)
if err != nil {
klog.Errorf("GRPC error: %v", err)
klog.Errorf("[ID:%d] GRPC error: %v", callID, err)
} else {
klog.V(5).Infof("GRPC response: %+v", protosanitizer.StripSecrets(resp))
klog.V(5).Infof("[ID:%d] GRPC response: %s", callID, protosanitizer.StripSecrets(resp))
}

return resp, err
}

0 comments on commit 2be0c5a

Please sign in to comment.