Skip to content

Commit 3e97682

Browse files
committed
fix: reduce some method logs
remove comments reduce logs rename funcs
1 parent 43635b2 commit 3e97682

File tree

8 files changed

+49
-24
lines changed

8 files changed

+49
-24
lines changed

pkg/blob/controllerserver.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,6 @@ func (d *Driver) ValidateVolumeCapabilities(ctx context.Context, req *csi.Valida
310310

311311
// ControllerGetCapabilities returns the capabilities of the Controller plugin
312312
func (d *Driver) ControllerGetCapabilities(ctx context.Context, req *csi.ControllerGetCapabilitiesRequest) (*csi.ControllerGetCapabilitiesResponse, error) {
313-
klog.V(5).Infof("Using default ControllerGetCapabilities")
314-
315313
return &csi.ControllerGetCapabilitiesResponse{
316314
Capabilities: d.Cap,
317315
}, nil

pkg/csi-common/controllerserver-default.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ limitations under the License.
1717
package csicommon
1818

1919
import (
20-
"k8s.io/klog/v2"
21-
2220
"github.com/container-storage-interface/spec/lib/go/csi"
2321
"golang.org/x/net/context"
2422
"google.golang.org/grpc/codes"
@@ -46,8 +44,6 @@ func (cs *DefaultControllerServer) ControllerUnpublishVolume(ctx context.Context
4644
}
4745

4846
func (cs *DefaultControllerServer) ValidateVolumeCapabilities(ctx context.Context, req *csi.ValidateVolumeCapabilitiesRequest) (*csi.ValidateVolumeCapabilitiesResponse, error) {
49-
klog.V(5).Infof("Using default ValidateVolumeCapabilities")
50-
5147
for _, c := range req.GetVolumeCapabilities() {
5248
found := false
5349
for _, c1 := range cs.Driver.VC {
@@ -77,8 +73,6 @@ func (cs *DefaultControllerServer) GetCapacity(ctx context.Context, req *csi.Get
7773
// ControllerGetCapabilities implements the default GRPC callout.
7874
// Default supports all capabilities
7975
func (cs *DefaultControllerServer) ControllerGetCapabilities(ctx context.Context, req *csi.ControllerGetCapabilitiesRequest) (*csi.ControllerGetCapabilitiesResponse, error) {
80-
klog.V(5).Infof("Using default ControllerGetCapabilities")
81-
8276
return &csi.ControllerGetCapabilitiesResponse{
8377
Capabilities: cs.Driver.Cap,
8478
}, nil

pkg/csi-common/driver_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ func TestAddControllerServiceCapabilities(t *testing.T) {
7171
}
7272

7373
func TestGetVolumeCapabilityAccessModes(t *testing.T) {
74-
7574
d := NewFakeDriver()
7675

7776
// Test no volume access modes.

pkg/csi-common/identityserver-default.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,13 @@ import (
2121
"golang.org/x/net/context"
2222
"google.golang.org/grpc/codes"
2323
"google.golang.org/grpc/status"
24-
"k8s.io/klog/v2"
2524
)
2625

2726
type DefaultIdentityServer struct {
2827
Driver *CSIDriver
2928
}
3029

3130
func (ids *DefaultIdentityServer) GetPluginInfo(ctx context.Context, req *csi.GetPluginInfoRequest) (*csi.GetPluginInfoResponse, error) {
32-
klog.V(5).Infof("Using default GetPluginInfo")
33-
3431
if ids.Driver.Name == "" {
3532
return nil, status.Error(codes.Unavailable, "Driver name not configured")
3633
}
@@ -50,7 +47,6 @@ func (ids *DefaultIdentityServer) Probe(ctx context.Context, req *csi.ProbeReque
5047
}
5148

5249
func (ids *DefaultIdentityServer) GetPluginCapabilities(ctx context.Context, req *csi.GetPluginCapabilitiesRequest) (*csi.GetPluginCapabilitiesResponse, error) {
53-
klog.V(5).Infof("Using default capabilities")
5450
return &csi.GetPluginCapabilitiesResponse{
5551
Capabilities: []*csi.PluginCapability{
5652
{

pkg/csi-common/nodeserver-default.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,19 @@ package csicommon
1919
import (
2020
"github.com/container-storage-interface/spec/lib/go/csi"
2121
"golang.org/x/net/context"
22-
"k8s.io/klog/v2"
2322
)
2423

2524
type DefaultNodeServer struct {
2625
Driver *CSIDriver
2726
}
2827

2928
func (ns *DefaultNodeServer) NodeGetInfo(ctx context.Context, req *csi.NodeGetInfoRequest) (*csi.NodeGetInfoResponse, error) {
30-
klog.V(5).Infof("Using default NodeGetInfo")
31-
3229
return &csi.NodeGetInfoResponse{
3330
NodeId: ns.Driver.NodeID,
3431
}, nil
3532
}
3633

3734
func (ns *DefaultNodeServer) NodeGetCapabilities(ctx context.Context, req *csi.NodeGetCapabilitiesRequest) (*csi.NodeGetCapabilitiesResponse, error) {
38-
klog.V(2).Infof("Using default NodeGetCapabilities")
39-
4035
return &csi.NodeGetCapabilitiesResponse{
4136
Capabilities: ns.Driver.NSCap,
4237
}, nil

pkg/csi-common/server.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ func (s *nonBlockingGRPCServer) ForceStop() {
6868
}
6969

7070
func (s *nonBlockingGRPCServer) serve(endpoint string, ids csi.IdentityServer, cs csi.ControllerServer, ns csi.NodeServer, testMode bool) {
71-
7271
proto, addr, err := ParseEndpoint(endpoint)
7372
if err != nil {
7473
klog.Fatal(err.Error())

pkg/csi-common/utils.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ func NewNodeServiceCapability(cap csi.NodeServiceCapability_RPC_Type) *csi.NodeS
8181

8282
func RunNodePublishServer(endpoint string, d *CSIDriver, ns csi.NodeServer, testMode bool) {
8383
ids := NewDefaultIdentityServer(d)
84-
8584
s := NewNonBlockingGRPCServer()
8685
s.Start(endpoint, ids, nil, ns, testMode)
8786
s.Wait()
@@ -97,20 +96,30 @@ func RunControllerPublishServer(endpoint string, d *CSIDriver, cs csi.Controller
9796

9897
func RunControllerandNodePublishServer(endpoint string, d *CSIDriver, cs csi.ControllerServer, ns csi.NodeServer, testMode bool) {
9998
ids := NewDefaultIdentityServer(d)
100-
10199
s := NewNonBlockingGRPCServer()
102100
s.Start(endpoint, ids, cs, ns, testMode)
103101
s.Wait()
104102
}
105103

104+
func getLogLevel(method string) int32 {
105+
if method == "/csi.v1.Identity/Probe" ||
106+
method == "/csi.v1.Node/NodeGetCapabilities" ||
107+
method == "/csi.v1.Node/NodeGetVolumeStats" {
108+
return 10
109+
}
110+
return 2
111+
}
112+
106113
func logGRPC(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
107-
klog.V(3).Infof("GRPC call: %s", info.FullMethod)
108-
klog.V(5).Infof("GRPC request: %s", protosanitizer.StripSecrets(req))
114+
level := klog.Level(getLogLevel(info.FullMethod))
115+
klog.V(level).Infof("GRPC call: %s", info.FullMethod)
116+
klog.V(level).Infof("GRPC request: %s", protosanitizer.StripSecrets(req))
117+
109118
resp, err := handler(ctx, req)
110119
if err != nil {
111120
klog.Errorf("GRPC error: %v", err)
112121
} else {
113-
klog.V(5).Infof("GRPC response: %s", protosanitizer.StripSecrets(resp))
122+
klog.V(level).Infof("GRPC response: %s", protosanitizer.StripSecrets(resp))
114123
}
115124
return resp, err
116125
}

pkg/csi-common/utils_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,38 @@ func TestNewNodeServiceCapability(t *testing.T) {
197197
assert.Equal(t, resp.XXX_sizecache, int32(0))
198198
}
199199
}
200+
201+
func TestGetLogLevel(t *testing.T) {
202+
tests := []struct {
203+
method string
204+
level int32
205+
}{
206+
{
207+
method: "/csi.v1.Identity/Probe",
208+
level: 10,
209+
},
210+
{
211+
method: "/csi.v1.Node/NodeGetCapabilities",
212+
level: 10,
213+
},
214+
{
215+
method: "/csi.v1.Node/NodeGetVolumeStats",
216+
level: 10,
217+
},
218+
{
219+
method: "",
220+
level: 2,
221+
},
222+
{
223+
method: "unknown",
224+
level: 2,
225+
},
226+
}
227+
228+
for _, test := range tests {
229+
level := getLogLevel(test.method)
230+
if level != test.level {
231+
t.Errorf("returned level: (%v), expected level: (%v)", level, test.level)
232+
}
233+
}
234+
}

0 commit comments

Comments
 (0)