在 Grafana 中如何展示 Istio 的 4xx/5xx 拓扑?

解读

国内生产级 Istio 环境普遍采用 Prometheus + Grafana 作为可观测性基座,面试官想验证候选人是否能把 服务网格黄金指标(4xx/5xx 比例)落到 拓扑图 上,并兼顾 命名空间隔离、权限、性能、告警 等企业级诉求。回答必须体现:

  1. 数据链路:Istio → Envoy → Prometheus → Grafana
  2. 拓扑插件:Node Graph / FlowChart / 自定义面板
  3. 查询语言:PromQL 精准匹配 4xx/5xx
  4. 国内云原生落地细节:ACK、TKE、Kubesphere 场景下的标签差异

知识点

  • Istio 标准指标:istio_request_total{response_code=~"4..|5.."}
  • Prometheus 服务发现:kubernetes-pods job 需保留 destination_service_name、source_workload、reporter 标签
  • Node Graph 面板:依赖 nodes 与 edges 两个查询,节点用 destination_service_name,边用 source_workload→destination_service_name
  • 国内标签坑:阿里云 ACK 注入的 pod_name 与开源 pod 字段不一致,需做 label_replace
  • 性能优化:拓扑边>1k 时启用 recording rule 预聚合:istio:4xx5xx:rate5m
  • 权限隔离:Grafana RBAC 利用 datasource permission + folder ACL 实现命名空间级只读
  • 告警联动:在拓扑面板下锚定 annotations 直达 SRE OnCall 群(钉钉)

答案

  1. 确认 Istio 已开启 default Prometheus metrics,且 reporter="destination" 标签完整
  2. Prometheus 侧新增 recording rule 减少实时计算:
    - record: istio:4xx5xx:rate5m
      expr: sum(rate(istio_request_total{response_code=~"4..|5.."}[5m])) by (source_workload, destination_service_name, namespace)
    
  3. Grafana 创建 Node Graph 面板:
    • 节点查询:
      label_values(istio:4xx5xx:rate5m, destination_service_name)
      
    • 边查询:
      istio:4xx5xx:rate5m > 0
      
    映射字段:source→source_workload,target→destination_service_name,value→错误率
  4. 开启 Color by value 阈值:0-1% 绿色,1-5% 橙色,>5% 红色,符合国内 SLO 红线 5%
  5. 在 Panel > Annotation 层叠 Istio 版本变更事件,方便 复盘
  6. 保存到 “Istio 拓扑” 文件夹,设置 namespace 变量 并绑定 datasource permission,实现 多租户只读
  7. 配置 告警:
    expr: sum(rate(istio_request_total{response_code=~"5.."}[2m])) by (destination_service_name) > 0.05
    for: 2m
    annotations:
      summary: "服务 {{ $labels.destination_service_name }} 5xx 率超 5%"
    
    通知渠道选择 钉钉机器人 加签模式,满足国内合规

拓展思考

  • 若集群规模>500 服务,可把 Node Graph 替换为 FlowCharting 插件,利用 Graphviz 预生成布局,降低浏览器渲染压力
  • 对 东西向流量 与 南北向流量 混布场景,可在 PromQL 增加 reporter 判断,分别绘制两张拓扑,避免 边缘网关 节点膨胀
  • 结合 Grafana Tempo,点击拓扑边可下钻到 Trace,实现 错误率→慢调用→具体 Span 三级下钻,符合国内 “一图定位” 的运维 KPI 诉求