fix: reduce driver logs

This commit is contained in:
andyzhangx 2021-01-20 06:53:19 +00:00
parent 3e9ef1e80d
commit e7cdcedcc4
6 changed files with 54 additions and 10 deletions

View File

@ -10,7 +10,7 @@ jobs:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.13
go-version: ^1.15
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v2

View File

@ -13,7 +13,7 @@ jobs:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.13
go-version: ^1.15
id: go
- name: Check out code into the Go module directory

View File

@ -24,6 +24,9 @@ kubectl apply -f ./deploy/example/statefulset.yaml
echo "sleep 60s ..."
sleep 60
echo "begin to check pod status ..."
kubectl get pods -o wide
kubectl get pods --field-selector status.phase=Running | grep deployment-nfs
kubectl get pods --field-selector status.phase=Running | grep statefulset-nfs-0

View File

@ -22,8 +22,6 @@ import (
"golang.org/x/net/context"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"k8s.io/klog/v2"
)
type IdentityServer struct {
@ -31,8 +29,6 @@ type IdentityServer struct {
}
func (ids *IdentityServer) GetPluginInfo(ctx context.Context, req *csi.GetPluginInfoRequest) (*csi.GetPluginInfoResponse, error) {
klog.V(5).Infof("Using default GetPluginInfo")
if ids.Driver.name == "" {
return nil, status.Error(codes.Unavailable, "Driver name not configured")
}
@ -56,7 +52,6 @@ func (ids *IdentityServer) Probe(ctx context.Context, req *csi.ProbeRequest) (*c
}
func (ids *IdentityServer) GetPluginCapabilities(ctx context.Context, req *csi.GetPluginCapabilitiesRequest) (*csi.GetPluginCapabilitiesResponse, error) {
klog.V(5).Infof("Using default capabilities")
return &csi.GetPluginCapabilitiesResponse{
Capabilities: []*csi.PluginCapability{
{

View File

@ -70,14 +70,25 @@ func ParseEndpoint(ep string) (string, string, error) {
return "", "", fmt.Errorf("Invalid endpoint: %v", ep)
}
func getLogLevel(method string) int32 {
if method == "/csi.v1.Identity/Probe" ||
method == "/csi.v1.Node/NodeGetCapabilities" ||
method == "/csi.v1.Node/NodeGetVolumeStats" {
return 10
}
return 2
}
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: %s", protosanitizer.StripSecrets(req))
level := klog.Level(getLogLevel(info.FullMethod))
klog.V(level).Infof("GRPC call: %s", info.FullMethod)
klog.V(level).Infof("GRPC request: %s", protosanitizer.StripSecrets(req))
resp, err := handler(ctx, req)
if err != nil {
klog.Errorf("GRPC error: %v", err)
} else {
klog.V(5).Infof("GRPC response: %s", protosanitizer.StripSecrets(resp))
klog.V(level).Infof("GRPC response: %s", protosanitizer.StripSecrets(resp))
}
return resp, err
}

View File

@ -83,3 +83,38 @@ func TestParseEndpoint(t *testing.T) {
})
}
}
func TestGetLogLevel(t *testing.T) {
tests := []struct {
method string
level int32
}{
{
method: "/csi.v1.Identity/Probe",
level: 10,
},
{
method: "/csi.v1.Node/NodeGetCapabilities",
level: 10,
},
{
method: "/csi.v1.Node/NodeGetVolumeStats",
level: 10,
},
{
method: "",
level: 2,
},
{
method: "unknown",
level: 2,
},
}
for _, test := range tests {
level := getLogLevel(test.method)
if level != test.level {
t.Errorf("returned level: (%v), expected level: (%v)", level, test.level)
}
}
}