Creating a filter for your gRPC logs

Diego Garcia
2 min readJul 30, 2017

I’m having a lot of fun working on Teresa project (Teresa is a simple PaaS on top of Kubernetes). Our main use case is Magazine Luiza where we deploy hundreds of applications to cloud with AWS as a cloud provider of our Kubernetes cluster.

Recently we chose to change from go-swagger to gRPC. Consequently, the project quality took a leap forward. But after that, an annoying behavior came across. When you expose a Load Balancer service in Kubernetes, it creates a load balancer on the cloud provider and by default, the AWS ELB performs a health check in its backend. But, gRPC uses HTTP2 instead of HTTP1 and doesn’t understand the ELB health check requests causing chaos on logs.

I was tired of using grep -v

I don’t wanna to change the configurations of ELB by hand because it’s not a multi-cloud action and while Kubernetes doesn’t provide a way to deal with it, I’ll fix this issue on the application layer.

Fortunately, creating a filter in logs of the standard library is very simple, you just have to re-write the method Write of io.Writer interface.

And to use it with gRPC, just set the logger of the server with this new writer: grpclog.SetLogger(logger.New(os.Stdout)). And that's it, no more tons of useless messages on your log.

Is there a better solution for this issue? Let me know If you know a better way to solve this issue without the AWS console (i.e. a generic solution for any cloud provider).

--

--