当前位置:网站首页>Who says cat can't do link tracking? Stand up for me
Who says cat can't do link tracking? Stand up for me
2020-11-06 01:29:00 【Yin Jihuan】
background
Link tracking , We have a lot of options . Common are zipkin,pinpoint,skywalking,jaeger etc. .
It's basically based on Google 《Dapper A tracking system for large-scale distributed systems 》 This paper developed .
Today, let's talk about Cat How to implement link tracking in , Never used Cat You can check this article of mine 《 Stay up late : One article for you to understand Cat Distributed monitoring 》 Get to know .
stay Cat It is convenient to see the total time consumption and business operation of each request , The time consumption of database operations . The call between services can also be monitored by means of embedding points .
Here's the picture , As you can see, one was initiated within the request RPC Call to ,callRPC The first record . Time consuming 11ms, But this RPC Where is the time spent inside the service , You can't view it directly here , You can only check it in another service , Not very convenient .
In detail, I drew a picture to illustrate the current problem :
As can be seen from the above figure , A request passes through multiple services , Each service has a buried point for remote or local calls , In this way, the exceptions and performance indicators of the call can be monitored .
The next part is in Cat Let's take a look at the scenarios of these indicators ,Cat Data presentation in is presented in terms of project dimensions , So each service has its own monitoring data .
If I want to know about that request , Where is the slowest in the whole link , Where does it take , I have to go separately 4 This information can only be seen in the following services , Is not intuitive .
Realization way
As shown in the figure below :
From gateway to service , From service to service , We need to Trace Only when the information is transmitted can the whole link be concatenated . Only when they are connected together can they be in Cat View the time-consuming information of the whole link in the .
The effect that this article needs to realize is that it can be at the entrance of the request ( gateway ), See all the services that this request passed through , Time spent in each service .
To connect the whole request , There must be a unique request identifier , Generally we call it traceId. The rest of the work is to pass the link related information layer by layer .
First, receive the request header information in the filter of each service , From gateway to service A, So service A This information needs to be received and passed on to the next service .
HTTP Request message tree construction :
// Building a remote message tree if(request.getHeader(CatConstantsExt.CAT_HTTP_HEADER_ROOT_MESSAGE_ID) != null){
CatContext catContext = new CatContext();
catContext.addProperty(Cat.Context.ROOT,request.getHeader(CatConstantsExt.CAT_HTTP_HEADER_ROOT_MESSAGE_ID));
catContext.addProperty(Cat.Context.PARENT,request.getHeader(CatConstantsExt.CAT_HTTP_HEADER_PARENT_MESSAGE_ID));
catContext.addProperty(Cat.Context.CHILD,request.getHeader(CatConstantsExt.CAT_HTTP_HEADER_CHILD_MESSAGE_ID));
Cat.logRemoteCallServer(catContext);
}
When passing the message tree information to the next service, it depends on how you call it , If you use Feign perhaps RestTemplate You can use interceptors to deliver .
public class FeignRequestInterceptor implements RequestInterceptor {
@Override
public void apply(RequestTemplate template) {
CatContext catContext = new CatContext();
Cat.logRemoteCallClient(catContext,Cat.getManager().getDomain());
template.header(CatConstantsExt.CAT_HTTP_HEADER_ROOT_MESSAGE_ID, catContext.getProperty(Cat.Context.ROOT));
template.header(CatConstantsExt.CAT_HTTP_HEADER_PARENT_MESSAGE_ID, catContext.getProperty(Cat.Context.PARENT));
template.header(CatConstantsExt.CAT_HTTP_HEADER_CHILD_MESSAGE_ID, catContext.getProperty(Cat.Context.CHILD));
}
}
If I use theta Dubbo You can use Dubbo Of Filter To achieve the same effect .
The final effect is shown in the figure below , Called articles/newest Interface , Gateway forwards request to article-provider service ,article-provider Call... Again user-provider Of users/uid Interface to get user information , most important of all user-provider We can also see the time consuming of these operations here , Very convenient .
Complete source reference : https://github.com/yinjihuan/kitty
About author : Yin Jihuan , Simple technology enthusiasts ,《Spring Cloud Microservices - Full stack technology and case analysis 》, 《Spring Cloud Microservices introduction Actual combat and advanced 》 author , official account Ape world Originator . Personal wechat jihuan900 , Welcome to hook up with .
I have compiled a complete set of learning materials , Those who are interested can search through wechat 「 Ape world 」, Reply key 「 Learning materials 」 Get what I've sorted out Spring Cloud,Spring Cloud Alibaba,Sharding-JDBC Sub database and sub table , Task scheduling framework XXL-JOB,MongoDB, Reptiles and other related information .
版权声明
本文为[Yin Jihuan]所创,转载请带上原文链接,感谢
边栏推荐
- ES6学习笔记(四):教你轻松搞懂ES6的新增语法
- 一篇文章带你了解CSS 渐变知识
- Filecoin主网上线以来Filecoin矿机扇区密封到底是什么意思
- Python + appium automatic operation wechat is enough
- Let the front-end siege division develop independently from the back-end: Mock.js
- Skywalking series blog 5-apm-customize-enhance-plugin
- Wiremock: a powerful tool for API testing
- 一篇文章教会你使用Python网络爬虫下载酷狗音乐
- Three Python tips for reading, creating and running multiple files
- Construction of encoder decoder model with keras LSTM
猜你喜欢
MeterSphere开发者手册
Do not understand UML class diagram? Take a look at this edition of rural love class diagram, a learn!
一篇文章带你了解CSS 渐变知识
axios学习笔记(二):轻松弄懂XHR的使用及如何封装简易axios
How to use Python 2.7 after installing anaconda3?
Python基础数据类型——tuple浅析
Three Python tips for reading, creating and running multiple files
这个项目可以让你在几分钟快速了解某个编程语言
ES6学习笔记(五):轻松了解ES6的内置扩展对象
Face to face Manual Chapter 16: explanation and implementation of fair lock of code peasant association lock and reentrantlock
随机推荐
EOS创始人BM: UE,UBI,URI有什么区别?
Analysis of etcd core mechanism
至联云分享:IPFS/Filecoin值不值得投资?
比特币一度突破14000美元,即将面临美国大选考验
6.2 handleradapter adapter processor (in-depth analysis of SSM and project practice)
[actual combat of flutter] pubspec.yaml Configuration file details
Wow, elasticsearch multi field weight sorting can play like this
这个项目可以让你在几分钟快速了解某个编程语言
vue-codemirror基本用法:实现搜索功能、代码折叠功能、获取编辑器值及时验证
Music generation through deep neural network
Vite + TS quickly build vue3 project and introduce related features
How to encapsulate distributed locks more elegantly
每个前端工程师都应该懂的前端性能优化总结:
一篇文章带你了解CSS3 背景知识
Common algorithm interview has been out! Machine learning algorithm interview - KDnuggets
Do not understand UML class diagram? Take a look at this edition of rural love class diagram, a learn!
In order to save money, I learned PHP in one day!
A course on word embedding
From zero learning artificial intelligence, open the road of career planning!
Python saves the list data