Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/py4mac/fizzbuzz
Fizzbuzz Technical Test
https://github.com/py4mac/fizzbuzz
golang grafana monitoring prometheus
Last synced: 4 days ago
JSON representation
Fizzbuzz Technical Test
- Host: GitHub
- URL: https://github.com/py4mac/fizzbuzz
- Owner: py4mac
- Created: 2022-08-16T19:18:46.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-01-26T21:33:26.000Z (almost 2 years ago)
- Last Synced: 2024-06-21T13:14:34.104Z (5 months ago)
- Topics: golang, grafana, monitoring, prometheus
- Language: Go
- Homepage:
- Size: 204 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Go Fizzbuzz implementation with PostgreSQL
[![Test](https://github.com/py4mac/fizzbuzz/workflows/Test/badge.svg)](https://github.com/py4mac/fizzbuzz/releases/latest)
[![codecov](https://codecov.io/gh/py4mac/fizzbuzz/branch/main/graph/badge.svg)](https://codecov.io/gh/py4mac/fizzbuzz)Exercise: Write a simple fizz-buzz REST server.
"The original fizz-buzz consists in writing all numbers from 1 to 100, and just replacing all multiples of 3 by ""fizz"", all multiples of 5 by ""buzz"", and all multiples of 15 by ""fizzbuzz"".
The output would look like this: ""1,2,fizz,4,buzz,fizz,7,8,fizz,buzz,11,fizz,13,14,fizzbuzz,16,...""."Your goal is to implement a web server that will expose a REST API endpoint that:
- Accepts five parameters: three integers int1, int2 and limit, and two strings str1 and str2.
- Returns a list of strings with numbers from 1 to limit, where: all multiples of int1 are replaced by str1, all multiples of int2 are replaced by str2, all multiples of int1 and int2 are replaced by str1str2.The server needs to be:
- Ready for production
- Easy to maintain by other developersBonus: add a statistics endpoint allowing users to know what the most frequent request has been. This endpoint should:
- Accept no parameter
- Return the parameters corresponding to the most used request, as well as the number of hits for this request# Setup local development
## Clone repository
```sh
❯ git clone [email protected]:py4mac/fizzbuzz.git
```## Install tools
The following tools are required to be installed on local machine.
[Golang](https://go.dev/) in version 1.19
[Docker](https://www.docker.com/products/docker-desktop/) docker and docker-compose
[Linter](https://golangci-lint.run/usage/install/) for linter source code
[Swag](https://github.com/swaggo/swag) for generating swagger documentation
[Migrate](https://github.com/golang-migrate/migrate) for database migrations
[Mock](https://github.com/golang/mock) for mocking
[Godoc](https://github.com/golang/mock) for generating live documentation, to install it run `❯ go install golang.org/x/tools/cmd/godoc@latest`## Other stacks
These other stacks are already pre-installed inside differents containers. No installation is required here, it's just for information.
[PostgreSQL](https://github.com/jackc/pgx) as fizzbuzz persistent store
[Opentelemetry](https://opentelemetry.io/) for tracing
[Prometheus](https://prometheus.io/) monitoring and alerting
[Grafana](https://grafana.com/) to expose dashboards collecting Prometheus metrics
[Echo](https://github.com/labstack/echo) web framework## Getting Started
### Run unittest
```sh
❯ make test
```### Run local containers
The following command starts PostgreSQL, Jaeger, Prometheus and Grafana containers.
```sh
❯ make start_local
```### Initialize database
Onece PostgreSQL container is running, the following command initialize the database.
```sh
❯ make migrate_up
```### Run local application
```sh
❯ make run
```# Services availables
Once local containers and local application is started, the following endpoints are availables.
## Swagger
It exposes RestAPI handlers
http://localhost:8000/swagger/index.html### Fizzbuzz
**URL** : `/api/v1/fizzbuzz`
**Method** : `GET`
```sh
❯ curl -i http://localhost:8000/api/v1/fizzbuzz\?int1\=3\&int2\=5\&limit\=100\&str1\=fizz\&str2\=buzz
HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
Vary: Origin
Date: Thu, 18 Aug 2022 09:14:59 GMT
Content-Length: 415"1,2,fizz,4,buzz,fizz,7,8,fizz,buzz,11,fizz,13,14,fizzbuzz,16,17,fizz,19,buzz,fizz,22,23,fizz,buzz,26,fizz,28,29,fizzbuzz,31,32,fizz,34,buzz,fizz,37,38,fizz,buzz,41,fizz,43,44,fizzbuzz,46,47,fizz,49,buzz,fizz,52,53,fizz,buzz,56,fizz,58,59,fizzbuzz,61,62,fizz,64,buzz,fizz,67,68,fizz,buzz,71,fizz,73,74,fizzbuzz,76,77,fizz,79,buzz,fizz,82,83,fizz,buzz,86,fizz,88,89,fizzbuzz,91,92,fizz,94,buzz,fizz,97,98,fizz,buzz"
```### Stats
**URL** : `/api/v1/stats`
**Method** : `GET`
```sh
❯ curl -i http://localhost:8000/api/v1/stats
HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
Vary: Origin
Date: Thu, 18 Aug 2022 09:16:09 GMT
Content-Length: 70{"hits":20,"int1":3,"int2":5,"limit":100,"str1":"fizz","str2":"buzz"}
```## Metrics Endpoint
http://localhost:8080/metrics
## Jaeger
http://localhost:16686
## Prometheus
http://localhost:9090
## Grafana
http://localhost:3000/d/3bB90wi4z/fizzbuzz
## Stop local containers
```sh
❯ make stop_local
```# Setup production environment
### Run production containers
```sh
❯ make start_prod
```and database migration script
```sh
❯ make migrate_up
```# Services availables
Once production containers are started, the same services are started. The same endpoints are also availables.
# Source code documentation
An other command is available to explore live documentation
```sh
❯ make doc
```