Capturing Metrics with Go’s Reverse Proxy

Sidney Wijngaarde
ITNEXT
Published in
4 min readOct 7, 2019

--

I had to capture metrics from a service I couldn’t directly access. The go standard library ships with a reverse proxy implementation 🤯. By proxying client requests to the service I was able to capture metrics without modifying the service itself.

What is a Reverse Proxy?

“In computer networks , a reverse proxy is a type of proxy server that retrieves resources on behalf of a client from one or more servers. These resources are then returned to the client, appearing as if they originated from the proxy server itself. “

From Wikipedia

Essentially, a reverse proxy forwards traffic from a client to a set of servers behind the proxy. There are many applications for reverse proxies. Load balancing, TLS termination, and A/B testing are just a few. Reverse proxies are also useful for inserting instrumentation around an HTTP service without having to modify the service itself.

reverse proxy network diagram

If you’d like to learn more about proxying I recommend checking out Introduction to modern network load balancing and proxying by Matt Klein. Matt is the creator of Envoy Proxy, a robust proxy server that powers service mesh tools like Istio. His post does a great job of outlining the approaches used by modern load balancers and proxies.

Simple Go Reverse Proxy

Go is one of my favorite programming languages for many reasons. The designers of the language focused on Simplicity, practicality, and performance. These considerations make Go a joy to use. The language shines with networking tasks. Part of the reason for this is the incredibly comprehensive standard library, which among other common implementations includes a reverse proxy.

Rolling your own proxy in go is as simple as

--

--