FLASK server generated using Open API generator based on the specs. Uses PostgreSQL as a db for actual data.
Docker
To run the server, please execute the following from the root directory:
docker compose up --build
and open your browser to see swagger ui:
http://localhost:8080/ui/
The entire dashboard settings file with PromQL can be found in ./grafana/provisioning/dashboards/grafana-dashboard.json
- REQUEST_COUNT, PromQL: sum by (method, endpoint, http_status) (rate(request_count_total[1m]))
- REQUEST_LATENCY, PromQL: histogram_quantile(0.95, sum(rate(request_latency_seconds_bucket[5m])) by (le, method, endpoint))
- STATUS_CODE_COUNT, PromQL: sum by (status_code) (rate(status_code_count_total[1m]))
- CPU_USAGE
- MEMORY_USAGE
Uses prometheus-client within the flask app to track all the metrics. Uses pull model and gets the data from ../metrics endpoint automatically (described in prometheus.yml file). Metrics are being pulled from python-server:8080 (in the basic case: localhost/8080).
Uses prometheus server in a docker container to gather and store all the metrics
Uses grafana in a container to display the data from prometheus server. Grafana dashboard is defined in grafana-dashboard.json file and includes 5 graphs.
Grafana is automatically set up with configuration files while using
docker compose up --build
Grafana:
http://localhost:3001
If you want to directly see the metrics:
http://localhost:8080/metrics
If you want to directly access Prometheus:
http://localhost:9090/
PromQL examples:
rate(request_count_total[1m])
sum by (method, endpoint, http_status) (rate(request_count_total[1m]))
sum by (status_code) (rate(status_code_count_total[1m]))
histogram_quantile(0.95, sum(rate(request_latency_seconds_bucket[5m])) by (le, method, endpoint))
Implements logs using files with promtail + Grafana Loki.
Logs are saved to a docker volume shared wiith a promtail server in another container. Promtail pushes logs to the Loki server instance. After that Grafana provides dashboards over those logs in Loki.
.env file is used to configure external ports promtail-config.yml is used to configure promtail, including push link:
http://loki:3100/loki/api/v1/push
loki-config.yml is used to configure loki.
Grafana and Loki are automatically set up with configuration files while using
docker compose up --build
Loki:
http://localhost:3100
Promtail metrics:
http://localhost:9080
Additional dashboards can be created to allow search for specific log instances or categories. LogQL is used to provide certain queries.
For example (can be found in ./grafana/provisioning/dashboards/loki-dashboard.json):
"{job=\"varlogs\"} |= `DELETE` |= \"DEBUG\" | logfmt --strict"
Traces are managed using Grafana Tempo and are sent to it's instance using OpenTelemetry. Spans are created to showcase the time it takes to complete different parts of a request.
Tempo is running using gRPC, it's port is 4317 to push data using gRPC. Pushing using HTTP is also available, though not used. The port is 4318.
To retrieve data from Tempo
http://localhost:3200
Dashboards are provided to anylize traces:
TraceQL examples:
{traceDuration > 4ms} | count() > 3
{resource.service.name="articles-api" && duration>10ms}
Here is an example of a trace:
Created 3 CI/CD workflows:
- Test the API
- Push image to dockerhub
- Deploy (an imitation)