負載回報服務 (LRS
)
這個簡單的範例示範了 Envoy 的 負載回報服務 (LRS) 功能以及如何使用它。
假設叢集 A(下游)與叢集 B(上游)和叢集 C(上游)通訊。當為叢集 A 啟用負載回報時,LRS 伺服器應該將 LoadStatsResponse 與 LoadStatsResponse.Clusters 為 B 和 C 發送至叢集 A。然後 LRS 伺服器將從叢集 A 到叢集 B 以及從叢集 A 到叢集 C 接收 LoadStatsRequests(帶有總請求、成功請求等)。
在此範例中,所有傳入的請求都透過 Envoy 路由到簡單的 goLang 網頁伺服器(又稱 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,然後 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。