如何过滤 Istio 遥测上报的指标包?
解读
在国内云原生落地场景中,Istio 的遥测数据默认通过 HTTP/gRPC 主动推送到 Prometheus 或 阿里云 ARMS 等后端,而非被动拉取。Wireshark 面试时,考官想确认你能否在 混杂流量 里精准抓到这些“主动上报”的指标包,并排除业务 Pod 正常通信的噪音。核心思路是:先定位上报端口,再按协议特征二次过滤。
知识点
- Istio 1.20+ 默认端口:
- Prometheus 输出:
15090/TCP(Envoy Admin 的/stats/prometheus) - gRPC 上报:
15020/TCP(istio-agent 的istio-proxy容器,路径/stats/prometheus或/stats/grpc) - 阿里云 ASM:
9128/TCP(本地 Node 上的 arms-prom 进程)
- Prometheus 输出:
- HTTP 特征:
POST或GET路径带/stats/prometheus,User-Agent: Prometheus/或istio-proxy - gRPC 特征:
HTTP/2帧头,:path: /istio.mixer.v1.Mixer/Report或/envoy.service.metrics.v3.MetricsService/StreamMetrics - TLS 场景:若启用 STRICT mTLS,需先导入 Envoy Secret 或 istio-certs 到 Wireshark 的 TLS 解密列表,否则只能看到 TCP 443 密文
- K8s 侧信息:通过
kubectl get svc -n istio-system prometheus -ojsonpath='{.spec.ports[0].port}'确认实际端口,避免死记硬背
答案
步骤如下,可直接在 Wireshark 3.6+ 图形界面或 tshark 命令行复现:
-
捕获范围
在 Node 上执行(避免 sidecar 截断):sudo tshark -i any -f "tcp port 15090 or tcp port 15020 or tcp port 9128" -w istio_metrics.pcap -
显示过滤器
打开 pcap 后,在 Filter Bar 输入:(tcp.port == 15090 || tcp.port == 15020 || tcp.port == 9128) && (http.request.uri contains "/stats/prometheus" || http2.headers.path contains "/stats/prometheus" || grpc.path contains "StreamMetrics") -
TLS 解密(可选)
若集群开启 mTLS,把 istio-certs 目录下的cert-chain.pem+key.pem导入:Edit → Preferences → Protocols → TLS → (RSA keys list)端口填
15090,协议填http,即可看到明文指标 -
验证
选中一条HTTP/2 200帧,Follow → HTTP/2 Stream,可看到返回体为 Prometheus 文本格式,含envoy_cluster_upstream_rq_total等 Istio 标准指标,即证明过滤成功
拓展思考
- 多集群联邦场景:若使用 Thanos Sidecar 通过 gRPC 10901 上传,需要把端口也加入捕获范围,并用
grpc.service_name == "thanos.Store"二次过滤 - eBPF 无侧车模式:Istio Ambient Mesh 的 ztunnel 采用 HBONE(HTTP/2 CONNECT over UDP 443) 隧道,Wireshark 3.7+ 已支持 HTTP/3 dissector,可用
udp.port == 443 && http3.stream_type == "CONNECT"先拆隧道,再按上述逻辑过滤内部指标流 - 面试加分项:提到 Wireshark 的 "Statistics → I/O Graph" 可把指标包速率绘成折线,直观展示 Istio 遥测风暴;或写一段 Lua post-dissector 自动提取
istio_request_total的实时值,直接打印在 Packet List 的自定义列,体现自动化分析能力