Skip to content
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

feat(zfspv): filter grpc logs to reduce the pollution #161

Merged
merged 5 commits into from
Jun 24, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelogs/unreleased/161-vaniisgh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
adds a filter for grpc logs to reduce pollution in zfs-node caused by filtering NodeGetVolumeStats & NodeGetCapabilities calls
Copy link
Contributor

@pawanpraka1 pawanpraka1 Jun 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let us just keep it : adds a filter for grpc logs to reduce the pollution

Copy link
Contributor Author

@vaniisgh vaniisgh Jun 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it, this seemed to verbose anyway :), I'm sorry I missed adding the newline again though, realized too late.

49 changes: 38 additions & 11 deletions pkg/driver/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package driver

import (
"bytes"
"fmt"
"net"
"os"
Expand All @@ -26,8 +27,8 @@ import (
"golang.org/x/net/context"
"google.golang.org/grpc"

"github.com/Sirupsen/logrus"
"github.com/kubernetes-csi/csi-lib-utils/protosanitizer"
"k8s.io/klog"

"github.com/container-storage-interface/spec/lib/go/csi"
)
Expand All @@ -43,16 +44,42 @@ func parseEndpoint(ep string) (string, string, error) {
return "", "", fmt.Errorf("Invalid endpoint: %v", ep)
}

//filters if the logd are informative or pollutant
func isInfotrmativeLog(info string) bool {

// add the messages that pollute logs to the array
var msgsToFilter = [][]byte{
[]byte("NodeGetVolumeStats"),
[]byte("NodeGetCapabilities"),
}

// checks for message in request
for _, msg := range msgsToFilter {
if bytes.Contains([]byte(info), msg) {
return false
}
}

return true
}

// logGRPC logs all the grpc related errors, i.e the final errors
// which are returned to the grpc clients
func logGRPC(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
logrus.Infof("GRPC call: %s", info.FullMethod)
logrus.Infof("GRPC request: %s", protosanitizer.StripSecrets(req))

log := isInfotrmativeLog(info.FullMethod)
if log == true {
klog.Infof("GRPC call: %s\n requests %s", info.FullMethod, protosanitizer.StripSecrets(req))
}

resp, err := handler(ctx, req)
if err != nil {
logrus.Errorf("GRPC error: %v", err)
} else {
logrus.Infof("GRPC response: %s", protosanitizer.StripSecrets(resp))

if log == true {
if err != nil {
klog.Errorf("GRPC error: %v", err)
} else {
klog.Infof("GRPC response: %s", protosanitizer.StripSecrets(resp))
}
}
return resp, err
}
Expand Down Expand Up @@ -125,7 +152,7 @@ func (s *nonBlockingGRPCServer) serve(endpoint string, ids csi.IdentityServer, c

proto, addr, err := parseEndpoint(endpoint)
if err != nil {
logrus.Fatal(err.Error())
klog.Fatal(err.Error())
}

// Clear off the addr if it is already present, this is done to remove stale
Expand All @@ -135,13 +162,13 @@ func (s *nonBlockingGRPCServer) serve(endpoint string, ids csi.IdentityServer, c
if proto == "unix" {
addr = "/" + addr
if err := os.Remove(addr); err != nil && !os.IsNotExist(err) {
logrus.Fatalf("Failed to remove %s, error: %s", addr, err.Error())
klog.Fatalf("Failed to remove %s, error: %s", addr, err.Error())
}
}

listener, err := net.Listen(proto, addr)
if err != nil {
logrus.Fatalf("Failed to listen: %v", err)
klog.Fatalf("Failed to listen: %v", err)
}

opts := []grpc.ServerOption{
Expand All @@ -162,7 +189,7 @@ func (s *nonBlockingGRPCServer) serve(endpoint string, ids csi.IdentityServer, c
csi.RegisterNodeServer(server, ns)
}

logrus.Infof("Listening for connections on address: %#v", listener.Addr())
klog.Infof("Listening for connections on address: %#v", listener.Addr())

// Start serving requests on the grpc server created
server.Serve(listener)
Expand Down