通過(guò)ARMS Go探針和ASM對(duì)Go應(yīng)用進(jìn)行全鏈路灰度并實(shí)時(shí)監(jiān)控
本文介紹如何通過(guò)ARMS Go探針和ASM對(duì)Go應(yīng)用進(jìn)行全鏈路灰度并實(shí)時(shí)監(jiān)控。
Demo應(yīng)用
Demo應(yīng)用部署架構(gòu):
Demo應(yīng)用YAML:
所有應(yīng)用均部署在go-gray命名空間下。
apiVersion: apps/v1 kind: Deployment metadata: name: requestsender namespace: go-gray spec: replicas: 1 selector: matchLabels: app: requestsender template: metadata: labels: app: requestsender ASM_TRAFFIC_TAG: v1 version: v1 armsPilotCreateAppName: requestsender armsPilotAutoEnable: 'on' aliyun.com/app-language: golang spec: containers: - name: requestsender image: registry.cn-hangzhou.aliyuncs.com/private-mesh/hellob:requestsender-demo imagePullPolicy: Always ports: - containerPort: 8080 --- apiVersion: v1 kind: Service metadata: name: requestsender namespace: go-gray spec: selector: app: requestsender ports: - protocol: TCP port: 80 targetPort: 8080 type: ClusterIP
apiVersion: apps/v1 kind: Deployment metadata: name: go-demo-a-base namespace: go-gray spec: replicas: 1 selector: matchLabels: app: go-demo-a template: metadata: labels: app: go-demo-a armsPilotAutoEnable: "on" ASM_TRAFFIC_TAG: v1 version: v1 armsPilotCreateAppName: "go-demo-a" aliyun.com/app-language: golang spec: containers: - name: go-demo-a image: registry.cn-hangzhou.aliyuncs.com/private-mesh/hellob:a-demo imagePullPolicy: Always ports: - containerPort: 8080 --- apiVersion: apps/v1 kind: Deployment metadata: name: go-demo-a-gray namespace: go-gray spec: replicas: 1 selector: matchLabels: app: go-demo-a template: metadata: labels: app: go-demo-a ASM_TRAFFIC_TAG: v2 version: v2 armsPilotCreateAppName: go-demo-a armsPilotAutoEnable: 'on' aliyun.com/app-language: golang spec: containers: - name: go-demo-a-base image: registry.cn-hangzhou.aliyuncs.com/private-mesh/hellob:a-demo-gray imagePullPolicy: Always ports: - containerPort: 8080 --- apiVersion: v1 kind: Service metadata: name: go-demo-a namespace: go-gray spec: selector: app: go-demo-a ports: - protocol: TCP port: 80 targetPort: 8080 type: ClusterIP
apiVersion: apps/v1 kind: Deployment metadata: name: go-demo-b-base namespace: go-gray spec: replicas: 1 selector: matchLabels: app: go-demo-b template: metadata: labels: app: go-demo-b ASM_TRAFFIC_TAG: v1 version: v1 armsPilotCreateAppName: go-demo-b armsPilotAutoEnable: 'on' aliyun.com/app-language: golang spec: containers: - name: go-demo-b image: registry.cn-hangzhou.aliyuncs.com/private-mesh/hellob:b-demo imagePullPolicy: Always ports: - containerPort: 8080 --- apiVersion: apps/v1 kind: Deployment metadata: name: go-demo-b-gray namespace: go-gray spec: replicas: 1 selector: matchLabels: app: go-demo-b template: metadata: labels: app: go-demo-b ASM_TRAFFIC_TAG: v2 version: v2 armsPilotCreateAppName: go-demo-b armsPilotAutoEnable: 'on' aliyun.com/app-language: golang spec: containers: - name: go-demo-b image: registry.cn-hangzhou.aliyuncs.com/private-mesh/hellob:b-demo-gray imagePullPolicy: Always ports: - containerPort: 8080 --- apiVersion: v1 kind: Service metadata: name: go-demo-b namespace: go-gray spec: selector: app: go-demo-b ports: - protocol: TCP port: 80 targetPort: 8080 type: ClusterIP
apiVersion: apps/v1 kind: Deployment metadata: name: go-demo-c-base namespace: go-gray spec: replicas: 1 selector: matchLabels: app: go-demo-c template: metadata: labels: app: go-demo-c ASM_TRAFFIC_TAG: v1 version: v1 armsPilotCreateAppName: go-demo-c armsPilotAutoEnable: 'on' aliyun.com/app-language: golang spec: containers: - name: go-demo-c image: registry.cn-hangzhou.aliyuncs.com/private-mesh/hellob:c-demo imagePullPolicy: Always ports: - containerPort: 8080 --- apiVersion: apps/v1 kind: Deployment metadata: name: go-demo-c-gray namespace: go-gray spec: replicas: 1 selector: matchLabels: app: go-demo-c template: metadata: labels: app: go-demo-c ASM_TRAFFIC_TAG: v2 version: v2 armsPilotCreateAppName: go-demo-c armsPilotAutoEnable: 'on' aliyun.com/app-language: golang spec: containers: - name: go-demo-c image: registry.cn-hangzhou.aliyuncs.com/private-mesh/hellob:c-demo-gray imagePullPolicy: Always ports: - containerPort: 8080 --- apiVersion: v1 kind: Service metadata: name: go-demo-c namespace: go-gray spec: selector: app: go-demo-c ports: - protocol: TCP port: 80 targetPort: 8080 type: ClusterIP
使用ARMS監(jiān)控Golang應(yīng)用
通過(guò)Golang探針將Go應(yīng)用接入ARMS應(yīng)用監(jiān)控,即可在ARMS中查看對(duì)應(yīng)應(yīng)用的應(yīng)用拓?fù)洹⒔涌谡{(diào)用、數(shù)據(jù)庫(kù)分析等相關(guān)監(jiān)控?cái)?shù)據(jù)。
使用ASM進(jìn)行全鏈路灰度
創(chuàng)建ASM實(shí)例并添加集群。
使用以下內(nèi)容創(chuàng)建命名空間為istio-system的ingressgateway網(wǎng)關(guān)規(guī)則。具體操作,請(qǐng)參見(jiàn)創(chuàng)建ingressgateway網(wǎng)關(guān)規(guī)則。
apiVersion: networking.istio.io/v1beta1 kind: Gateway metadata: name: ingressgateway namespace: istio-system spec: selector: istio: ingressgateway servers: - port: number: 80 name: http protocol: HTTP hosts: - '*'
給Demo的所有應(yīng)用注入Sidecar并重啟。具體操作,請(qǐng)參見(jiàn)安裝Sidecar代理。
配置鏈路追蹤。
創(chuàng)建opentelemetry-operator-system命名空間。
kubectl create namespace opentelemetry-operator-system
創(chuàng)建鏈路追蹤的Service。
apiVersion: v1 kind: Service metadata: name: default-collector namespace: opentelemetry-operator-system spec: ports: - port: 4317 protocol: TCP targetPort: 4317 selector: app: default-collector sessionAffinity: None type: ClusterIP
在ASM控制臺(tái)開(kāi)啟鏈路追蹤。
OpenTelemetry服務(wù)域名(完整FQDN):default-collector.opentelemetry-operator-system.svc.cluster.local
OpenTelemetry服務(wù)端口:4317
在可觀測(cè)配置頁(yè)面的鏈路追蹤設(shè)置區(qū)域,啟用鏈路追蹤,并按需配置采樣率。
創(chuàng)建泳道組test。
配置項(xiàng)
說(shuō)明
trace id請(qǐng)求頭
traceparent
引流請(qǐng)求頭
x-asm-prefer-tag
泳道服務(wù)
requestsender、go-demo-a、go-demo-b、go-demo-c
創(chuàng)建v1和v2泳道。
配置項(xiàng)
說(shuō)明
泳道名稱
分別配置為v1、v2
配置服務(wù)標(biāo)簽
標(biāo)簽名稱:選擇ASM_TRAFFIC_TAG
標(biāo)簽值:分別選擇v1、v2
添加服務(wù)
v1泳道:選擇requestsender、go-demo-a、go-demo-b、go-demo-c
v2泳道:選擇go-demo-a、go-demo-c
分別為v1和v2泳道添加引流規(guī)則。
配置項(xiàng)
說(shuō)明
入口服務(wù)
選擇requestsender.go-gray.svc.cluster.local
引流規(guī)則
名稱:分別輸入v1、v2
域名:*
匹配方式:精確
匹配內(nèi)容:/greetinit
創(chuàng)建完成示例:
驗(yàn)證結(jié)果
在頁(yè)面獲取ASM網(wǎng)關(guān)的公網(wǎng)IP。
執(zhí)行以下命令,設(shè)置環(huán)境變量。
xxx.xxx.xxx.xxx
為上一步獲取的IP。export ASM_GATEWAY_IP=xxx.xxx.xxx.xxx
驗(yàn)證全鏈路灰度功能是否生效。
基線:
for i in {1..100}; do curl -H 'x-asm-prefer-tag: v1' http://${ASM_GATEWAY_IP}/greetinit; echo ''; sleep 1; done;
預(yù)期輸出:
{"code":0,"data":{"greeting":"Hello ","callChain":"Init:base:172.30.208.29 - A:base:172.30.208.114 - B:base:172.30.208.116 - C:base:172.30.208.120"},"message":"success"} {"code":0,"data":{"greeting":"Hello ","callChain":"Init:base:172.30.208.29 - A:base:172.30.208.114 - B:base:172.30.208.116 - C:base:172.30.208.120"},"message":"success"}
灰度:
for i in {1..100}; do curl -H 'x-asm-prefer-tag: v2' http://${ASM_GATEWAY_IP}/greetinit; echo ''; sleep 1; done;
預(yù)期輸出:
{"code":0,"data":{"greeting":"Hello ","callChain":"Init:base:172.30.208.29 - A:gray:172.30.208.115 - B:base:172.30.208.116 - C:gray:172.30.208.122"},"message":"success"} {"code":0,"data":{"greeting":"Hello ","callChain":"Init:base:172.30.208.29 - A:gray:172.30.208.115 - B:base:172.30.208.116 - C:gray:172.30.208.122"},"message":"success"}
查看監(jiān)控?cái)?shù)據(jù)
在ARMS控制臺(tái)的 頁(yè)面查看對(duì)應(yīng)的Go應(yīng)用監(jiān)控。