- API gateway
- Distributed Tracing with OpenTelemetry
1. API Gateway with Kong
Kong with Database mode
$git clone https://github.com/Kong/docker-kong
$cd docker-kong/compose/
$KONG_DATABASE=postgres docker compose --profile database up -d
Status of Kong server and database
$docker compose ps
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
compose-db-1 postgres:9.5 "docker-entrypoint.s…" db 49 seconds ago Up 49 seconds (healthy) 5432/tcp
compose-kong-1 kong:latest "/docker-entrypoint.…" kong 49 seconds ago Up 44 seconds (healthy) 0.0.0.0:8000-8002->8000-8002/tcp, [::]:8001-8002->8001-8002/tcp, 0.0.0.0:8443-8444->8443-8444/tcp, [::]:8444->8444/tcp
- http://localhost:8000 - send traffic to your service via Kong
- http://localhost:8001 - configure Kong using Admin API or via decK
- http://localhost:8002 - access Kong's management Web UI (Kong Manager)
$cd kong-plugins
$docker image build -t mykong .
Start Kong server with image=mykong
$docker compose --profile database down
$docker volume prune
$export KONG_DOCKER_TAG=mykong
$KONG_DATABASE=postgres docker compose --profile database up -d
$docker compose ps
List of plugins in Kong manager
- Add service
- Add plugin
demo-authto service- http/https
- URl=http://auth-service:1323/auth
- Add route to service
Add service
$curl http://127.0.0.1:8001/services \
-d name=demo-api \
-d url=https://jsonplaceholder.typicode.com
Add route to service
$curl http://127.0.0.1:8001/services/demo-api/routes \
-d name=demo-api \
-d 'paths[]=/test'
Check
$docker compose build auth-service
$docker compose up -d auth-service
List of urls
Check from API Gateway
- List of services
- API gateway with Kong
- Auth service
Add plugins in Kong with Global scope
- http://localhost:8002/plugins
- New plugin
- Metric with prometheus
- Trace and Log with opentelemetry
- traces_endpoint: http://localhost:4318/v1/traces
- logs_endpoint: http://localhost:4318/v1/logs
- New plugin
6. Start LGTM Stack
- Log
- Grafana
- Trace
- Metric
$docker compose up -d lgtm
$docker compose up ps
Edit traces_endpoint
Check data in Grafana dashboard
$docker compose build python-service
$docker compose up -d python-service
List of urls
- http://localhost:9001
- http://localhost:9001/metrics
- http://localhost:9001/health
- http://localhost:9001/articles
- Add service
- Add route to service
Add service
$curl http://127.0.0.1:8001/services \
-d name=python-service \
-d url=http://python-service:8000
Add route to service
$curl http://127.0.0.1:8001/services/python-service/routes \
-d name=python-service \
-d 'paths[]=/python'
Check from API Gateway
- Express
- OpenTelemetry
- Database with PostgreSQL
$docker compose build nodejs-service
$docker compose up -d nodejs-service
List of urls
- http://localhost:9002
- http://localhost:9002/metrics
- http://localhost:9002/call-db
- http://localhost:9002/steps
- Add service
- Add route to service
Add service
$curl http://127.0.0.1:8001/services \
-d name=nodejs-service \
-d url=http://nodejs-service:3000
Add route to service
$curl http://127.0.0.1:8001/services/nodejs-service/routes \
-d name=nodejs-service \
-d 'paths[]=/nodejs'
Check from API Gateway
- http://localhost:8000/nodejs
- http://localhost:8000/nodejs/health
- http://localhost:8000/nodejs/call-db
- http://localhost:8000/nodejs/steps
9. Application metrics with Prometheus
- API gateway with Kong
- Python service
- NodeJS service
- Config in file
prometheus/prometheus.yml - Start server
File prometheus.yml
scrape_configs:
- job_name: 'api-gateway'
scrape_interval: 5s
metrics_path: '/metrics'
static_configs:
- targets: ['kong:8001']
labels:
application: 'kong'
- job_name: 'python-service'
scrape_interval: 5s
metrics_path: '/metrics'
static_configs:
- targets: ['python-service:8000']
labels:
application: 'python-service'
- job_name: 'nodejs-service'
scrape_interval: 5s
metrics_path: '/metrics'
static_configs:
- targets: ['nodejs-service:3000']
labels:
application: 'nodejs-service'
Start server
$docker compose up -d prometheus
$docker compose ps
Access to prometheus
- http://localhost:9090
- Go to menu Status => Target health