Creating a filter for your gRPC logs

Diego Garcia
Jul 30, 2017 · 2 min read

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).

Thanks to Fernando Freitas Alves

Diego Garcia

Written by

Software Engineer at @LuizaLabs

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade