如何解决Kong First Reqtest延迟问题,如何限制对某些路线的访问,如何进行仪器
我有一个基于python/django的几个服务的微服务结构
。结构如下:
用户< ===> kong < ===> alpha< ===> kong < ===> beta< ===> 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
这是
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服务中运行kong的docker-compose文件,我使用python的request> request
库来调用beta的终点使用Python的请求
库来调用/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)
第一个问题
当我发送请求 http:http://127.0时。 0.1/伽玛/Live 返回响应需要20秒。 但是从第二次开始,它需要毫秒
我发现了这个问题
是否有一种方法可以解决/解决此问题?
第二个问题
我使用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时on http://127.0.0.1:9411 ,跟踪显示我的三个请求如下:
- ##### #####################
-
- #〜20 s
像这个
- ########
- 虽然应该 ## 〜20 s
- -.-.-.-.-.--------.-.-.-.-.-.-.-.-.- #########至20 s
,为了实现这一目标,我需要仪器使用下面列表中的库中的每项服务:
https://zipkin.io/pages/pages/tracers_instrumentation
问题2第1部分:我应该为干净易用的python做什么?
问题2第2部分:有没有办法不必这样做?我正在寻找语言敏捷的延迟跟踪,可以通过kong来完成,以便我不必在服务alpha,beta,gamma中添加任何东西
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 millisecondsall 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论