Merge pull request #138 from andyzhangx/reduce-logs

fix: reduce driver logs
This commit is contained in:
Andy Zhang 2021-01-21 11:57:35 +08:00 committed by GitHub
commit 7a1256a835
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 62 additions and 18 deletions

View File

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

View File

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

View File

@ -28,7 +28,7 @@ spec:
- name: csi-provisioner - name: csi-provisioner
image: "{{ .Values.image.csiProvisioner.repository }}:{{ .Values.image.csiProvisioner.tag }}" image: "{{ .Values.image.csiProvisioner.repository }}:{{ .Values.image.csiProvisioner.tag }}"
args: args:
- "-v=5" - "-v=2"
- "--csi-address=$(ADDRESS)" - "--csi-address=$(ADDRESS)"
- "--leader-election" - "--leader-election"
env: env:
@ -51,7 +51,7 @@ spec:
- --csi-address=/csi/csi.sock - --csi-address=/csi/csi.sock
- --probe-timeout=3s - --probe-timeout=3s
- --health-port=29652 - --health-port=29652
- --v=5 - --v=2
imagePullPolicy: {{ .Values.image.livenessProbe.pullPolicy }} imagePullPolicy: {{ .Values.image.livenessProbe.pullPolicy }}
volumeMounts: volumeMounts:
- name: socket-dir - name: socket-dir

View File

@ -26,7 +26,7 @@ spec:
- --csi-address=/csi/csi.sock - --csi-address=/csi/csi.sock
- --probe-timeout=3s - --probe-timeout=3s
- --health-port=29653 - --health-port=29653
- --v=5 - --v=2
imagePullPolicy: {{ .Values.image.livenessProbe.pullPolicy }} imagePullPolicy: {{ .Values.image.livenessProbe.pullPolicy }}
volumeMounts: volumeMounts:
- name: socket-dir - name: socket-dir
@ -45,7 +45,7 @@ spec:
exec: exec:
command: ["/bin/sh", "-c", "rm -rf /registration/csi-nfsplugin /registration/csi-nfsplugin-reg.sock"] command: ["/bin/sh", "-c", "rm -rf /registration/csi-nfsplugin /registration/csi-nfsplugin-reg.sock"]
args: args:
- --v=5 - --v=2
- --csi-address=/csi/csi.sock - --csi-address=/csi/csi.sock
- --kubelet-registration-path=/var/lib/kubelet/plugins/csi-nfsplugin/csi.sock - --kubelet-registration-path=/var/lib/kubelet/plugins/csi-nfsplugin/csi.sock
env: env:

View File

@ -27,7 +27,7 @@ spec:
- name: csi-provisioner - name: csi-provisioner
image: k8s.gcr.io/sig-storage/csi-provisioner:v2.0.4 image: k8s.gcr.io/sig-storage/csi-provisioner:v2.0.4
args: args:
- "-v=5" - "-v=2"
- "--csi-address=$(ADDRESS)" - "--csi-address=$(ADDRESS)"
- "--leader-election" - "--leader-election"
env: env:
@ -49,7 +49,7 @@ spec:
- --csi-address=/csi/csi.sock - --csi-address=/csi/csi.sock
- --probe-timeout=3s - --probe-timeout=3s
- --health-port=29652 - --health-port=29652
- --v=5 - --v=2
volumeMounts: volumeMounts:
- name: socket-dir - name: socket-dir
mountPath: /csi mountPath: /csi

View File

@ -26,7 +26,7 @@ spec:
- --csi-address=/csi/csi.sock - --csi-address=/csi/csi.sock
- --probe-timeout=3s - --probe-timeout=3s
- --health-port=29653 - --health-port=29653
- --v=5 - --v=2
volumeMounts: volumeMounts:
- name: socket-dir - name: socket-dir
mountPath: /csi mountPath: /csi
@ -44,7 +44,7 @@ spec:
exec: exec:
command: ["/bin/sh", "-c", "rm -rf /registration/csi-nfsplugin /registration/csi-nfsplugin-reg.sock"] command: ["/bin/sh", "-c", "rm -rf /registration/csi-nfsplugin /registration/csi-nfsplugin-reg.sock"]
args: args:
- --v=5 - --v=2
- --csi-address=/csi/csi.sock - --csi-address=/csi/csi.sock
- --kubelet-registration-path=/var/lib/kubelet/plugins/csi-nfsplugin/csi.sock - --kubelet-registration-path=/var/lib/kubelet/plugins/csi-nfsplugin/csi.sock
env: env:

View File

@ -24,6 +24,9 @@ kubectl apply -f ./deploy/example/statefulset.yaml
echo "sleep 60s ..." echo "sleep 60s ..."
sleep 60 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 deployment-nfs
kubectl get pods --field-selector status.phase=Running | grep statefulset-nfs-0 kubectl get pods --field-selector status.phase=Running | grep statefulset-nfs-0

View File

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

View File

@ -70,14 +70,25 @@ func ParseEndpoint(ep string) (string, string, error) {
return "", "", fmt.Errorf("Invalid endpoint: %v", ep) 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) { func logGRPC(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
klog.V(3).Infof("GRPC call: %s", info.FullMethod) level := klog.Level(getLogLevel(info.FullMethod))
klog.V(5).Infof("GRPC request: %s", protosanitizer.StripSecrets(req)) klog.V(level).Infof("GRPC call: %s", info.FullMethod)
klog.V(level).Infof("GRPC request: %s", protosanitizer.StripSecrets(req))
resp, err := handler(ctx, req) resp, err := handler(ctx, req)
if err != nil { if err != nil {
klog.Errorf("GRPC error: %v", err) klog.Errorf("GRPC error: %v", err)
} else { } else {
klog.V(5).Infof("GRPC response: %s", protosanitizer.StripSecrets(resp)) klog.V(level).Infof("GRPC response: %s", protosanitizer.StripSecrets(resp))
} }
return resp, err 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)
}
}
}