Git Product home page Git Product logo

go-rev-proxy's Introduction

go-rev-proxy

This simple project was meant to be an opportunity to play with a handful of enterprise technologies. It is a reverse proxy written in Go with support for Redis caching, Prometheus metrics and distributed tracing.

Running the Application

After cloning the repo run docker-compose build && docker-compose up to build and start the application with all its supporting services. Exercise the reverse proxy by querying the application through it:

$ curl http://localhost:8080/api/fibonacci?pos=10000
2132534333
$ curl http://localhost:8080/api/echo?echo=test
test

OpenTracing

Navigate to the Jaeger UI at http://localhost:16686/ to see some traces:

jaeger screenshot

Prometheus Metrics

Prometheus metrics are available in the usual spot:

$ curl http://localhost:8080/metrics
# HELP go_rev_proxy_requests_latency_ms Summary of Request Latency (ms)
# TYPE go_rev_proxy_requests_latency_ms summary
go_rev_proxy_requests_latency_ms{path="/api/echo",quantile="0.5"} 1
go_rev_proxy_requests_latency_ms{path="/api/echo",quantile="0.9"} 11
go_rev_proxy_requests_latency_ms{path="/api/echo",quantile="0.99"} 11
go_rev_proxy_requests_latency_ms_sum{path="/api/echo"} 15
go_rev_proxy_requests_latency_ms_count{path="/api/echo"} 6
go_rev_proxy_requests_latency_ms{path="/api/fibonacci",quantile="0.5"} 1
go_rev_proxy_requests_latency_ms{path="/api/fibonacci",quantile="0.9"} 300
go_rev_proxy_requests_latency_ms{path="/api/fibonacci",quantile="0.99"} 300
go_rev_proxy_requests_latency_ms_sum{path="/api/fibonacci"} 303
go_rev_proxy_requests_latency_ms_count{path="/api/fibonacci"} 6

Redis

Logging shows the impact of caching

proxy_1    | Starting Request http://backend:8080/api/echo?echo=test
proxy_1    | Caching: Miss http://backend:8080/api/echo?echo=test
proxy_1    | Ending Request http://backend:8080/api/echo?echo=test
proxy_1    | 2019/07/10 02:39:58 HTTPRequest took 11.4113ms
proxy_1    | Starting Request http://backend:8080/api/echo?echo=test
proxy_1    | Caching: Hit http://backend:8080/api/echo?echo=test
proxy_1    | Ending Request http://backend:8080/api/echo?echo=test
proxy_1    | 2019/07/10 02:39:58 HTTPRequest took 1.0331ms

Final Thoughts

Overall this turned into a fun project that allowed for some basic exploration of go, caching, tracing and other technologies. This code should never be used in any real world scenario. However, if you're interested in doing similar things you may find some useful sample code buried in here.

Improvements that could be made:

  • Respect incoming OpenTracing headers
  • Set outgoing OpenTracing headers
  • Add distributed rate limiting through Redis
  • Make caching, tracing, etc. configurable
  • Only cache gets

go-rev-proxy's People

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.