Skip to content

A study on OpenAPI codegen, metrics, logs and traces using Grafana and CI/CD

Notifications You must be signed in to change notification settings

RoundRonin/development-tools

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OpenAPI generated server

Overview

FLASK server generated using Open API generator based on the specs. Uses PostgreSQL as a db for actual data.

Requirements

Docker

Usage

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/

Swagger examples

изображение

изображение

Testing the request: изображение

изображение

Testing the request: изображение

Grafana dashboard

Metrics

The entire dashboard settings file with PromQL can be found in ./grafana/provisioning/dashboards/grafana-dashboard.json

  1. REQUEST_COUNT, PromQL: sum by (method, endpoint, http_status) (rate(request_count_total[1m]))
  2. REQUEST_LATENCY, PromQL: histogram_quantile(0.95, sum(rate(request_latency_seconds_bucket[5m])) by (le, method, endpoint))
  3. STATUS_CODE_COUNT, PromQL: sum by (status_code) (rate(status_code_count_total[1m]))
  4. CPU_USAGE
  5. MEMORY_USAGE

Description

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

Access

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/

Image

изображение

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))

Logging

Description

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

Access

Loki:

http://localhost:3100

Promtail metrics:

http://localhost:9080

Image

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

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.

Access

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

Image

Dashboards are provided to anylize traces:

image

TraceQL examples:

{traceDuration > 4ms} | count() > 3
{resource.service.name="articles-api" && duration>10ms}

Here is an example of a trace:

изображение

CI/CD

Created 3 CI/CD workflows:

  1. Test the API
  2. Push image to dockerhub
  3. Deploy (an imitation)

About

A study on OpenAPI codegen, metrics, logs and traces using Grafana and CI/CD

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published