Bytecode-based micro-service governance method, device and product
By embedding the bytecode program generated by ASM in the microservice system to intercept and analyze the call relationship data, it solves the problems of high microservice governance development costs and security risks in the existing technology, realizes flexible monitoring and load balancing strategies, and improves improve system stability and performance.
Patent Information
- Application Number
- CN202410693045.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-30
- Publication Date
- 2024-09-24
AI Technical Summary
Existing microservice governance methods use bytecode technology to monitor the calling relationships between microservices, which have problems such as high development costs, difficulty in modification and expansion, and information security risks.
Adopt a bytecode-based microservice governance method, embed the target service in the microservice system through the target bytecode program generated by ASM, intercept the call relationship data, and conduct statistics and analysis by calling the relationship service, and use the load balancing strategy to determine the call Requested nodes, avoiding the use of third-party frameworks and complete monitoring systems.
It reduces development costs, improves the flexibility and security of monitoring call relationships between microservices, avoids the risk of information leakage, and achieves effective governance and performance optimization of microservice systems.
Smart Images

Figure CN118689666A
Abstract
Description
Technical Field
[0001] The present application relates to the field of microservice technology, and in particular to a bytecode-based microservice governance method, device, and product. Background Art
[0002] In the microservice scenario, as the business complexity increases, the complexity of calls between microservices increases dramatically, so the governance of microservices is particularly important. Microservice governance includes sorting out the call relationships between microservices, so as to facilitate load balancing of service nodes according to the call conditions between microservices. The governance of microservices usually includes arranging service clusters based on the call frequency between services so that services can be better split; selecting appropriate routing strategies for call requests; setting service scheduling priorities and traffic control; optimizing service performance and selecting grayscale strategies based on the dependencies between services.
[0003] Bytecode technology refers to the technology of compiling source code (such as Java source code) into an intermediate code form, which is called bytecode. Through bytecode technology, applications can be dynamically modified and expanded. In the current microservice governance scenario, bytecode technology is used to monitor and sort out the call relationship between services, usually using the third-party technology framework Skywalking and Java online diagnostic tool Arthas. Skywalking can intercept the start and end time of each service call, call link, service name, operation name, and call result data, and use this as a basis to calculate the performance indicators of the service, such as response time, throughput, concurrency, etc. It can also intercept SQL statements and include the executed SQL in the monitoring scope to analyze database performance and hot SQL. Arthas online troubleshooting can use attach dynamic mounting plus bytecode technology to dynamically insert bytecode on class methods, so as to obtain and analyze the target application and various runtime data in real time without affecting the application.
[0004] However, the method of using skywalking and Arthas to monitor the calling relationship between services has the following defects: the third-party framework is not universal and cannot ensure that the microservice cluster adopts skywalking. If functional modifications or expansions are required, secondary development of the third-party framework is required, which has high technical requirements for developers; when using a third-party framework, the microservice cluster needs to build a complete monitoring system, resulting in high development costs; the third-party framework has information security issues, which may lead to the leakage of user privacy data. Summary of the invention
[0005] In view of this, the present application aims to propose a bytecode-based microservice governance method, device and product to solve the current problems of high development cost, difficulty in modification and expansion, and information security risks when monitoring the calling relationship between microservices through bytecode technology.
[0006] To achieve the above purpose, the technical solution of this application is as follows:
[0007] A first aspect of an embodiment of the present application provides a bytecode-based microservice governance method, which is applied to a microservice system and includes:
[0008] Embed the target bytecode program generated based on the bytecode technology asm into the program of the target service; the target service is any service in the microservice system that needs to obtain call relationship data;
[0009] When the target service receives a call request, the call relationship data is intercepted by the target bytecode program; the call relationship data is information about the caller calling the target service, and the caller is other services, a third-party system or a user end in the microservice system;
[0010] transmitting the call relation data to a call relation service through the target bytecode program;
[0011] By using the call relationship service, statistics and analysis are performed on the received call relationship data to obtain result data;
[0012] A load balancing strategy is adopted to determine a node for executing the call request of the target service based on the result data.
[0013] Optionally, embedding the target bytecode program generated based on the bytecode technology asm into the program of the target service includes:
[0014] A target bytecode program is created by Byte Buddy bytecode technology, and is added to the Java virtual machine startup parameters of the target service in an agent manner, so that the target bytecode program runs before the program of the target service; the Byte Buddy bytecode technology is a bytecode generation solution based on the asm bytecode technology, and the Byte Buddy bytecode technology provides an API interface for quickly generating bytecode programs.
[0015] Optionally, intercepting the call relationship data through the target bytecode program includes:
[0016] When the Java virtual machine of the target service is started, premain is called as the entry function through Byte Buddy, and the target class that the target bytecode program needs to intercept is specified through AgentBuilder.Default(); the target class includes: a class annotated with @RestController and a class annotated with @Controller;
[0017] The call request received by the target service is intercepted through the AgentBuilder.Transformer instance, and the interface of each calling method is captured through method interception according to the annotations used by each interface of the target service, and the interceptor is specified to capture the call relationship data.
[0018] Optionally, specify an interceptor to capture call relationship data, including:
[0019] The interceptor executes the capture method. Before the call relationship data is captured, ByteBuddy is informed to inject the original data to be captured into the interceptor through annotations; the annotations include: @RuntimeType, @This, @AllArguments, @Origin, @Super and @SuperCall;
[0020] The capture method is executed by the interceptor, the call request is obtained using the RequestContextHolder tool class, and the identifier of the caller is obtained from the request header; the identifier of the caller is any one of the following: a service name, an identifier of a third-party system, or an identifier of a user terminal;
[0021] Executing the fetching method through the interceptor to obtain the service name of the target service from the configuration center or local configuration file of the target service;
[0022] Executing the capture method through the interceptor, comparing the request path of the call request with the path of the target service, replacing the path parameters in the request path, and obtaining the calling mode of the call request;
[0023] The identifier of the caller, the service name of the target service, the request path and the calling method are used as calling relationship data.
[0024] Optionally, specify an interceptor to capture call relationship data, including:
[0025] When obtaining the full-link call relationship of the call request, intercepting the call relationship data of the service to which the target bytecode program belongs through the target bytecode program in each service through which the call request passes;
[0026] When specifying an interceptor to capture the call relationship data, it also includes: executing a capture method through the interceptor to capture the TraceID of the call request received by the service.
[0027] Optionally, specify an interceptor to capture call relationship data, including:
[0028] The capture method is executed by the interceptor, and the load information of the node corresponding to the target service is obtained from the registration center according to the service name of the target service; wherein an instance of the target service is deployed in any node;
[0029] The load information of all nodes is sent to the call relationship service as call relationship data.
[0030] Optionally, transmitting the call relationship data to a call relationship service includes:
[0031] By means of the target bytecode program, the call relationship data is sent to the call relationship service via the WebFlux asynchronous transmission mode;
[0032] Through the call relationship service, the received call relationship data is placed into the message queue using RocketMQ asynchronous processing;
[0033] The call relationship service processes the call relationship data by consuming the MQ message in the message queue.
[0034] Optionally, after statistics and analysis are performed on the received call relationship data to obtain result data, the following further includes:
[0035] By calling the relationship service, storing the result data in a database;
[0036] Obtain result data from the database and push it visually through the calling relationship service;
[0037] Through the call relationship service, based on the business scenario of the current call target service, result data with a high call frequency is obtained from the database and cached.
[0038] Optionally, the bytecode-based microservice governance method further includes:
[0039] When the caller calls the target service through the gateway, the gateway queries the call relationship service for load information of all nodes of the target service, and dynamically adjusts the load rules of each node using a load balancing strategy;
[0040] In the case where the caller does not call the target service through the gateway, the call relationship service is queried for load information of all nodes of the target service through OpenFeign, and the load balancing strategy is used to dynamically adjust the load rules of each node.
[0041] According to a second aspect of an embodiment of the present application, a bytecode-based microservice management device is provided, which is used to implement the bytecode-based microservice management method provided in the first aspect of the embodiment of the present application, and the device includes:
[0042] The embedding module is configured to embed the target bytecode program generated based on the bytecode technology asm into the program of the target service; the target service is any service in the microservice system that needs to obtain call relationship data;
[0043] An interception module is configured to intercept call relationship data through the target bytecode program when the target service receives a call request; the call relationship data is information about a caller calling the target service, and the caller is other services in the microservice system, a third-party system, or a user end;
[0044] A transmission module, configured to transmit the call relationship data to a call relationship service through the target bytecode program;
[0045] A processing module is configured to perform statistics and analysis on the received call relationship data through the call relationship service to obtain result data;
[0046] The load adjustment module is configured to adopt a load balancing strategy and determine a node for executing the call request of the target service based on the result data.
[0047] According to a third aspect of an embodiment of the present application, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps in the bytecode-based microservice governance method as described in the first aspect of the embodiment of the present application are implemented.
[0048] According to a fourth aspect of an embodiment of the present application, a computer program product is provided, including a computer program. When the computer program is executed by a processor, the steps in the bytecode-based microservice governance method as described in the first aspect of the embodiment of the present application are implemented.
[0049] The bytecode-based microservice governance method provided by the present application is adopted to create a target bytecode program, and the target bytecode program is directly added to the target service in the microservice system whose call relationship needs to be monitored. When the target service is running, the target bytecode program runs at the same time. When the target service receives a call request, the call request is intercepted by the target bytecode program, and the information therein is captured as call relationship data and sent to the call relationship service for statistics and analysis. The call relationship service stores the call relationship data after statistics and analysis, so that the caller of the target service can use the load balancing strategy to route the call of the target service to a certain node according to the call relationship data of the target service.
[0050] The method provided in this application does not require the construction of a complete monitoring system, nor does it use the bytecode technology of a third-party framework, thereby saving development costs and ensuring data security. Since this application generates bytecode programs directly based on the lowest-level scheme asm of bytecode, the monitoring function for the target service can be flexibly modified and expanded by directly modifying the code, thereby improving the flexibility of monitoring the calling relationship between microservices. BRIEF DESCRIPTION OF THE DRAWINGS
[0051] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the description of the embodiments of the present application will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0052] Figure 1 It is a flowchart of a bytecode-based microservice governance method proposed in one embodiment of the present application;
[0053] Figure 2 is a schematic diagram of a bytecode-based microservice management device proposed in one embodiment of the present application;
[0054] Figure 3 This is a schematic diagram of the transmission path of calling relationship data in an embodiment of the present application;
[0055] Figure 4 It is a schematic diagram of the gateway dynamically adjusting the operating rules for calling the target service in one embodiment of the present application. DETAILED DESCRIPTION
[0056] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0057] It should be understood that the references to "one embodiment" or "an embodiment" throughout the specification mean that the specific features, structures, or characteristics associated with the embodiment are included in at least one embodiment of the present application. Therefore, the references to "in one embodiment" or "in an embodiment" appearing throughout the specification do not necessarily refer to the same embodiment. In addition, these specific features, structures, or characteristics may be combined in any suitable manner in one or more embodiments.
[0058] In the various embodiments of the present application, it should be understood that the size of the serial numbers of the following processes does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.
[0059] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present application. Instead, they are merely examples of devices and methods consistent with some aspects as detailed in the present application.
[0060] It should be noted that, in the absence of conflict, the embodiments and features in the embodiments of the present application may be combined with each other.
[0061] The present application will be described in detail below with reference to the accompanying drawings and in combination with embodiments.
[0062] Figure 1 is a flow chart of a bytecode-based microservice governance method proposed in an embodiment of the present application. The method is applied to a microservice system, such as Figure 1 As shown, the method includes:
[0063] S1: embedding the target bytecode program generated based on the bytecode technology asm into the program of the target service; the target service is any service in the microservice system that needs to obtain call relationship data;
[0064] S2: When the target service receives a call request, the call relationship data is intercepted by the target bytecode program; the call relationship data is information about the caller calling the target service, and the caller is other services in the microservice system, a third-party system or a user end;
[0065] S3: transmitting the call relation data to a call relation service through the target bytecode program;
[0066] S4: Through the call relationship service, statistics and analysis are performed on the received call relationship data to obtain result data;
[0067] S5: Adopt a load balancing strategy and determine a node for executing the call request of the target service based on the result data.
[0068] In this embodiment, the target bytecode program is first generated based on the asm bytecode technology, and then the target bytecode program is embedded in the program of the target service that needs to monitor the call relationship between services, and runs together with the target service. When the target service is called by the front end (third-party system or client) or by other services in the microservice system, the call request is intercepted by the target bytecode program and the call relationship data therein is captured and sent to the call relationship service. The call relationship service receives the call relationship data sent by the bytecode programs of all services in the microservice system and performs statistics and analysis, and stores the result data for the call service to determine the call request routing, and adopts the load balancing strategy to determine the node currently executing the target service. According to the result data stored in the call relationship service, it is possible to dynamically allocate the call request to different service instances corresponding to the target service according to the load situation of the target service, so as to avoid overloading of a single node.
[0069] Figure 3 Schematic diagram of the transmission path of calling relationship data in one embodiment of the present application. Figure 3 As shown, the caller ( Figure 3 When a third-party system, user terminal or service A calls a target service, the call relationship data of the target service is captured through the target bytecode program embedded in the target service, and the captured call relationship data is sent to the call relationship service for statistics and analysis to obtain result data, which is the statistical data obtained by statistics or the analysis results obtained by analysis.
[0070] In this embodiment, a third-party framework is not used. The target bytecode program is directly generated based on the underlying asm bytecode technology, and the target bytecode program is embedded in the target service, thereby ensuring data security and reducing development costs. The call relationship data of the target service is captured in real time through the target bytecode program, and the call relationship data of all services in the microservice system are counted and analyzed in combination with the call relationship service, thereby realizing the monitoring of the call relationship between microservices and the dynamic load balancing adjustment of nodes, and improving the stability and overall performance of the system.
[0071] Optionally, embedding the target bytecode program generated based on the bytecode technology asm into the program of the target service includes:
[0072] A target bytecode program is created by Byte Buddy bytecode technology, and is added to the Java virtual machine startup parameters of the target service in an agent manner, so that the target bytecode program runs before the program of the target service; the Byte Buddy bytecode technology is a bytecode generation solution based on the asm bytecode technology, and the Byte Buddy bytecode technology provides an API interface for quickly generating bytecode programs.
[0073] Asm bytecode technology is the lowest level solution for modifying bytecodes. It can directly generate, modify, and save binary class files. However, it is difficult to use asm directly, and requires a full understanding of assembly. This embodiment uses ByteBuddy technology to generate and modify bytecode programs. Byte Buddy is an advanced bytecode generation solution that provides a rich and flexible API interface that can quickly create new classes, inherit existing classes, and dynamically reconstruct classes. Its main goal is to generate code with fast execution time, and its bottom layer is based on asm bytecode technology. The bytecode generation solution based on Byte Buddy can be applied to non-containerized deployment, containerized deployment, and K8S deployment scenarios at the same time. The advantage is that it will not be coupled with the code of the target service.
[0074] In this embodiment, when the target service is started, the target bytecode program is added to the JVM (Java virtual machine) startup parameters in agent mode, thereby embedding the target bytecode program into the target service. Specifically, the agent path is added to the JVM startup parameter "javaagent", and the startup item is modified to make the agent effective. Instrumentation (a class library provided by JVM that can modify loaded classes) pre-sets a premain method, which will be called before the main method of the target service program. When premain is called, instrument can be used to convert the binary class file, so that the target bytecode program runs before the target service and intercepts the call request received by the target service.
[0075] Optionally, intercepting the call relationship data through the target bytecode program includes:
[0076] When the Java virtual machine of the target service is started, premain is called as the entry function through Byte Buddy, and the target class that the target bytecode program needs to intercept is specified through AgentBuilder.Default(); the target class includes: a class annotated with @RestController and a class annotated with @Controller;
[0077] The call request received by the target service is intercepted through the AgentBuilder.Transformer instance, and the interface of each calling method is captured through method interception according to the annotations used by each interface of the target service, and the interceptor is specified to capture the call relationship data.
[0078] In this embodiment, it is necessary to specify the information that needs to be intercepted for the target bytecode program. When the JVM is just started, Byte Buddy uses premain as the entry function and AgentBuilder.Default() to specify the class to be intercepted. In this embodiment, the entry of all interfaces of the target service is set to intercept, that is, the classes with @RestController annotations and @Controller annotations are intercepted.
[0079] When the target service is called, the target bytecode program intercepts the call request through the AgentBuilder.Transformer instance, intercepts all call interfaces using method according to the annotations used by each interface of the target service, and entrusts the specified interceptor to capture the request data.
[0080] In one embodiment, only some interfaces of the service can be intercepted and the call relationship data can be captured according to actual needs, instead of uniformly intercepting all interfaces of the target service. By specifying the interface to be intercepted, when a call request is received, only the specified interface is intercepted and information is captured, saving bandwidth resources and improving capture efficiency.
[0081] Optionally, specify an interceptor to capture call relationship data, including:
[0082] The interceptor executes the capture method. Before the call relationship data is captured, ByteBuddy is informed to inject the original data to be captured into the interceptor through annotations; the annotations include: @RuntimeType, @This, @AllArguments, @Origin, @Super and @SuperCall;
[0083] The capture method is executed by the interceptor, the call request is obtained using the RequestContextHolder tool class, and the identifier of the caller is obtained from the request header; the identifier of the caller is any one of the following: a service name, an identifier of a third-party system, or an identifier of a user terminal;
[0084] Executing the fetching method through the interceptor to obtain the service name of the target service from the configuration center or local configuration file of the target service;
[0085] Executing the capture method through the interceptor, comparing the request path of the call request with the path of the target service, replacing the path parameters in the request path, and obtaining the calling mode of the call request;
[0086] The identifier of the caller, the service name of the target service, the request path and the calling method are used as calling relationship data.
[0087] In this embodiment, the specific business logic processing is performed in the specified interceptor through the capture method. Specifically, the capture method informs Byte Buddy in advance through annotations, and the original data that needs to be captured for call relationship data is injected into the interceptor. In this embodiment, the interceptor captures data containing the following annotations: @RuntimeType, @This, @AllArguments, @Origin, @Super, and @SuperCall. The functions of each annotation are as follows:
[0088] @RuntimeType: tells Byte Buddy not to perform strict parameter type checking. When parameter matching fails, try to use runtime type casting to convert the type to match the corresponding method.
[0089] @This: Injects the intercepted target object;
[0090] @AllArguments: Injects all parameters of the target method;
[0091] @Origin: Injects the Method object corresponding to the target method. If the interception is a field, this annotation needs to be annotated to the Field type parameter;
[0092] @Super: Injects the target object. All methods of the target object can be called through this object;
[0093] @SuperCall: The target method needs to be injected in this way when calling the intercept() method, and the calling parameters cannot be modified. In addition, the @SuperCall annotation can also modify the parameters of the Runnable type, but the return value of the target method cannot be obtained.
[0094] In this embodiment, the interceptor obtains the current call request through RequestContextHolder in the capture method, and captures the identifier of the service caller (third-party system, user end or other service) from the request header. If it is a third-party system and user end, it corresponds to a specific third-party identifier and UI identifier, and for other services in the microservice system, it has a corresponding service name. The interceptor obtains the service name of the callee (i.e., the target service) from the configuration center or local configuration file of the service callee through the capture method, and compares the call path of the call request with the path of the callee (target service), replaces the path parameters in the path of the call request and obtains the call method of the call request (for example, GET, POST, PUT, DELETE, etc.). The interceptor sends the captured caller identifier, the service name of the callee, the path of the call request and the call method as call relationship data to the call relationship service.
[0095] In one embodiment, when the target bytecode program specifies that the interceptor captures information in the call request, filtering conditions can be further set based on the information that does not need to be captured. There are request data and parameter data (for example, basic data that needs to be calculated) in the call request for calling the target service, and the call relationship service does not need to use the parameter data when counting and analyzing. Therefore, an interception rule can be set in the capture method to specify that the interceptor ignores the parameter data when capturing the request data. Optionally, since the request data and parameter data are usually placed in different locations of the call request, the interception rule can be set based on the data storage location, the request header of the call request is intercepted, and the request body is filtered out, thereby reducing the amount of data processed by the interceptor, saving bandwidth resources, and also improving the capture efficiency of the call relationship data.
[0096] Optionally, specify an interceptor to capture call relationship data, including:
[0097] When obtaining the full-link call relationship of the call request, intercepting the call relationship data of the service to which the target bytecode program belongs through the target bytecode program in each service through which the call request passes;
[0098] When specifying an interceptor to capture the call relationship data, it also includes: executing a capture method through the interceptor to capture the TraceID of the call request received by the service.
[0099] In one embodiment, if it is necessary to monitor the call relationship data of all services through which the call request passes during a request service call (i.e., monitor the call relationship between services in the entire link), it is necessary to embed a target bytecode program in each service that processes the request, and intercept and capture the call relationship data of the service to which it belongs through the target bytecode program in each service, and send it to the call relationship service for summary statistics and analysis. In the case of counting the call relationship data of the entire link, the target bytecode program in each service also needs to specify an interceptor to capture the TraceID of the received call request. TraceID is a unique identifier for tracking requests in a distributed system, a number or string used to uniquely identify a request. A request in a microservice system may involve multiple service calls. Therefore, by capturing the TraceID of the call request received by each service, the call relationship data generated by the same request in the entire link can be distinguished through the TraceID in the call service request, so that the call relationship service can perform a full-link analysis for a request process.
[0100] Optionally, specify an interceptor to capture call relationship data, including:
[0101] The capture method is executed by the interceptor, and the load information of the node corresponding to the target service is obtained from the registration center according to the service name of the target service; wherein an instance of the target service is deployed in any node;
[0102] The load information of all nodes is sent to the call relationship service as call relationship data.
[0103] When the target service is called, the target bytecode program embedded in the target service is used to capture the call relationship data of the target service, and the captured call relationship data is sent to the call relationship service for statistics and analysis. In addition to the information carried by the call request, the call relationship data also includes the load status of each node providing the target service.
[0104] After the interceptor obtains the service name of the called service, it queries the registration center for the node information that provides the target service instance based on the service name, including the node address, the number of node calls, the node load information, etc. The target bytecode program also sends the obtained node load information of the target service to the call relationship service as call relationship data, so that the caller (front end or other service) can obtain the load status of each node that provides the target service instance when calling the target service, and then select the node with the lower current load to execute the service call according to the load balancing strategy.
[0105] Optionally, transmitting the call relationship data to a call relationship service includes:
[0106] By means of the target bytecode program, the call relationship data is sent to the call relationship service via the WebFlux asynchronous transmission mode;
[0107] Through the call relationship service, the received call relationship data is placed into the message queue using RocketMQ asynchronous processing;
[0108] The call relationship service processes the call relationship data by consuming the MQ message in the message queue.
[0109] In this embodiment, the developer modifies the target bytecode program, sets the sending interval of the call relationship data, and transmits the captured call relationship data to the call relationship service in real time. Optionally, it can also be set to transmit all the captured call relationship data to the call relationship service after the current service call ends (result data is returned).
[0110] When transmitting call relationship data, considering the huge number of services in the microservice system and the complex call relationship between services, since each service in the microservice system will send the call relationship data to the call relationship service, if the traditional synchronous blocking method is used to process parallel data, it will cause excessive pressure on the call relationship service. In order to alleviate the data processing pressure of the call relationship service, WebFlux and RocketMQ are combined in this embodiment to alleviate the concurrent processing pressure. WebFlux is the support of the Spring framework for responsive programming, which adapts to the requirements of high concurrency, high throughput and low latency. It can be directly nested in the code and uses asynchronous processing to receive concurrent data streams. RocketMQ is mainly used to store message queues inside the call relationship service. RocketMQ is a distributed message middleware with high performance, high reliability, high real-time and distributed characteristics. It uses MQ message queues to store call relationship data to be processed. When the call relationship service performs statistics and analysis on the call relationship data transmitted by each bytecode program, it is carried out in the form of MQ messages in the consumer message queue.
[0111] In this embodiment, two asynchronous processing technologies, WebFlux and RocketMQ, are used to cache the call relationship data to be processed, thereby achieving the purpose of alleviating the concurrent data processing pressure of the call relationship service.
[0112] In one embodiment, the call relationship service can implement multiple functions through plug-ins, and analyze and process the received call relationship data according to the needs of the actual application scenario. Furthermore, the result data obtained by the analysis can be connected to other applications or services through plug-ins, so that other applications or services can obtain the result data of the analysis in order to perform related operations. For example, the load status of each node instance of the target service is obtained, and the subsequent service calls are reasonably allocated based on this. It is worth noting that in this embodiment, the call relationship service combines with the plug-in to perform different types of statistics and analysis on a call relationship data, and then provide the required data support relationship data for multiple applications and services. Based on the statistical results of the call relationship data, the call relationship service can monitor and analyze the performance indicators (for example, service response time), error rate, etc. of the target service in real time, so as to timely discover potential problems and optimize them.
[0113] In one embodiment, before analyzing the call relationship data, the call relationship service first collects statistics on the call relationship data, and dynamically sets the statistical type according to different service types and subsequent application scenarios for analyzing the call relationship data, including service call time interval, call duration, call success rate, failure rate, etc. For example, for service A that needs to be called frequently during task execution, its call time interval is monitored; for service B with a lower call frequency, its call success rate and failure rate are monitored. For the call relationship statistics of the entire link, the statistics of the response time of each service in the call link can also be added as needed, so as to analyze the performance of each service and interface based on the statistical data, and provide basic data for subsequent system optimization.
[0114] In this embodiment, before performing call data analysis, call relationship data that does not need to be analyzed is filtered through data statistics operations, and only the call relationship data required for the specified service type or the current application scenario is counted, thereby saving statistics on call relationship data that does not need to be analyzed and saving bandwidth resources.
[0115] Optionally, after statistics and analysis are performed on the received call relationship data to obtain result data, the following further includes:
[0116] By calling the relationship service, storing the result data in a database;
[0117] Obtain result data from the database and push it visually through the calling relationship service;
[0118] Through the call relationship service, based on the business scenario of the current call target service, result data with a high call frequency is obtained from the database and cached.
[0119] In this embodiment, after the call relationship service performs statistics and analysis on the received call relationship data, the result data can be subsequently processed in a variety of ways. Optionally, the full-link call situation of the request is counted, and the statistical results are transmitted to the database for storage. According to the needs of the actual application, an OLAP (Online Analytical Processing) database or an OLTP (Online Transaction Processing) database can be selected to store the call relationship data.
[0120] Optionally, the statistical results and analysis results are pushed to the visual monitoring page for display. In this embodiment, the call relationship and call frequency statistics of the service can be pushed separately for visualization. The indicators of the call relationship between services and the data analysis results (for example, call success rate, call failure rate) can also be pushed. In addition, the call relationship service can be connected to an external monitoring system, and the statistical data and analysis results can be integrated into the visual large screen of the external monitoring system for display.
[0121] Optionally, for the call relationship data related to frequently called services, the statistical results or analysis results can be cached in the call relationship service so that the caller can quickly obtain them, thereby improving the service call efficiency.
[0122] Optionally, the bytecode-based microservice governance method is characterized by further comprising:
[0123] When the caller calls the target service through the gateway, the gateway queries the call relationship service for load information of all nodes of the target service, and dynamically adjusts the load rules of each node using a load balancing strategy;
[0124] In the case where the caller does not call the target service through the gateway, the call relationship service is queried for load information of all nodes of the target service through OpenFeign, and the load balancing strategy is used to dynamically adjust the load rules of each node.
[0125] In one embodiment, the result data (statistical data or analysis results) obtained by the call relationship service through statistics and analysis can be queried by the service caller. In the case where the caller is a third-party system or user end, the call to the target service will pass through the gateway layer.
[0126] Figure 4 Schematic diagram of the gateway dynamically adjusting the operation rules of calling the target service in one embodiment of the present application. Figure 4As shown, the gateway layer can obtain the node load information of the called service from the call relationship service, and adjust the load balancing, grayscale, current limiting and other operating rules when calling the target service based on the pre-set load balancing strategy (considering factors such as the node load rate and load range). When the call request passes through the gateway layer, the gateway will query the load of the target service through the call relationship service. The call relationship service can cache the call relationship data with higher access frequency in the current application scenario and send the call relationship data with lower access frequency to the database for caching. The gateway requests the call relationship service to query the node load information of the target service, and then dynamically adjusts the load rules, grayscale rules, current limiting rules and other operating rules of the third-party system or user end when calling the target service based on the node load information of the target service to avoid overloading of a single node. The gateway layer identifies services that have reached performance bottlenecks and services that need to increase or reduce load, so as to perform targeted optimization. In addition, the target service can also obtain the load information of each interface from the call relationship service, and dynamically adjust the current limiting rules of a single interface within the service.
[0127] When the caller is other services in the microservice system, the call to the target service does not need to go through the gateway layer. Other services make remote calls to the target service through OpenFeign, and can obtain the node load of the callee (target service) from the call relationship service through OpenFeign. Based on the pre-set load balancing strategy, adjust the gateway layer's load balancing strategy and grayscale strategy for the called service, and dynamically set the service-level current limiting rules.
[0128] In addition, call relationship data can also be used to adjust the system's fault tolerance mechanism. When a service call fails, the fault tolerance mechanism can automatically perform operations such as retry, fuse, or downgrade based on the call relationship data of the target service (including node load information) to ensure the stability of the entire microservice system. The fault tolerance mechanism can be deployed together with the load balancing strategy in the ingress gateway or OpenFeign.
[0129] Based on the same inventive concept, an embodiment of the present application provides a bytecode-based microservice management device. Figure 2 , Figure 2 1 is a schematic diagram of a bytecode-based microservice management device 100 proposed in one embodiment of the present application. Figure 2 As shown, the device comprises:
[0130] The embedding module 101 is configured to embed the target bytecode program generated based on the bytecode technology asm into the program of the target service; the target service is any service in the microservice system that needs to obtain call relationship data;
[0131] The interception module 102 is configured to intercept the call relationship data through the target bytecode program when the target service receives the call request; the call relationship data is the information of the caller calling the target service, and the caller is other services, a third-party system or a user end in the microservice system;
[0132] The transmission module 103 is configured to transmit the call relationship data to the call relationship service through the target bytecode program;
[0133] The processing module 104 is configured to perform statistics and analysis on the received call relationship data through the call relationship service to obtain result data;
[0134] The load adjustment module 105 is configured to adopt a load balancing strategy and determine a node for executing the call request of the target service based on the result data.
[0135] As an implementation manner of the present application, the embedded module 101 is configured to perform the following steps:
[0136] A target bytecode program is created by Byte Buddy bytecode technology, and is added to the Java virtual machine startup parameters of the target service in an agent manner, so that the target bytecode program runs before the program of the target service; the Byte Buddy bytecode technology is a bytecode generation solution based on the asm bytecode technology, and the Byte Buddy bytecode technology provides an API interface for quickly generating bytecode programs.
[0137] As an implementation manner of the present application, the interception module 102 is configured to perform the following steps:
[0138] When the Java virtual machine of the target service is started, premain is called as the entry function through Byte Buddy, and the target class that the target bytecode program needs to intercept is specified through AgentBuilder.Default(); the target class includes: a class annotated with @RestController and a class annotated with @Controller;
[0139] The call request received by the target service is intercepted through the AgentBuilder.Transformer instance, and the interface of each calling method is captured through method interception according to the annotations used by each interface of the target service, and the interceptor is specified to capture the call relationship data.
[0140] As an implementation manner of the present application, the interception module 102 is configured to specify an interceptor to capture call relationship data, specifically including:
[0141] The interceptor executes the capture method. Before the call relationship data is captured, ByteBuddy is informed to inject the original data to be captured into the interceptor through annotations; the annotations include: @RuntimeType, @This, @AllArguments, @Origin, @Super and @SuperCall;
[0142] The capture method is executed by the interceptor, the call request is obtained using the RequestContextHolder tool class, and the identifier of the caller is obtained from the request header; the identifier of the caller is any one of the following: a service name, an identifier of a third-party system, or an identifier of a user terminal;
[0143] Executing the fetching method through the interceptor to obtain the service name of the target service from the configuration center or local configuration file of the target service;
[0144] Executing the capture method through the interceptor, comparing the request path of the call request with the path of the target service, replacing the path parameters in the request path, and obtaining the calling mode of the call request;
[0145] The identifier of the caller, the service name of the target service, the request path and the calling method are used as calling relationship data.
[0146] As an implementation manner of the present application, the interception module 102 is configured to specify an interceptor to capture call relationship data, and further includes:
[0147] When obtaining the full-link call relationship of the call request, intercepting the call relationship data of the service to which the target bytecode program belongs through the target bytecode program in each service through which the call request passes;
[0148] When specifying an interceptor to capture the call relationship data, it also includes: executing a capture method through the interceptor to capture the TraceID of the call request received by the service.
[0149] As an implementation manner of the present application, the interception module 102 is configured to specify an interceptor to capture call relationship data, and further includes:
[0150] The capture method is executed by the interceptor, and the load information of the node corresponding to the target service is obtained from the registration center according to the service name of the target service; wherein an instance of the target service is deployed in any node;
[0151] The load information of all nodes is sent to the call relationship service as call relationship data.
[0152] As an implementation manner of the present application, the transmission module 103 is configured to perform the following steps:
[0153] By means of the target bytecode program, the call relationship data is sent to the call relationship service via the WebFlux asynchronous transmission mode;
[0154] Through the call relationship service, the received call relationship data is placed into the message queue using RocketMQ asynchronous processing;
[0155] The call relationship service processes the call relationship data by consuming the MQ message in the message queue.
[0156] As an implementation manner of the present application, the processing module 104 is configured to perform the following steps after performing statistics and analysis on the received call relationship data and obtaining result data:
[0157] By calling the relationship service, storing the result data in a database;
[0158] Obtain result data from the database and push it visually through the calling relationship service;
[0159] Through the call relationship service, based on the business scenario of the current call target service, result data with a high call frequency is obtained from the database and cached.
[0160] As an implementation manner of the present application, the load adjustment module 105 is further configured to perform the following steps:
[0161] When the caller calls the target service through the gateway, the gateway queries the call relationship service for load information of all nodes of the target service, and dynamically adjusts the load rules of each node using a load balancing strategy;
[0162] In the case where the caller does not call the target service through the gateway, the call relationship service is queried for load information of all nodes of the target service through OpenFeign, and the load balancing strategy is used to dynamically adjust the load rules of each node.
[0163] Based on the same inventive concept, an embodiment of the present application provides a readable storage medium on which a computer program is stored. When the program is executed by a processor, the steps in the bytecode-based microservice governance method as described in any of the above embodiments of the present application are implemented.
[0164] Based on the same inventive concept, an embodiment of the present application provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that when the processor executes the computer program, the steps of the bytecode-based microservice governance method described in any of the above embodiments are implemented.
[0165] Regarding the device in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.
[0166] The above description is only a preferred embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application should be included in the protection scope of the present application.
[0167] For the method embodiments, for the sake of simplicity, they are all described as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the order of the actions described, because according to the present application, some steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and components involved are not necessarily required by the present application.
[0168] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, devices, or computer program products. Therefore, the embodiments of the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the embodiments of the present application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.
[0169] The embodiments of the present application are described with reference to the flowcharts and / or block diagrams of the methods, terminal devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0170] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing terminal device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0171] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable terminal device to implement the process. Figure 1 A process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0172] Although the preferred embodiments of the present application have been described, those skilled in the art may make additional changes and modifications to these embodiments once they are aware of the basic creative concepts. Therefore, the present application is interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present application.
[0173] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or terminal device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or terminal device including the elements.
[0174] The above is a detailed introduction to the bytecode-based microservice governance method, device and product provided by the present application. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea; at the same time, for general technical personnel in this field, according to the idea of the present application, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
Claims
1. A bytecode-based microservice governance method, characterized in that: Applied to microservice systems, including: Embed the target bytecode program generated based on the bytecode technology asm into the program of the target service; the target service is any service in the microservice system that needs to obtain call relationship data; When the target service receives a call request, the call relationship data is intercepted by the target bytecode program; the call relationship data is information about the caller calling the target service, and the caller is other services, a third-party system or a user end in the microservice system; transmitting the call relation data to a call relation service through the target bytecode program; By using the call relationship service, statistics and analysis are performed on the received call relationship data to obtain result data; A load balancing strategy is adopted to determine a node for executing the call request of the target service based on the result data.
2. The bytecode-based microservice governance method according to claim 1, characterized in that: Embed the target bytecode program generated based on the bytecode technology asm into the target service program, including: A target bytecode program is created by Byte Buddy bytecode technology, and is added to the Java virtual machine startup parameters of the target service in an agent manner, so that the target bytecode program runs before the program of the target service; the Byte Buddy bytecode technology is a bytecode generation solution based on the asm bytecode technology, and the Byte Buddy bytecode technology provides an API interface for quickly generating bytecode programs.
3. The bytecode-based microservice governance method according to claim 1, characterized in that: Intercepting call relationship data through the target bytecode program includes: When the Java virtual machine of the target service is started, premain is called as the entry function through Byte Buddy, and the target class that the target bytecode program needs to intercept is specified through AgentBuilder.Default(); the target class includes: a class annotated with @RestController and a class annotated with @Controller; The call request received by the target service is intercepted through the AgentBuilder.Transformer instance, and the interface of each calling method is captured through method interception according to the annotations used by each interface of the target service, and the interceptor is specified to capture the call relationship data.
4. The bytecode-based microservice governance method according to claim 3 is characterized in that: Specify the interceptor to capture call relationship data, including: The interceptor executes the capture method. Before the call relationship data is captured, Byte Buddy is informed to inject the original data to be captured into the interceptor through annotations; the annotations include: @RuntimeType, @This, @AllArguments, @Origin, @Super and @SuperCall; The capture method is executed by the interceptor, the call request is obtained using the RequestContextHolder tool class, and the identifier of the caller is obtained from the request header; the identifier of the caller is any one of the following: a service name, an identifier of a third-party system, or an identifier of a user terminal; Executing the fetching method through the interceptor to obtain the service name of the target service from the configuration center or local configuration file of the target service; Executing the capture method through the interceptor, comparing the request path of the call request with the path of the target service, replacing the path parameters in the request path, and obtaining the calling mode of the call request; The identifier of the caller, the service name of the target service, the request path and the calling method are used as calling relationship data.
5. The bytecode-based microservice governance method according to claim 3, characterized in that: Specify the interceptor to capture call relationship data, including: When obtaining the full-link call relationship of the call request, intercepting the call relationship data of the service to which the target bytecode program belongs through the target bytecode program in each service through which the call request passes; When specifying an interceptor to capture the call relationship data, it also includes: executing a capture method through the interceptor to capture the TraceID of the call request received by the service.
6. The bytecode-based microservice governance method according to claim 4, characterized in that: Specify the interceptor to capture call relationship data, including: The capture method is executed by the interceptor, and the load information of the node corresponding to the target service is obtained from the registration center according to the service name of the target service; wherein an instance of the target service is deployed in any node; The load information of all nodes is sent to the call relationship service as call relationship data.
7. The bytecode-based microservice governance method according to claim 1, characterized in that: Transmitting the call relationship data to the call relationship service includes: By means of the target bytecode program, the call relationship data is sent to the call relationship service via the WebFlux asynchronous transmission mode; Through the call relationship service, the received call relationship data is placed into the message queue using RocketMQ asynchronous processing; The call relationship service processes the call relationship data by consuming the MQ message in the message queue.
8. The bytecode-based microservice governance method according to claim 1, characterized in that: After the received call relationship data is counted and analyzed to obtain the result data, it also includes: By calling the relationship service, storing the result data in a database; Obtain result data from the database and push it visually through the calling relationship service; Through the call relationship service, based on the business scenario of the current call target service, result data with a high call frequency is obtained from the database and cached.
9. The bytecode-based microservice governance method according to claim 6, characterized in that: Also includes: When the caller calls the target service through the gateway, the gateway queries the call relationship service for load information of all nodes of the target service, and dynamically adjusts the load rules of each node using a load balancing strategy; In the case where the caller does not call the target service through the gateway, the call relationship service is queried for load information of all nodes of the target service through OpenFeign, and the load balancing strategy is used to dynamically adjust the load rules of each node.
10. A bytecode-based microservice management device, characterized in that: The method for implementing any one of claims 1 to 9 comprises: The embedding module is configured to embed the target bytecode program generated based on the bytecode technology asm into the program of the target service; the target service is any service in the microservice system that needs to obtain call relationship data; An interception module is configured to intercept call relationship data through the target bytecode program when the target service receives a call request; the call relationship data is information about a caller calling the target service, and the caller is other services in the microservice system, a third-party system, or a user end; A transmission module, configured to transmit the call relationship data to a call relationship service through the target bytecode program; A processing module is configured to perform statistics and analysis on the received call relationship data through the call relationship service to obtain result data; The load adjustment module is configured to adopt a load balancing strategy and determine a node for executing the call request of the target service based on the result data.
11. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps in any one of the methods of claims 1-9 are implemented.
12. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 9 are implemented.
