In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces "how to realize the request light call chain". In the daily operation, I believe that many people have doubts about how to realize the request light call chain. The editor consulted all kinds of materials and sorted out a simple and easy-to-use operation method. I hope it will be helpful to answer the doubt of "how to realize the request light call chain". Next, please follow the editor to study!
I. Preface
This paper introduces the server-side information collection of the call chain and the context transmission between services.
Second, server-side information collection
The overall process of server information collection is shown in the figure below. By inserting pointcuts during the startup of the application container (tomcat, etc.), the request is hijacked before and after the application logic is executed.
Before the application logic is executed: parse the call chain information in request and initialize the call chain context
After the application logic is executed, the call chain information in response is parsed, and all the call chain information processed by this request is output to the log file.
Third, tangent point implantation
Before introducing pointcuts, we should have an overall understanding of the general process of processing a request by the servlet container (this article uses tomcat as an example).
The picture comes from the Internet.
After the Connector receives a connection and converts it into a request (Request), the request is passed to the valve (ValveA) in the pipe (Pipeline) of the Engine. The request is passed to the valve Engine Valve in the pipeline of Engine. The request is then passed from Engine Valve to a Host pipe, where it is passed to the valve Host Valve. It is then passed from Host Valve to a pipe of Context, where it is passed to Context Valve. The request is then passed to the valve Wrapper Valve contained in the pipe in Wrapper C, where it passes through a filter chain (Filter Chain) and finally to a Servlet. With the help of this architectural design of tomcat, we can enhance the external capabilities of tomcat, that is, the middleware enhancement technology of UAV, by implanting our own logic in the life cycle of UAV to process a request.
The middleware enhancement technology not only skillfully uses the architectural design of the tomcat container, but also makes use of java Instrumentation (it provides us with the ability to dynamically modify the bytecode when the object is loaded for the first time, which is not explained in detail here because of the length, and the friends who do not understand consult the data by themselves). Provide a variety of pointcut capabilities through UAVServer in UAV.
With middleware enhancements, there are pointcuts before and after the application logic is executed, and then our own call chain logic is executed at these pointcuts.
Fourth, the use of middleware enhancement technology in the call chain
The inter-component enhancement technology described above is a framework that dynamically inserts pointcut code into tomcat code by using javaagent and provides capabilities in the form of UAVServer (specific capabilities will be described in more detail in future articles). The implementation of the light call chain uses the GlobalFilterHandler capabilities provided by UAVServer.
GlobalFilterHandler: GlobalFilterHandler here is a capability in middleware enhancement technology that has nothing to do with traditional filter. It provides four capabilities:
DoRequest: hijack before all applications process the request
DoResponse: hijack after all applications have processed the request
BlockHandlerChain: blocks all handler since the current handler, where the handler is registered in the current
BlockFilterChain blocks all Filter since the current Filter.
With the help of the first two capabilities provided by GlobalFilterHandler, the call chain implements the function of executing the call chain logic before and after the application processes the request.
Fifth, the realization of light call chain
The specific UML figure is as follows:
From the UML diagram, it is clear that InvokeChainSupporter (call chain implementation class for implementing logical entry and resource initialization required by call chain) has enhanced the middleware enhancement technology twice. It allows users to register different handler and dynamically weave adapter before and after the preCap and doCap (pointcut terminology before and after logic execution in middleware enhancement) methods of handler, thus performing more customized adaptation and personalization logic. All supporter and adapter adopt reflective invocation mode, which minimizes the dependence on middleware enhancement technology.
With the secondary enhancement technology, we can start the following call chain drawing work.
The implementation of light call chain drawing mainly depends on the ServiceSpanInvokeChainHandler registered on InvokeChainSupporter. The main drawing process is as follows:
Parse the request information, extract the information concerned by the calling chain, and put the parsed information into the context
Through the logical diversion of the parsed request header information, different logical processing is performed according to different protocol types; ✔ mq logic ✔ http logic ✔ dubbo logic
Initialize the call chain context and initialize the main span context
After the application processes the request, the call chain information is output uniformly.
Let's take a look at what has been done at each step.
5.1 parsing request information
For middleware containers such as tomcat, all requests into tomcat are encapsulated as HttpServletRequest and HttpServletResponse (hereinafter referred to as request and response) and eventually entered into the user's servlet. With the help of middleware enhancement technology, the call chain will intercept request and response once before the user logic processing, and parse whether it contains call chain information. If so, the call chain information is encapsulated and placed in the context.
5.2 logical shunt
Because the drawing logic of the call chain corresponding to different protocols is also different, the call chain here will be distributed according to the protocol type.
5.3 initialize the call chain context
Parse the information in the context of the call chain:
If there is no parent node, the current node is used as the initialization node, and the main span that records the call chain information within the current service is initialized.
The parent node initializes the current node according to the parent node information, and initializes the main span that records the call chain information in the current service.
Main span: multiple client or inter-service communications may occur within the service, and a main span is required to record the information of the last node in the call chain within the current service.
5.4 call chain information output
After the user logic processing is completed, the call chain logger fetches the call chain information for the current service from the context and outputs it to the specified log path.
5.5 context transmission between services
The way of transmitting information for different protocol call chains is also slightly different, and the specific implementation is based on another capability provided by middleware enhancement technology: AppFrkHook (referred to as hook, which will be introduced in detail when the client call chain is implemented). It can hijack the client technology used by the user. For example, if the user uses httpclient to communicate, then hijack the httpclient and dynamically weave the code, so as to achieve the effect of injecting the context information of the call chain in the process of http communication. When the target service parses the request information, it parses the call chain context; when initializing the call chain context logic, it uses the passed information to initialize the call chain context of the target service to achieve the connection across the system call chain.
At this point, the study on "how to achieve the request light call chain" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.