负载报告服务 (LRS
)
这个简单的示例演示了 Envoy 的 负载报告服务 (LRS) 功能及其使用方法。
假设集群 A(下游)与集群 B(上游)和集群 C(上游)通信。启用集群 A 的负载报告后,LRS 服务器应向集群 A 发送 LoadStatsResponse,其中 LoadStatsResponse.Clusters 为 B 和 C。然后,LRS 服务器将从集群 A 到集群 B 以及从集群 A 到集群 C 接收 LoadStatsRequests(包含总请求数、成功请求数等)。
在本示例中,所有传入请求都通过 Envoy 路由到一个简单的 goLang Web 服务器(即 http_server)。我们扩展了两个容器,并随机向每个容器发送请求。Envoy 被配置为发起与 LRS 服务器的连接。LRS 服务器通过发送 LoadStatsResponse 来启用统计信息。发送到 http_server 的请求将计入成功请求,并在 LRS 服务器日志中可见。
步骤 1:构建沙盒
切换到 examples/load-reporting-service
目录。
终端 1
$ pwd
envoy/examples/load-reporting-service
$ docker compose pull
$ docker compose up --scale http_service=2
终端 2
$ pwd
envoy/examples/load_reporting_service
$ docker compose ps
Name Command State Ports
-----------------------------------------------------------------------------------------------------------------
load-reporting-service_http_service_1 /docker-entrypoint.sh /usr ... Up 10000/tcp, 0.0.0.0:81->80/tcp
load-reporting-service_http_service_2 python3 /code/service.py ... Up (healthy)
load-reporting-service_lrs_server_1 go run main.go Up
步骤 2:开始发送 HTTP 请求流
终端 2
$ pwd
envoy/examples/load_reporting_service
$ bash send_requests.sh
上面的脚本 (send_requests.sh
) 随机向每个 Envoy 发送请求,后者再将请求转发到后端服务。
步骤 3:查看 Envoy 统计数据
您应该看到
终端 1
............................
lrs_server_1 | 2020/02/12 17:08:20 LRS Server is up and running on :18000
lrs_server_1 | 2020/02/12 17:08:23 Adding new cluster to cache `http_service` with node `0022a319e1e2`
lrs_server_1 | 2020/02/12 17:08:24 Adding new node `2417806c9d9a` to existing cluster `http_service`
lrs_server_1 | 2020/02/12 17:08:25 Creating LRS response for cluster http_service, node 2417806c9d9a with frequency 2 secs
lrs_server_1 | 2020/02/12 17:08:25 Creating LRS response for cluster http_service, node 0022a319e1e2 with frequency 2 secs
http_service_2 | 127.0.0.1 - - [12/Feb/2020 17:09:06] "GET /service HTTP/1.1" 200 -
http_service_1 | 127.0.0.1 - - [12/Feb/2020 17:09:06] "GET /service HTTP/1.1" 200 -
............................
lrs_server_1 | 2020/02/12 17:09:07 Got stats from cluster `http_service` node `0022a319e1e2` - cluster_name:"local_service" upstream_locality_stats:<locality:<> total_successful_requests:21 total_issued_requests:21 > load_report_interval:<seconds:1 nanos:998411000 >
lrs_server_1 | 2020/02/12 17:09:07 Got stats from cluster `http_service` node `2417806c9d9a` - cluster_name:"local_service" upstream_locality_stats:<locality:<> total_successful_requests:17 total_issued_requests:17 > load_report_interval:<seconds:1 nanos:994529000 >
http_service_2 | 127.0.0.1 - - [12/Feb/2020 17:09:07] "GET /service HTTP/1.1" 200 -
http_service_1 | 127.0.0.1 - - [12/Feb/2020 17:09:07] "GET /service HTTP/1.1" 200 -
............................
lrs_server_1 | 2020/02/12 17:09:09 Got stats from cluster `http_service` node `0022a319e1e2` - cluster_name:"local_service" upstream_locality_stats:<locality:<> total_successful_requests:3 total_issued_requests:3 > load_report_interval:<seconds:2 nanos:2458000 >
lrs_server_1 | 2020/02/12 17:09:09 Got stats from cluster `http_service` node `2417806c9d9a` - cluster_name:"local_service" upstream_locality_stats:<locality:<> total_successful_requests:9 total_issued_requests:9 > load_report_interval:<seconds:2 nanos:6487000 >
另请参阅
- 负载报告服务
Envoy 负载报告服务的概述。
- 负载报告服务 API(V3)
负载报告服务 API。