我有一个微服务结构,其中包含一些基于 python/Django 的服务
结构如下:
用户kong阿尔法kong 测试版 kong 伽玛
这是我的kong.yml
声明式配置:
_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
这是运行 kong 的 docker-compose 文件
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"
从 alpha 服务中我使用 python 的requests
库来调用使用 python 的 beta 端点requests
要调用的库/live
gamma 的终点如下
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)
第一个问题
我发现了这个问题
https://github.com/Kong/kong/issues/3058
有没有办法解决/解决这个问题?
第二个问题
我使用 docker 容器运行 Zipkin UI,如下所示
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"
当我打开 Zipkin UI 时http://127.0.0.1:9411,跟踪显示了三个请求,如下所示:
- ########################## ~ 60 秒
- ################ ~ 40 秒
- ####### ~ 20 秒
虽然它应该是这样的
- ######### ~ 20 秒
- -.-.-.-.-.-.- ######### ~ 20 秒
- -.-.-.-.--.-.-.-.-.-.-.- ######### ~ 20 秒
为了实现这一目标,我需要使用下面列表中的库来检测每个服务:
https://zipkin.io/pages/tracers_instrumentation
问题 2 第 1 部分:如何才能让Python变得干净又好用呢?
问题 2 第 2 部分: 有没有办法不用这么做?我正在寻找与语言无关的延迟跟踪,并且可以通过 kong 完成,这样我就不必向服务 alpha、beta、gamma 添加任何内容