https://github.com/observatorium/observable-demo
Demo of the instrumented L7 HTTP loadbalancer in Go following best practices.
https://github.com/observatorium/observable-demo
best-practices demo instrumentation loadbalancer metrics prometheus
Last synced: 4 months ago
JSON representation
Demo of the instrumented L7 HTTP loadbalancer in Go following best practices.
- Host: GitHub
- URL: https://github.com/observatorium/observable-demo
- Owner: observatorium
- License: apache-2.0
- Created: 2020-01-09T11:01:57.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-01-26T10:33:22.000Z (over 6 years ago)
- Last Synced: 2024-06-21T06:42:07.017Z (almost 2 years ago)
- Topics: best-practices, demo, instrumentation, loadbalancer, metrics, prometheus
- Language: Go
- Homepage:
- Size: 73.2 KB
- Stars: 7
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# observable-demo
[](https://github.com/observatorium/observable-demo/releases) [](https://github.com/observatorium/observable-demo/commits/master) [](https://cloud.drone.io/observatorium/observable-demo)[](http://godoc.org/github.com/observatorium/observable-demo) [](https://goreportcard.com/report/github.com/observatorium/observable-demo)
This repository includes simple L7 round robin loadbalancer implementation, instrumented with metrics.
> `WARNING` : This is not meant to be production ready L7 loadbalancer. It's missing things like proper retrying, DNS discovery, logging, tracing etc, that might be added in future (:

This implementation was **mainly** used for presentations that showcase best practices for Prometheus based metrics Go instrumentation like:
* [Avoiding globals](https://github.com/observatorium/observable-demo/blob/e89e67a9e3e564d1ab3cb716835c8969f4bc1201/pkg/lbtransport/transport.go#L31).
* [Middlewares](https://github.com/observatorium/observable-demo/blob/e89e67a9e3e564d1ab3cb716835c8969f4bc1201/pkg/exthttp/middleware.go#L82) and [Tripperwares](https://github.com/observatorium/observable-demo/blob/d9cf53a171f4b016512337faa3e36411830525df/pkg/exthttp/tripperware.go#L46).
* Histograms [usage](https://github.com/observatorium/observable-demo/blob/e89e67a9e3e564d1ab3cb716835c8969f4bc1201/pkg/lbtransport/transport.go#L43).
* [Avoiding high cardinality](https://github.com/observatorium/observable-demo/blob/e89e67a9e3e564d1ab3cb716835c8969f4bc1201/pkg/lbtransport/transport.go#L42).
* [Initialising metrics](https://github.com/observatorium/observable-demo/blob/e89e67a9e3e564d1ab3cb716835c8969f4bc1201/pkg/lbtransport/transport.go#L62).
* [Wrapping registries](https://github.com/observatorium/observable-demo/blob/e89e67a9e3e564d1ab3cb716835c8969f4bc1201/pkg/exthttp/middleware.go#L84).
* Naming conventions
* [Testing metrics](https://github.com/observatorium/observable-demo/blob/d9cf53a171f4b016512337faa3e36411830525df/pkg/lbtransport/transport_test.go#L189)
## Using demo
This demo is runable.
To run loadbalancer and Prometheus in docker run:
``` console
make demo
```
After this, you should be able to go via browser to:
* `http://localhost:8080/lb` for load balancing endpoint, that loadbalanced to 3 fake endpoints.
* `http://localhost:8080/metrics` for metric page
* `http://localhost:9090` for Prometheus UI that scrapes loadbalancer every second.
To curl loadbalancer every 500ms to generate traffic run in separate terminal:
``` console
make demo-test
```