分布式链路追踪Jaeger + 微服务Pig在Rainbond上的实践分享

随着微服务架构的流行,客户端发起的一次请求可能需要涉及到多个或 N 个服务,致使我们对服务之间的监控和排查变得更加复杂。

「举个例子:」

某条业务线的某个接口调用服务端时快时慢,这时就需要排查各个服务的日志进行分析,调动各个服务的开发人员联动排查,这种排查费时又费力。对于 ToB 的业务有时候还拿不到日志,难搞哦!

因此,就需要可以帮助理解系统行为、用于分析性能问题的工具,以便发生故障的时候,能够快速定位和解决问题,那就是 APM (Application Performance Monitor)。目前流行的 APM 开源工具有很多,比如:Zipkin,Skywalking,Pinpoint、Jaeger 等等,本文将主要介绍 Jaeger 。

Jaeger 是 Uber 技术团队发布的开源分布式跟踪系统,它用于监控和故障排查基于微服务的分布式系统:

  • 分布式上下文传播、事务监控
  • 根本原因、服务依赖分析
  • 性能/延迟优化
  • OpenTracing 启发的数据模型
  • 多个存储后端:Cassandra, Elasticsearch, memory.
  • 系统拓扑图
  • 服务性能监控(SPM)
  • 自适应采样

Jaeger 架构

Component Description
Jaeger Client Jaeger Client SDK
Jaeger Agent 收集 Client 数据
Jaeger Collector 收集 Jaeger Agent 数据,有 pull/push 两种方式
DB Storage Collector 需要存储后端,Collector 拿到的数据将存在 Elasticsearch 或 Cassandra。
Spark jobs 用于生成拓扑图 UI 数据
Jaeger Query Service & UI 负责从 Storage 查询数据并提供 API 和 UI

如何在Rainbond上集成?

「1.集成 OpenTelemetry Client:」

v1.36 版本以前 Jaeger Client 是基于 OpenTracing API 实现的客户端库,Jaeger Client 结合 Jaeger Agent 一起使用,发送 span 到 Jaeger Collector。

v1.36 版本以后被弃用。使用 OpenTelemetry 替代 Jaeger Client and Jaeger Agent,详情见 Jaeger and OpenTelemetry

OpenTelemetry 是无侵入的,只需在 Java 进程启动时添加 javaagent,例:java -javaagent:path/to/opentelemetry-javaagent.jar -jar myapp.jar

那么在 Rainbond 上就可以通过插件将 OpenTelemetry javaagent 下载到组件中并修改启动命令。

「2.连接到 Jaeger-Collector:」

将所有安装了 OpenTelemetry javaagent 插件的微服务组件都通过依赖连接到 Jaeger Collector

实践步骤

实践中将使用 Spring Cloud Pig 进行演示,Gitee:https://gitee.com/zhangbigqi/pig

Rainbond 部署请参阅文档 快速安装

1. Spring Cloud Pig 源码部署

通过源码部署 Spring Cloud Pig 微服务框架就不详细介绍部署了,请参阅:

2. OpenTelemetry 插件安装

从应用商店安装 opentelemetry-java-agent 初始化插件,该插件的作用是下载 opentelemetry-javaagent.jar 到微服务组件内,可以在 Java 启动项中指定。

  • 团队视图 -> 插件 -> 从应用商店安装插件 -> 搜索 opentelemetry-java-agent 并安装。

3. 部署 Jaeger

在开源应用商店中搜索 Jaeger 并安装到指定应用中。

4. OpenTelemetry Agent 插件配置

「1.开通 OpenTelemetry Agent 插件」

pig-gateway 为例,在组件 -> 插件中开通 opentelemetry-java-agent 插件并更新组件生效,微服务内的其他组件均需要开通插件并更新或重启组件生效。

「2.配置环境变量」

为所有微服务组件配置环境变量。

变量名 变量值 说明
OTEL_TRACES_EXPORTER jaeger 选择 Jaeger exporter
OTEL_EXPORTER_JAEGER_ENDPOINT http://127.0.0.1:14250 Jaeger Collector gRPC endpoint
OTEL_EXPORTER_JAEGER_TIMEOUT 10000 超时时间(毫秒)
OTEL_METRICS_EXPORTER none Metrics 导出器
JAVA_OPTS -javaagent:/agent/opentelemetry-javaagent.jar Java 启动参数

可使用 应用配置组 统一配置并应用到所有组件中。

「3.配置组件服务名称」

为所有微服务组件配置环境变量 OTEL_SERVICE_NAME ,配置组件的 Jaeger 服务名称,如:OTEL_SERVICE_NAME=pig-gateway OTEL_SERVICE_NAME=pig-auth

5.建立依赖关系

将所有微服务组件添加依赖连接到 Jaeger Collector

Jaeger 部署在另外一个应用,需要进入 组件 -> 依赖 -> 添加 Jaeger Collector 依赖,就可以在当前应用的拓扑图看到 Jaeger Collector 组件,剩下的组件都可通过拓扑图编辑模式进行依赖连接。更新或重启所有微服务组件使依赖关系生效。

6. Jaeger 快速使用

  1. 访问 Spring Cloud Pig UI 进行登录,使其产生数据。

  2. 访问 Jaeger-Query16686 端口,打开对外服务即可访问 Jaeger UI

  3. 在 Jaeger Search 页面中搜索微服务 Pig-gateway 的 Traces

    • Service:选择微服务的组件
    • Operation:选择操作类型,例:GET POST、接口、类…..
    • Tags:根据响应头筛选,例:http.status_code=200 error=true
    • Lookback:选择时间
    • Max Duration:最大持续时间;Min Duration:最小持续时间。
    • Limit Results:限制返回结果数量。
  1. 找到 Pig-gateway HTTP POST 的 Traces 并包含了 pig-auth Span并进入,可看到很清晰的展示了服务之间一层一层的调用以及接口的响应时间,这样我们就可以排查到底是哪个服务调用的慢或者调用有问题。

「Jaeger 拓扑图生成」

拓扑图默认不会生成,使用 spark-dependencies 组件生成拓扑图数据,这是一个 Spark 作业,它从存储中收集 span,分析服务之间的链接,并将它们存储起来以供以后在 UI 中展示。请参阅 Jaeger Spark dependencies

spark-dependencies 组件占用资源较大,不使用时可关闭,需要生成拓扑图数据时将其启动即可。

最后

有了 APM 系统后,使我们可以更好的分析业务性能、排查故障等。

结合 Rainbond 作为基座不管是 Spring Cloud还是 Jaeger 或其他 APM 都可以很方便、快捷的部署使用,从繁琐的部署、配置中解放出来,让我们更多的关注于业务层。

K8S中文社区微信公众号

评论 4

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
  1. #4

    I’m excited to write about Henry Hacker, he is a great and brilliant hacker who penetrated my spouse’s phone without a physical installation app. And I was able to access my spouse’s phone, SMS, Whatsapp, Instagram, Facebook, Wechat, Snapchat, Call Logs, Kik, Twitter and all social media. The most amazing thing there is that he restores all phone deleted text messages. And I also have access to everything including the phone gallery without touching the phone.I can see the whole secret of my spouse. Contact him for any hacking service. He is also a genius in repairing Credit Score, increasing school grade, Clear Criminal Record etc. His service is fast. Contact on: Henryclarkethicalhacker@gmail.com and you can text, call him on whatsapp him on +18134211326…

    Eliott Sharon2个月前 (09-19)回复
  2. #3

    Hello Guys, I just completed my divorce with my cheating husband of 10 years with two beautiful kids when i got a solid evidence of his unfaithfulness on extra marital affairs and his infidelity lifestyle, And the various applications he used to hide chats and lot of secret on his cell phone. Then, i decided to hire (Henry clark) an hacker and a PI just to be 100% sure because i don’t want to confront him or take any kinda step without proof, fact and figures because that could leads to defamation… It was with this great, honest, professional and trustworthy Man i got to know my husband is a professional cheater and has been using this app to hide most of his chats. This great hacker helped me broke to into his cell phone activities and wired everything he does on his cell phone directly to my phone and i was able to monitor and track him directly from my phone remotely without him knowing,
    Contact the Ethical hacker via email, Henryclarkethicalhacker@gmail.com you can also reach him on Whatsapp 18134211326..

    Steve Jenna2个月前 (09-19)回复
  3. #2

    Contact him for any type of hacking, he is a professional hacker that specializes in exposing cheating spouses, and every other hacking related issues. he is a cyber guru, he helps catch cheating spouses by hacking their communications like call, Facebook, text, emails, Skype, whats-app and many more. I have used this service before and he did a very good job, he gave me every proof I needed to know that my fiancee was cheating. You can contact him on his email to help you catch your cheating spouse, or for any other hacking related problems, like hacking websites, bank statement, grades and many more. he will definitely help you, he has helped a lot of people, contact him on, Henryclarkethicalhacker@gmail.com, and you can Text/Call &WhatsApp: +1 (262)-236-7526, and figure out your relationship status. I wish you the best.

    Lucy Janet3周前 (11-13)回复
  4. #1

    Tracking cellphones and getting an accurate report has been a bit worrisome, thanks to Jeffrey whose service helped me locate certain cellphones without breaking a sweat. His service made me know that the internet has become the most common method of cheating nowadays, either emotionally or physically. Taking a few extra steps in getting what would serve as proof for leaving a toxic relationship, to see who your spouse texts or chats with on social media isn’t a bad idea, I’d recommend you reach out to Jeffreyethicalhacker@gmail.com
    Text,call or whatsapp on: +1 (747)345-9036
    TFYGUH

    dda liey5541周前 (11-23)回复