Istio 使用 Apache SkyWalking 进行服务链路追踪、链路监控告警

本文主要是介绍Istio 使用 Apache SkyWalking 进行服务链路追踪、链路监控告警,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

一、Istio 使用 Apache SkyWalking 链路追踪和告警

SkyWalking是一个开源的观测平台,用于从服务和云原生等基础设施中收集、分析、聚合以及可视化数据,SkyWalking 提供了一种简便的方式来清晰地观测分布式系统,甚至可以观测横跨不同云的系统,SkyWalking 更像是一种现代的应用程序性能监控(Application Performance Monitoring,即APM)工具,专为云原生,基于容器以及分布式系统而设计。

此外,SkyWalking 还提供了链路监控告警功能,允许用户在服务性能指标异常时及时得到通知。用户可以定义多种告警规则,如服务响应时间、成功率等指标的阈值,当指标超过阈值时触发告警。系统还会记录所有告警的历史信息,便于用户回顾和分析系统的稳定性问题。

在这里插入图片描述

Istio 针对链路追踪本身就支持多种方式,包括 Zipkin、JaegerSkyWalking,默认支持 Zipkin 格式的追踪数据,本篇文章实验 Istio 使用 SkyWalking 进行服务链路追踪和监控告警,其中告警本次采用钉钉机器人,所以在开启前请准备好一个钉钉机器人,机器人的安全验证模式,这里我采用的加签模式:

在这里插入图片描述

二、K8s 部署 Apache SkyWalking

这里将 SkyWalking 的数据存储至 ES 中,需要有一个可用的 ES 服务,如果没有可以参考下面文章在 K8s 中部署一个:

K8s 部署 elasticsearch-7.14.0 集群 及 kibana 客户端

编写 skywalking.yml 清单,注意其中 ES 和钉钉机器人的信息换成你的环境下的:

vi skywalking.yml
kind: ConfigMap
apiVersion: v1
metadata:name: alarm-settingsnamespace: istio-system
data:alarm-settings.yml: |-rules:# Rule unique name, must be ended with `_rule`.service_resp_time_rule: ## 服务的平均响应时间超过1000毫秒时,如果在过去10分钟内发生3次,就会触发告警。metrics-name: service_resp_time op: ">"threshold: 1000period: 10count: 3silence-period: 5message: Response time of service {name} is more than 1000ms in 3 minutes of last 10 minutes.service_sla_rule: ## 服务的成功响应率低于80%(即8000/10000)时,如果在过去10分钟内发生2次,就会触发告警。# Metrics value need to be long, double or intmetrics-name: service_slaop: "<"threshold: 8000# The length of time to evaluate the metricsperiod: 10# How many times after the metrics match the condition, will trigger alarmcount: 2# How many times of checks, the alarm keeps silence after alarm triggered, default as same as period.silence-period: 3message: Successful rate of service {name} is lower than 80% in 2 minutes of last 10 minutesservice_resp_time_percentile_rule: ## 服务的响应时间百分位数(p50, p75, p90, p95, p99)中的任何一个超过1000毫秒时,如果在过去10分钟内发生3次,就会触发告警。# Metrics value need to be long, double or intmetrics-name: service_percentileop: ">"threshold: 1000,1000,1000,1000,1000period: 10count: 3silence-period: 5message: Percentile response time of service {name} alarm in 3 minutes of last 10 minutes, due to more than one condition of p50 > 1000, p75 > 1000, p90 > 1000, p95 > 1000, p99 > 1000service_instance_resp_time_rule: ## 服务实例的平均响应时间metrics-name: service_instance_resp_timeop: ">"threshold: 1000period: 10count: 2silence-period: 5message: Response time of service instance {name} is more than 1000ms in 2 minutes of last 10 minutesdatabase_access_resp_time_rule: ## 数据库访问的平均响应时间metrics-name: database_access_resp_timethreshold: 1000op: ">"period: 10count: 2message: Response time of database access {name} is more than 1000ms in 2 minutes of last 10 minutesendpoint_relation_resp_time_rule: ## 端点关系的平均响应时间metrics-name: endpoint_relation_resp_timethreshold: 1000op: ">"period: 10count: 2message: Response time of endpoint relation {name} is more than 1000ms in 2 minutes of last 10 minutes#  Active endpoint related metrics alarm will cost more memory than service and service instance metrics alarm.#  Because the number of endpoint is much more than service and instance.##  endpoint_resp_time_rule:#    metrics-name: endpoint_resp_time#    op: ">"#    threshold: 1000#    period: 10#    count: 2#    silence-period: 5#    message: Response time of endpoint {name} is more than 1000ms in 2 minutes of last 10 minutesdingtalkHooks:textTemplate: |-{"msgtype": "text","text": {"content": "Apache SkyWalking Alarm: \n %s."} }webhooks:- url: https://oapi.dingtalk.com/robot/send?access_token=你的机器人tokensecret: 你的Secret---
apiVersion: apps/v1
kind: Deployment
metadata:name: skywalking-oapnamespace: istio-systemlabels:app: skywalking-oap
spec:selector:matchLabels:app: skywalking-oaptemplate:metadata:labels:app: skywalking-oapsidecar.istio.io/inject: "false"spec:containers:- name: skywalking-oapimage: apache/skywalking-oap-server:9.1.0env:- name: SW_HEALTH_CHECKERvalue: default- name: SW_STORAGEvalue: elasticsearch- name: SW_STORAGE_ES_CLUSTER_NODESvalue: es.default.svc.cluster.local:9200- name: SW_ES_USERvalue: esuser- name: SW_ES_PASSWORDvalue: espasswordvolumeMounts:- name: alarm-settingsmountPath: /skywalking/config/alarm-settings.ymlsubPath: alarm-settings.ymlreadinessProbe:exec:command:- /skywalking/bin/swctl- healthinitialDelaySeconds: 30periodSeconds: 5volumes:- name: alarm-settingsconfigMap:                                name: alarm-settings---
apiVersion: v1
kind: Service
metadata:name: tracingnamespace: istio-systemlabels:app: skywalking-oap
spec:type: ClusterIPports:- name: grpcport: 11800protocol: TCPtargetPort: 11800- name: http-queryport: 12800protocol: TCPtargetPort: 12800selector:app: skywalking-oap
---
apiVersion: v1
kind: Service
metadata:labels:name: skywalking-oapname: skywalking-oapnamespace: istio-system
spec:ports:- port: 11800targetPort: 11800name: grpc- port: 12800targetPort: 12800name: http-queryselector:app: skywalking-oap
---
apiVersion: apps/v1
kind: Deployment
metadata:name: skywalking-uinamespace: istio-systemlabels:app: skywalking-ui
spec:selector:matchLabels:app: skywalking-uitemplate:metadata:labels:app: skywalking-uiannotations:sidecar.istio.io/inject: "false"spec:containers:- name: skywalking-uiimage: apache/skywalking-ui:9.1.0env:- name: SW_OAP_ADDRESSvalue: http://skywalking-oap:12800readinessProbe:httpGet:path: /port: 8080initialDelaySeconds: 30periodSeconds: 5
---
apiVersion: v1
kind: Service
metadata:name: tracing-uinamespace: istio-systemlabels:app: skywalking-ui
spec:type: ClusterIPports:- name: httpport: 8080protocol: TCPtargetPort: 8080selector:app: skywalking-ui
---
apiVersion: v1
kind: Service
metadata:labels:name: skywalking-uiname: skywalking-uinamespace: istio-system
spec:type: NodePortports:- port: 8080targetPort: 8080name: httpselector:app: skywalking-ui

其中告警规则字段的解释如下:

metrics-name:监控的指标名称。
op:比较操作符(例如 > 表示大于)。
threshold:触发告警的阈值。
period:评估指标的周期(分钟)。
count:在周期内满足条件的最小次数,以触发告警。
silence-period:告警触发后的静默期(分钟)。
message:告警消息,其中 {name} 将被替换为实际的服务名、实例名或端点名。

提交:

kubectl apply -f skywalking.yml

查看 pod

kubectl get pods -n istio-system

在这里插入图片描述

查看 skywalking-uiNodePort 端口:

kubectl get svc -n istio-system

在这里插入图片描述

浏览器访问:http://{node ip}:32327:

在这里插入图片描述

三、Istio 配置向 SkyWalking 发送链路追踪

Istio 代理默认不向 SkyWalking 发送链路追踪,需要修改 Istio 配置文件,在 k8s 中是以 ConfigMap 的方式存储的:

kubectl get cm -n istio-system

在这里插入图片描述

修改 istio

kubectl edit cm istio -n istio-system

defaultProviders 下增加 :

    defaultProviders:metrics:- prometheustracing:- "skywalking"

extensionProvidersskywalking 的地址指向上面部署的服务:

    extensionProviders:- name: skywalkingskywalking:port: 11800service: tracing.istio-system.svc.cluster.local

整体配置如下:

在这里插入图片描述
保存后自动生效。

四、链路追踪测试

这里部署 istio 官方使用的 Bookinfo 示例应用,测试链路追踪,该应用的结构如下:

在这里插入图片描述

创建一个命名空间,将Bookinfo 服务放在该空间下:

kubectl create ns test

给该命名空间添加标签,指示在部署应用的时候,自动注入 Envoy 边车代理:

kubectl label namespace test istio-injection=enabled

部署 Bookinfo 示例应用:

kubectl apply -f https://raw.githubusercontent.com/istio/istio/release-1.21/samples/bookinfo/platform/kube/bookinfo.yaml -n test

查看 pod

kubectl get pods -n test

在这里插入图片描述

部署 Bookinfo 应用的 GatewayVirtualService ,允许外部访问:

kubectl apply -f https://raw.githubusercontent.com/istio/istio/release-1.21/samples/bookinfo/networking/bookinfo-gateway.yaml -n test

查看 istio-ingressgateway 入口的 NodePort 端口:

kubectl get svc istio-ingressgateway -n istio-system

在这里插入图片描述

80端口对应的是 30868 ,然后使用浏览器访问 http://{node port}:30868/productpage ,可以打开 Bookinfo的示例页面:

在这里插入图片描述
然后多刷新访问几次后,去 SkyWalking 中查看,可以看到服务信息已经记录上来了:

在这里插入图片描述

点击 Topology 可以看到服务链路模型

在这里插入图片描述

点击 Trace 可以看到详细追踪信息:

在这里插入图片描述

五、链路监控告警测试

修改 Bookinfo 应用 review 的访问规则,使用 VirtualService 注入随机故障:

vi reviews-vs.yml
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:name: reviews-drnamespace: test
spec:host: reviewssubsets:- name: v1labels:version: v1- name: v2labels:version: v2- name: v3labels:version: v3---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:name: reviews-vsnamespace: test
spec:hosts:- "reviews"http:- route:- destination:host: reviewsport:number: 9080subset: v1weight: 30- destination:host: reviewsport:number: 9080subset: v2weight: 30- destination:host: reviewsport:number: 9080subset: v3weight: 40fault:delay:percentage:value: 20fixedDelay: 5sabort:percentage:value: 80httpStatus: 500

这里随机注入了 20% 的请求产生 5 秒的延时,80% 的请求直接中止返回 500 状态码。

下面在浏览器多次访问 http://{node port}:30868/productpage ,等待片刻后观察 SkyWalking 中的告警信息:

在这里插入图片描述

已经出现告警了,此时钉钉机器人应该也收到了告警信息:

在这里插入图片描述

这篇关于Istio 使用 Apache SkyWalking 进行服务链路追踪、链路监控告警的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/980443

相关文章

鸿蒙中@State的原理使用详解(HarmonyOS 5)

《鸿蒙中@State的原理使用详解(HarmonyOS5)》@State是HarmonyOSArkTS框架中用于管理组件状态的核心装饰器,其核心作用是实现数据驱动UI的响应式编程模式,本文给大家介绍... 目录一、@State在鸿蒙中是做什么的?二、@Spythontate的基本原理1. 依赖关系的收集2.

Python基础语法中defaultdict的使用小结

《Python基础语法中defaultdict的使用小结》Python的defaultdict是collections模块中提供的一种特殊的字典类型,它与普通的字典(dict)有着相似的功能,本文主要... 目录示例1示例2python的defaultdict是collections模块中提供的一种特殊的字

C++ Sort函数使用场景分析

《C++Sort函数使用场景分析》sort函数是algorithm库下的一个函数,sort函数是不稳定的,即大小相同的元素在排序后相对顺序可能发生改变,如果某些场景需要保持相同元素间的相对顺序,可使... 目录C++ Sort函数详解一、sort函数调用的两种方式二、sort函数使用场景三、sort函数排序

Java String字符串的常用使用方法

《JavaString字符串的常用使用方法》String是JDK提供的一个类,是引用类型,并不是基本的数据类型,String用于字符串操作,在之前学习c语言的时候,对于一些字符串,会初始化字符数组表... 目录一、什么是String二、如何定义一个String1. 用双引号定义2. 通过构造函数定义三、St

springboot filter实现请求响应全链路拦截

《springbootfilter实现请求响应全链路拦截》这篇文章主要为大家详细介绍了SpringBoot如何结合Filter同时拦截请求和响应,从而实现​​日志采集自动化,感兴趣的小伙伴可以跟随小... 目录一、为什么你需要这个过滤器?​​​二、核心实现:一个Filter搞定双向数据流​​​​三、完整代码

SpringSecurity6.0 如何通过JWTtoken进行认证授权

《SpringSecurity6.0如何通过JWTtoken进行认证授权》:本文主要介绍SpringSecurity6.0通过JWTtoken进行认证授权的过程,本文给大家介绍的非常详细,感兴趣... 目录项目依赖认证UserDetailService生成JWT token权限控制小结之前写过一个文章,从S

Pydantic中Optional 和Union类型的使用

《Pydantic中Optional和Union类型的使用》本文主要介绍了Pydantic中Optional和Union类型的使用,这两者在处理可选字段和多类型字段时尤为重要,文中通过示例代码介绍的... 目录简介Optional 类型Union 类型Optional 和 Union 的组合总结简介Pyd

Vue3使用router,params传参为空问题

《Vue3使用router,params传参为空问题》:本文主要介绍Vue3使用router,params传参为空问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐... 目录vue3使用China编程router,params传参为空1.使用query方式传参2.使用 Histo

AJAX请求上传下载进度监控实现方式

《AJAX请求上传下载进度监控实现方式》在日常Web开发中,AJAX(AsynchronousJavaScriptandXML)被广泛用于异步请求数据,而无需刷新整个页面,:本文主要介绍AJAX请... 目录1. 前言2. 基于XMLHttpRequest的进度监控2.1 基础版文件上传监控2.2 增强版多

使用Python自建轻量级的HTTP调试工具

《使用Python自建轻量级的HTTP调试工具》这篇文章主要为大家详细介绍了如何使用Python自建一个轻量级的HTTP调试工具,文中的示例代码讲解详细,感兴趣的小伙伴可以参考一下... 目录一、为什么需要自建工具二、核心功能设计三、技术选型四、分步实现五、进阶优化技巧六、使用示例七、性能对比八、扩展方向建