'how to solve kong first reqtest delay problem, how to restrict access to some routes, how to do instrumentaion
I have a microservices structure with a few services based on python/Django
The structure is as below:
user <===> kong <===> alpha <===> kong <===> beta <===> kong <===> gamma
this is my kong.yml
declarative configuration:
_format_version: "2.1"
_transform: true
services:
- name: alpha-beta-gamma-live
host: alpha
port: 8000
protocol: http
path: /beta/gamma/live
routes:
- name: alpha-beta-gamma-live
methods:
- GET
paths:
- /alpha/beta/gamma/live
strip_path: true
- name: beta-gamma-live
host: beta
port: 8000
protocol: http
path: /gamma/live
routes:
- name: beta-gamma-live
methods:
- GET
paths:
- /beta/gamma/live
strip_path: true
- name: gamma-live
host: gamma
port: 8000
protocol: http
path: /live
routes:
- name: gamma-live
methods:
- GET
paths:
- /gamma/live
strip_path: true
plugins:
- name: correlation-id
config:
header_name: X-Kong-Correlation-ID
generator: uuid
echo_downstream: true
- name: zipkin
config:
local_service_name: kong
http_endpoint: http://zipkin:9411/api/v2/spans
sample_ratio: 1
include_credential: true
traceid_byte_count: 16
header_type: preserve
default_header_type: b3
tags_header: Zipkin-Tags
and this is the docker-compose file to run kong
version: "3.8"
networks:
kong-net:
name: kong-net
driver: bridge
ipam:
config:
- subnet: 172.1.1.0/24
services:
kong:
container_name: kong
build:
context: .
dockerfile: Dockerfile
restart: unless-stopped
networks:
kong-net:
ipv4_address: 172.1.1.40
healthcheck:
test: [ “CMD”, “curl”, “-f”, “http://kong:8000” ]
interval: 5s
timeout: 2s
retries: 15
environment:
- KONG_DATABASE=off
- KONG_ADMIN_LISTEN=0.0.0.0:8001, 0.0.0.0:8444 ssl
- KONG_PROXY_ACCESS_LOG=/dev/stdout
- KONG_ADMIN_ACCESS_LOG=/dev/stdout
- KONG_PROXY_ERROR_LOG=/dev/stderr
- KONG_ADMIN_ERROR_LOG=/dev/stderr
- KONG_DECLARATIVE_CONFIG=/kong/declarative/kong.yml
ports:
- "8444:8444"
- "80:8000"
- "443:8443"
from within alpha service I use python's requests
library to call an endpoint of beta that use python's requests
library to call /live
endpoint of gamma as below
alpha
version: '3'
networks:
kong-net:
name: kong-net
driver: bridge
ipam:
config:
- subnet: 172.1.1.0/24
services:
alpha:
container_name: alpha
build:
context: .
dockerfile: Dockerfile
restart: unless-stopped
networks:
kong-net:
ipv4_address: 172.1.1.11
ports:
- "8011:8000"
environment:
SECRET_KEY: secret-key
DEBUG: 'true'
command: python manage.py runserver 0.0.0.0:8000
@api_view(["GET"])
def beta_gamma_live(request):
res_kong = requests.get("http://kong:8000/beta/gamma/live")
return Response({
"chained-alpha-beta-gamma-status-check-through-kong": res_kong.status_code,
}, status.HTTP_200_OK)
beta
version: '3'
networks:
kong-net:
name: kong-net
driver: bridge
ipam:
config:
- subnet: 172.1.1.0/24
services:
beta:
container_name: beta
build:
context: .
dockerfile: Dockerfile
restart: unless-stopped
networks:
kong-net:
ipv4_address: 172.1.1.12
ports:
- "8012:8000"
environment:
SECRET_KEY: secret-key
DEBUG: 'true'
command: python manage.py runserver 0.0.0.0:8000
@api_view(["GET"])
def gamma_live(request):
res_kong = requests.get("http://kong:8000/gamma/live")
return Response({
"chained-beta-gamma-status-check-through-kong": res_kong.status_code,
}, status.HTTP_200_OK)
gamma
version: '3'
networks:
kong-net:
name: kong-net
driver: bridge
ipam:
config:
- subnet: 172.1.1.0/24
services:
gamma:
container_name: gamma
build:
context: .
dockerfile: Dockerfile
restart: unless-stopped
networks:
kong-net:
ipv4_address: 172.1.1.13
ports:
- "8013:8000"
environment:
SECRET_KEY: secret-key
DEBUG: 'true'
command: python manage.py runserver 0.0.0.0:8000
@api_view(["GET"])
def live(request):
return Response({"status": "Success"}, status.HTTP_200_OK)
The First Question
When I send a request http://127.0.0.1/gamma/live it takes 20 seconds to return the response. But from the second time, it takes milliseconds
all requests sent to http://127.0.0.1/alpha/beta/gamma/live take 40 seconds
I have found this issue about it
https://github.com/Kong/kong/issues/3058
Is there a way to fix/address this problem?
Second question
I run Zipkin UI using a docker container as below
version: '3'
networks:
kong-net:
name: kong-net
driver: bridge
ipam:
config:
- subnet: 172.1.1.0/24
services:
zipkin:
container_name: zipkin
build:
context: .
dockerfile: Dockerfile
restart: unless-stopped
networks:
kong-net:
ipv4_address: 172.1.1.41
ports:
- "9411:9411"
When I open Zipkin UI on http://127.0.0.1:9411, The trace shows me three requests as below:
- ########################## ~ 60 s
- ################ ~ 40 s
- ####### ~ 20 s
While it should be like this
- ######### ~ 20 s
- -.-.-.-.-.-.- ######### ~ 20 s
- -.-.-.-.--.-.-.-.-.-.-.- ######### ~ 20 s
In order to achieve this, I need to instrument each of the services using a library in the list below:
https://zipkin.io/pages/tracers_instrumentation
Question 2 part 1: What Should I do for python that is clean and easy to use?
Question 2 part 2: is there a way not to have to do it? I am looking for latency tracing that is language-agnostic and can be done through kong so that I don't have to add anything to the services alpha, beta, gamma
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|