Micro-service detection method and device, computing equipment, storage medium and program product
By performing syntax tree analysis on the microservice source code, inserting statistical code, generating image files, and collecting function call data, the problem of low efficiency in microservice activity detection in existing technologies is solved, and automated and accurate microservice activity detection is achieved.
Patent Information
- Application Number
- CN202410972305.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-18
- Publication Date
- 2024-11-05
AI Technical Summary
Existing methods for detecting microservice activity are inefficient, require manual analysis and trial and error, cannot be performed in batches, and cannot accurately identify inactive microservices.
By performing syntax tree analysis on the source code of microservices, an abstract syntax tree is generated. Preset statistical code is inserted into the functions to generate microservice image files, collect function call data, and analyze service activity to determine whether a microservice is the target microservice.
It achieves automated detection of microservice activity, improves detection efficiency, accurately identifies inactive microservices, and supports batch detection, reducing manual intervention.
Smart Images

Figure CN118897802A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of Internet technology, and specifically to a microservice detection method, apparatus, computing device, computer storage medium, and computer program product. Background Art
[0002] After a microservice is launched, it may have low service activity due to various reasons. The current method for detecting whether a microservice is a low-activity microservice is mainly for R&D personnel to add log code to the suspected code blocks, merge the code for online service release, observe whether logs appear, and determine whether the microservice is a low-activity microservice based on log analysis. This method requires manual time and effort to continuously analyze and try the internal behavior of the microservice, which is inefficient and cannot be performed in batches. Summary of the invention
[0003] In view of the above problems, the present application is proposed to provide a microservice detection method, apparatus, computing device, computer storage medium and computer program product that overcome the above problems or at least partially solve the above problems.
[0004] According to one aspect of the present application, a microservice detection method is provided, comprising:
[0005] Obtain the service source code of the microservice to be tested, perform syntax tree analysis on the source code, and generate the corresponding abstract syntax tree;
[0006] Traverse all functions in the abstract syntax tree, insert preset statistical codes into the functions, and generate microservice image files;
[0007] Obtain the function call data collected by the preset statistical code after the microservice image file is run online;
[0008] Analyze the function call data to determine the service activity of the microservice to be tested;
[0009] Determine whether the microservice to be detected is the target microservice based on the service activity.
[0010] Optionally, analyzing the function call data to determine the service activity of the microservice to be detected further includes:
[0011] The total amount of function call data is counted, and the service activity of the microservice to be tested is determined based on the total amount of data and the time window corresponding to the function call data.
[0012] Optionally, the method further includes: if it is determined that the microservice to be detected is not the target microservice, generating a function call relationship link tree diagram according to the function call relationship in the function call data;
[0013] Determine whether the function call is valid based on the function call relationship link tree diagram;
[0014] If it is determined that the function call is invalid, it is determined that the microservice to be detected is in an idle running state.
[0015] Optionally, the method also includes: after running on the microservice image file online, a preset statistical code collects the time when the current function is called, the function name of the current function, the code location of the current function, the package name of the current function, the function name of the upper-layer calling function, and the package name of the upper-layer calling function, and records it in the memory as a function call data.
[0016] Optionally, the preset statistical code includes data reporting logic, which specifies the unit time of data segmentation and the data reporting cycle;
[0017] The method further includes: a preset statistical code performs data segmentation on the function call data stored in the memory according to the unit time of data segmentation, and reports the function call data within the unit time to the remote service according to the data reporting cycle;
[0018] The function call data collected by the preset statistical code after obtaining the microservice image file online further includes:
[0019] The remote service obtains the function call data per unit time reported by the preset statistical code.
[0020] Optionally, judging whether the microservice to be detected is a target microservice according to the service activity further includes:
[0021] Determine whether the service activity is less than a preset service activity threshold;
[0022] If yes, the microservice to be detected is determined as the target microservice.
[0023] Optionally, the method further includes: if it is determined that the microservice to be detected is a target microservice, taking the microservice to be detected offline or reducing its capacity.
[0024] According to another aspect of the present application, a microservice detection device is provided, including:
[0025] The first generation module is adapted to obtain the service source code of the microservice to be detected, perform syntax tree analysis on the source code, and generate a corresponding abstract syntax tree;
[0026] Insertion module, suitable for traversing all functions of the abstract syntax tree, inserting preset statistical codes into the functions, and generating microservice image files;
[0027] An acquisition module is used to obtain function call data collected by a preset statistical code after the microservice image file is run online;
[0028] An analysis module, suitable for analyzing function call data to determine the service activity of the microservice to be detected;
[0029] The first judgment module is adapted to judge whether the microservice to be detected is a target microservice according to the service activity.
[0030] According to another aspect of the present application, there is provided a computing device, comprising: a processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface communicate with each other via the communication bus;
[0031] The memory is used to store at least one executable instruction, and the executable instruction enables the processor to execute operations corresponding to the above-mentioned microservice detection method.
[0032] According to another aspect of the present application, a computer storage medium is provided, in which at least one executable instruction is stored, and the executable instruction enables a processor to perform operations corresponding to the above-mentioned microservice detection method.
[0033] According to another aspect of the present application, a computer program product is provided, comprising at least one executable instruction, wherein the executable instruction enables a processor to perform operations corresponding to the above-mentioned microservice detection method.
[0034] According to the microservice detection method, apparatus, computing device, computer storage medium, and computer program product provided in the embodiments of the present application, automated processing is achieved by inserting preset statistical codes into the function. There is no need for manual time and effort to continuously analyze and try the internal behavior of the microservice. It is possible to accurately detect whether a microservice is a target microservice without calling the microservice type, thereby improving detection efficiency and enabling batch detection.
[0035] The above description is only an overview of the technical solution of the present application. In order to more clearly understand the technical means of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] Various other advantages and benefits will become apparent to those of ordinary skill in the art by reading the detailed description of the preferred embodiments below. The accompanying drawings are only for the purpose of illustrating the preferred embodiments and are not to be considered as limiting the present application. Also, the same reference symbols are used throughout the accompanying drawings to represent the same components. In the accompanying drawings:
[0037] Figure 1 A schematic diagram of a process of a microservice detection method according to an embodiment of the present application is shown;
[0038] Figure 2A A schematic diagram of a process of a microservice detection method according to another embodiment of the present application is shown;
[0039] Figure 2B Statistical heat map for total amount;
[0040] Figure 2C Pie charts for function dimension statistics;
[0041] Figure 2D It is a function call relationship chain tree diagram;
[0042] Figure 3 A schematic diagram of the preset statistical code processing flow after the preset statistical code is inserted;
[0043] Figure 4 A schematic diagram of the structure of a microservice detection device according to an embodiment of the present application is shown;
[0044] Figure 5 A schematic diagram of the structure of a computing device according to an embodiment of the present application is shown. DETAILED DESCRIPTION
[0045] The exemplary embodiments of the present application will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present application are shown in the accompanying drawings, it should be understood that the present application can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided in order to enable a more thorough understanding of the present application and to fully convey the scope of the present application to those skilled in the art.
[0046] First, the terms involved in one or more embodiments of the present application are explained.
[0047] Syntax Tree: Syntax Tree, also known as Parse Tree, is a structure in computer science and linguistics that is used to represent the grammatical structure of a programming language or natural language sentence. The syntax tree shows the components of a sentence and their hierarchical relationships through a tree structure.
[0048] Microservices: Microservices is a software architecture style that decomposes a large single application into a set of small, loosely coupled, independently deployed services. These services are responsible for specific business functions and collaborate with each other through lightweight communication mechanisms (http or grpc and other rpc protocols).
[0049] Figure 1 FIG. 1 is a flow chart of a microservice detection method according to an embodiment of the present application. Figure 1 As shown, the method comprises the following steps:
[0050] Step S101, obtaining the service source code of the microservice to be detected, performing syntax tree analysis on the source code, and generating a corresponding abstract syntax tree.
[0051] When there is a need for microservice detection, the service source code of the corresponding microservice can be obtained. In order to realize automatic microservice detection without adjusting the microservice type, this embodiment generates a corresponding abstract syntax tree by performing syntax tree analysis on the source code, which mainly includes lexical analysis and syntax analysis. Each node of the abstract syntax tree represents a grammatical structure in the source code, such as a function. The structure of the tree intuitively reflects the nested hierarchy and composition relationship of the source code.
[0052] Step S102, traverse all functions of the abstract syntax tree, insert preset statistical codes into the functions, and generate a microservice image file.
[0053] In order to accurately detect whether the microservice to be detected is the target microservice, it is necessary to traverse all functions of the abstract syntax tree. For example, the abstract syntax tree can be traversed using depth-first search (DFS) or breadth-first search (BFS), and a preset statistical code is inserted into each traversed function, for example, the preset statistical code is inserted at the beginning of each function. After inserting the preset statistical code, a new executable microservice image file is generated according to the inserted code, wherein the microservice image file does not modify any business code logic.
[0054] After generating the microservice image file corresponding to the microservice to be tested, the microservice image file is released and deployed to the online environment to accept online traffic. As the traffic enters the microservice, the functions in the microservice begin to be called, and the embedded preset statistical code begins to collect function call data.
[0055] Step S103, obtaining function call data collected by a preset statistical code after the microservice image file is run online.
[0056] This application mainly analyzes and determines whether the microservice to be detected is the target microservice based on the function call data collected by the preset statistical code. Therefore, it is necessary to first obtain the function call data collected by the preset statistical code after the microservice image file is run online, where the function call data is the data generated when the function within the microservice is called.
[0057] Step S104: Analyze the function call data to determine the service activity of the microservice to be detected.
[0058] After obtaining the function call data, the function call data can be analyzed to determine the service activity of the microservice to be detected. For example, the mapping relationship between the function call data, the system resource usage and the service activity can be pre-set. After obtaining the function call data, the system resource usage of the microservice to be detected can be determined, so as to determine the service activity. Among them, the service activity reflects the degree of service usage and operation status.
[0059] Step S105: determine whether the microservice to be detected is a target microservice according to the service activity.
[0060] Among them, the target microservice refers to a microservice with low activity, so the target microservice can also be called a low-activity microservice. Therefore, after determining the service activity of the microservice to be detected, it can be determined whether the microservice to be detected is the target microservice according to the service activity, that is, whether the microservice to be detected is a low-activity microservice.
[0061] In summary, according to the method provided in this embodiment, by inserting preset statistical codes in the function, automated processing is achieved, and there is no need for manual time and energy to continuously analyze and try the internal behavior of the microservice. It can accurately detect whether a microservice is the target microservice without calling the microservice type, thereby improving detection efficiency and realizing batch detection.
[0062] Figure 2A FIG. 2 shows a flow chart of a microservice detection method according to another embodiment of the present application. Figure 2A As shown, the method comprises the following steps:
[0063] Step S201, obtain the service source code of the microservice to be detected, perform syntax tree analysis on the source code, and generate a corresponding abstract syntax tree.
[0064] When there is a need for microservice detection, the service source code of the corresponding microservice can be obtained. In order to realize automatic microservice detection without adjusting the microservice type, this embodiment generates a corresponding abstract syntax tree by performing syntax tree analysis on the source code, which mainly includes lexical analysis and syntax analysis. Each node of the abstract syntax tree represents a grammatical structure in the source code, such as a function. The structure of the tree intuitively reflects the nested hierarchy and composition relationship of the source code. Among them, the root node is the initial startup entry function of each microservice to be detected, and the child node is the child function. Usually, other functions are called inside a function, which is similar to a tree.
[0065] Step S202, traverse all functions of the abstract syntax tree, insert preset statistical codes into the functions, and generate a microservice image file.
[0066] In order to accurately detect whether the microservice to be detected is the target microservice, it is necessary to traverse all functions of the abstract syntax tree. For example, the abstract syntax tree can be traversed using depth-first search (DFS) or breadth-first search (BFS), and a preset statistical code is inserted into each traversed function, for example, the preset statistical code is inserted at the beginning of each function. After inserting the preset statistical code, a new executable microservice image file is generated according to the inserted code, wherein the microservice image file does not modify any business code logic.
[0067] After generating the microservice image file corresponding to the microservice to be tested, publish the microservice image file and deploy it to the online environment.
[0068] Step S203, after the microservice image file is run online, the preset statistical code collects the time when the current function is called, the function name of the current function, the code location of the current function, the package name of the current function, the function name of the upper-layer calling function, and the package name of the upper-layer calling function, and records it in the memory as a function call data.
[0069] After the microservice image file is deployed to the online environment, it will receive online traffic. As the traffic enters the microservice, the functions in the microservice begin to be called, and the embedded preset statistical code begins to collect function call data. Specifically, the preset statistical code collects the current function call time, the function name of the current function, the code location of the current function, the package name of the current function, the function name of the upper-layer calling function, and the package name of the upper-layer calling function, where the upper-layer calling function refers to which function calls the current function. The above data obtained will be recorded in the memory as a function call data.
[0070] In actual applications, a function is called by one request, and there may be multiple requests online at the same time. All the same functions will be called repeatedly in each cycle, so the same information may exist. That is, the time when the current function is called, the function name of the current function, the code location of the current function, the package name of the current function, the function name of the upper-level calling function, and the package name of the upper-level calling function may exist multiple times at the same time. Therefore, the same function call data will be accumulated and stored in the memory. That is to say, the data volume corresponding to the same function call data will be recorded in the memory.
[0071] Step S204, obtaining function call data collected by a preset statistical code after the microservice image file is run online.
[0072] This application mainly analyzes and determines whether the microservice to be detected is the target microservice based on the function call data collected by the preset statistical code. Therefore, it is necessary to first obtain the function call data collected by the preset statistical code after the microservice image file is run online, wherein the function call data is the data generated when the function in the microservice is called. For example, the function call data can be obtained from the memory.
[0073] The unit time of the function call data obtained each time can also be pre-specified, so that the time interval within which the function call data needs to be obtained can be determined according to the unit time, and the function call data within the unit time can be obtained from the memory according to the current function call time.
[0074] Step S205 , counting the total amount of function call data, and determining the service activity of the microservice to be detected according to the total amount of data and the time window corresponding to the function call data.
[0075] The total amount of the acquired function call data is counted, and the function call frequency can be determined in combination with the time window of the acquired function call data. The function call frequency reflects the service activity of the microservice to be detected.
[0076] In actual applications, the total amount statistical heat map and function dimension statistical pie chart can be generated by combining the unit time or the time window of the obtained function call data, and displayed to the processing end. Through the visual display, it is convenient for the processing end to analyze and determine whether the microservice to be detected is the target microservice. Taking the unit time as 1 day as an example, the corresponding total amount statistical heat map is as follows: Figure 2B As shown, the function dimension statistics pie chart is as follows Figure 2C shown.
[0077] Step S206, determine whether the service activity is less than a preset service activity threshold; if so, execute step S207; if not, execute step S208.
[0078] Specifically, a threshold of service activity is set according to the business needs of the microservice. When the service activity is lower than the threshold, the microservice is considered inactive or low-active. Therefore, after determining the service activity of the microservice to be detected, the service activity of the microservice to be detected is compared with the preset service activity threshold. If the service activity is less than the preset service activity threshold, the microservice to be detected can be determined as the target microservice; if the service activity is greater than or equal to the preset service activity threshold, it can be further determined whether the microservice to be detected has an idle run.
[0079] Step S207: determine the microservice to be detected as the target microservice, and jump to step S211.
[0080] If the service activity is less than the preset service activity threshold, it can be determined that the microservice to be detected is a target microservice, that is, a low-activity microservice, and then the process jumps to step S211.
[0081] Step S208, generating a function call relationship link tree diagram according to the function call relationship in the function call data.
[0082] The function call data contains the information of the upper-level calling function. Therefore, a function call relationship chain tree diagram can be generated according to the function call relationship. The function call relationship chain tree diagram summarizes the call relationship between all functions, such as Figure 2D As shown, it should be noted that Figure 2D Only some functions are listed schematically. There may be more layers of function calls in the future, which are not shown here. The root node root in the function call relationship chain tree diagram is the starting entry function of the microservice operation, and then a function will call other functions. Usually, the function close to the root node is the entry of the interface function, or the entry of the consumer function, or the entry of the task function.
[0083] It should be noted that, in this embodiment, step S205 and step S208 may be executed simultaneously, or step S205 may be executed first, then step S208, and then step S206. If it is determined that the service activity is greater than or equal to the preset service activity threshold, step S209 is executed.
[0084] Step S209, judging whether the function call is valid according to the function call relationship link tree diagram, if not, executing step S210.
[0085] In actual applications, the business functions of a microservice may be offline, but the interface of the microservice may not be offline due to being forgotten, and some users continue to call the interface function by grabbing the interface. The preset statistical code will count the number of calls to these interface functions online. The calls of these functions will be considered meaningless, which may cause the microservice to run in vain. In addition, task functions generally run periodically and generate data for interface function calls. If only the task function is running, but no interface function calls use this data, it also means that the task is running in vain. Therefore, the function call relationship link tree diagram can be used to determine whether the function call is valid. For example, the function call relationship The link tree diagram determines the interface function and / or task function close to the root node, and then identifies whether the function call is valid based on the business function status of the microservice and the function call data corresponding to the interface function, and / or determines whether the task function is called by the interface function, and determines whether the function call is valid based on the identification result, wherein a valid function call means that the business function of the microservice is in an online running state and the interface function has corresponding function call data, or the data generated by the task function is used by the interface function call; an invalid function call means that the business function of the microservice is in an offline state but the interface function has corresponding function call data, or the data generated by the task function is not used by the interface function call.
[0086] Step S210: determine that the microservice to be detected is in an idle running state, and jump to step S211.
[0087] If it is determined that the function call is invalid, it can be determined that the microservice to be detected is in an idle state, and the corresponding detection result can be output. For example, the detection result is that the microservice to be detected is in an idle state and displayed to the processing end, so as to facilitate the processing end to drill down and analyze the operation status of the microservice.
[0088] Step S211: offline the microservice to be detected.
[0089] When it is determined that the microservice to be detected is the target microservice or the microservice to be detected is in an idle state, the microservice to be detected can be taken offline.
[0090] In an optional implementation, if the microservice to be detected is determined to be a target microservice, the microservice to be detected may also be scaled down, for example, by dynamically reducing the number of service instances or lowering resource specifications of the service instances.
[0091] In an optional implementation, the preset statistical code includes data reporting logic, which specifies the unit time of data segmentation and the data reporting period, wherein the unit time of data segmentation can be 1 day, 1 hour or 1 minute, etc., and the data reporting period can be once every 2 minutes, once every day, etc., and technical personnel in this field can set it according to actual needs.
[0092] Therefore, the preset statistical code can perform data segmentation on the function call data stored in the memory according to the unit time of data segmentation, and report the function call data within the unit time to the remote service according to the data reporting cycle;
[0093] Obtaining the function call data collected by the preset statistical code after the microservice image file is run online can be further achieved by the following method: remote service obtains the function call data within a unit time reported by the preset statistical code.
[0094] After receiving the reported function call data, the remote service analyzes the function call data in the background, determines the function call frequency and the function call relationship link tree diagram, and stores the function call frequency and the function call relationship link tree diagram persistently, for example, in a database.
[0095] In an optional implementation, a microservice with very low total amount of function call data belongs to some edge services, and the total amount of function call data of the active microservice differs by at least two data levels. Therefore, the total amount of function call data of the microservice to be detected can be compared with the total amount of function call data of known active microservices (non-target microservices) to determine whether the microservice to be detected is a target microservice.
[0096] In summary, according to the method provided in this embodiment, by inserting preset statistical codes in the function, automated processing is achieved, and there is no need for manual time and energy to continuously analyze and try the internal behavior of the microservice. It can accurately detect whether a microservice is the target microservice without calling the microservice type, thereby improving the detection efficiency and realizing batch detection. When the function call data collected by the preset statistical code is used to analyze that a microservice is not the target microservice, further analysis is performed based on the generated function call relationship link tree diagram to determine whether the microservice is running empty, and the microservice is effectively managed based on the results.
[0097] Figure 3 This is a schematic diagram of the preset statistical code processing flow after the preset statistical code is inserted, such as Figure 3As shown, the business layer includes various business microservices. For a certain business microservice, a preset statistical code is inserted into function 1-function n of the business microservice, and the function call data is counted using the preset statistical code and put into the asynchronous queue. The asynchronous queue receives the function call data from the business layer and processes it in a certain order. The same function call data in the queue will go through a series of accumulation operations to finally obtain the information of each function. The function call data will record the function call time. Therefore, the function call data can be periodically aggregated in combination with the function call time and then stored in the memory. Once the stop signal is received, the accumulation operation will stop and the accumulated results will be reported to the remote service.
[0098] Figure 4 FIG. 1 shows a schematic diagram of the structure of a microservice detection device according to an embodiment of the present application. Figure 4 As shown, the device comprises:
[0099] The first generation module 401 is adapted to obtain the service source code of the microservice to be detected, perform syntax tree analysis on the source code, and generate a corresponding abstract syntax tree;
[0100] Insertion module 402, adapted to traverse all functions of the abstract syntax tree, insert preset statistical codes into the functions, and generate a microservice image file;
[0101] An acquisition module 403 is adapted to acquire function call data collected by a preset statistical code after the microservice image file is run online;
[0102] An analysis module 404 is adapted to analyze the function call data to determine the service activity of the microservice to be detected;
[0103] The first judgment module 405 is adapted to judge whether the microservice to be detected is a target microservice according to the service activity.
[0104] Optionally, the analysis module is further adapted to: count the total amount of function call data, and determine the service activity of the microservice to be detected according to the total amount of data and the time window corresponding to the function call data.
[0105] Optionally, the device further comprises: a second generating module adapted to generate a function call relationship link tree diagram according to the function call relationship in the function call data if it is determined that the microservice to be detected is not the target microservice;
[0106] A second judgment module is adapted to judge whether a function call is valid according to a function call relationship link tree diagram;
[0107] The determination module is adapted to determine that the microservice to be detected is in an idle running state if it is determined that the function call is invalid.
[0108] Optionally, the device also includes: a statistical module, which is suitable for collecting the current function call time, the function name of the current function, the code location of the current function, the package name of the current function, the function name of the upper-layer calling function, and the package name of the upper-layer calling function through preset statistical codes after running on the microservice image file online, and recording it in the memory as a function call data.
[0109] Optionally, the preset statistical code includes data reporting logic, which specifies the unit time of data segmentation and the data reporting cycle;
[0110] The statistics module is adapted to perform data segmentation on the function call data stored in the memory according to the unit time of data segmentation by presetting the statistics code, and report the function call data within the unit time to the module for remote service according to the data reporting cycle;
[0111] The function call data collected by the preset statistical code after obtaining the microservice image file online further includes:
[0112] The device also includes: a module for remote service, suitable for obtaining function call data within a unit time reported by a preset statistical code.
[0113] Optionally, the first judgment module is further adapted to: judge whether the service activity is less than a preset service activity threshold;
[0114] If yes, the microservice to be detected is determined as the target microservice.
[0115] Optionally, the device further includes: a processing module, adapted to, if it is determined that the microservice to be detected is a target microservice, perform offline processing or capacity reduction processing on the microservice to be detected.
[0116] In summary, according to the device provided in this embodiment, automatic processing is achieved by inserting preset statistical codes in the function. There is no need for manual time and energy to continuously analyze and try the internal behavior of the microservice. It can accurately detect whether a microservice is a target microservice without calling the microservice type, thereby improving detection efficiency and realizing batch detection.
[0117] An embodiment of the present application provides a non-volatile computer storage medium, which stores at least one executable instruction or computer program, which enables a processor to perform operations corresponding to the microservice detection method in any of the above method embodiments.
[0118] An embodiment of the present application provides a computer program product, which includes at least one executable instruction or computer program, which can enable a processor to perform operations corresponding to the microservice detection method in any of the above method embodiments.
[0119] Figure 5 A schematic diagram of the structure of an embodiment of a computing device of the present application is shown. The specific embodiment of the present application does not limit the specific implementation of the computing device.
[0120] like Figure 5 As shown, the computing device may include: a processor (processor) 502 , a communications interface (Communications Interface) 504 , a memory (memory) 506 , and a communication bus 508 .
[0121] The processor 502, the communication interface 504, and the memory 506 communicate with each other via the communication bus 508. The communication interface 504 is used to communicate with other devices such as a client or other server network elements. The processor 502 is used to execute the program 510, which can specifically execute the relevant steps in the above-mentioned microservice detection method embodiment for a computing device.
[0122] Specifically, the program 510 may include program codes, which include computer operation instructions.
[0123] The processor 502 may be a central processing unit (CPU), or an application-specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of the present application. The one or more processors included in the computing device may be processors of the same type, such as one or more CPUs; or may be processors of different types, such as one or more CPUs and one or more ASICs.
[0124] The memory 506 is used to store the program 510. The memory 506 may include a high-speed RAM memory, and may also include a non-volatile memory (non-volatile memory), such as at least one disk memory.
[0125] The program 510 can be specifically used to enable the processor 502 to execute the microservice detection method in any of the above-mentioned method embodiments. The specific implementation of each step in the program 510 can refer to the corresponding description in the corresponding steps and units in the above-mentioned microservice detection embodiment, which will not be repeated here. Those skilled in the art can clearly understand that for the convenience and simplicity of description, the specific working process of the above-described devices and modules can refer to the corresponding process description in the above-mentioned method embodiment, which will not be repeated here.
[0126] The algorithm or display provided here are not inherently related to any specific computer, virtual system or other equipment. Various general systems can also be used together with the teaching based on this. According to the above description, it is obvious to construct the structure required for this type of system. In addition, the present application embodiment is not directed to any specific programming language yet. It should be understood that various programming languages can be utilized to realize the content of the present application described here, and the above description of specific languages is to disclose the best mode of implementation of the present application.
[0127] In the description provided herein, a large number of specific details are described. However, it is understood that the embodiments of the present application can be practiced without these specific details. In some instances, well-known methods, structures and techniques are not shown in detail so as not to obscure the understanding of this description.
[0128] Similarly, it should be understood that in order to streamline the present application and help understand one or more of the various inventive aspects, in the above description of the exemplary embodiments of the present application, the various features of the embodiments of the present application are sometimes grouped together into a single embodiment, figure, or description thereof. However, the disclosed method should not be interpreted as reflecting the following intention: the claimed application requires more features than the features clearly stated in each claim. More specifically, as reflected in the claims below, the inventive aspects are less than all the features of the single embodiment disclosed above. Therefore, the claims following the specific embodiment are hereby expressly incorporated into the specific embodiment, wherein each claim itself serves as a separate embodiment of the present application.
[0129] Those skilled in the art will appreciate that the modules in the devices in the embodiments may be adaptively changed and arranged in one or more devices different from the embodiments. The modules or units or components in the embodiments may be combined into one module or unit or component, and in addition they may be divided into a plurality of submodules or subunits or subcomponents. Except that at least some of such features and / or processes or units are mutually exclusive, all features disclosed in this specification (including the accompanying claims, abstracts and drawings) and all processes or units of any method or device disclosed in this manner may be combined in any combination. Unless otherwise expressly stated, each feature disclosed in this specification (including the accompanying claims, abstracts and drawings) may be replaced by an alternative feature providing the same, equivalent or similar purpose.
[0130] In addition, those skilled in the art will appreciate that, although some embodiments herein include certain features included in other embodiments but not other features, the combination of features of different embodiments is meant to be within the scope of the present application and form different embodiments. For example, in the claims below, any one of the claimed embodiments may be used in any combination.
[0131] The various component embodiments of the present application can be implemented in hardware, or in software modules running on one or more processors, or in a combination thereof. It should be understood by those skilled in the art that a microprocessor or digital signal processor (DSP) can be used in practice to implement some or all functions of some or all components according to the embodiments of the present application. The application can also be implemented as a device or apparatus program (e.g., computer program and computer program product) for executing a part or all of the methods described herein. Such a program implementing the present application can be stored on a computer-readable medium, or can have the form of one or more signals. Such a signal can be downloaded from an Internet website, or provided on a carrier signal, or provided in any other form.
[0132] It should be noted that the above embodiments illustrate the present application rather than limit the present application, and that those skilled in the art may design alternative embodiments without departing from the scope of the appended claims. In the claims, any reference symbol between brackets shall not be constructed as a limitation on the claims. The word "comprising" does not exclude the presence of elements or steps not listed in the claims. The word "one" or "an" preceding an element does not exclude the presence of multiple such elements. The present application may be implemented by means of hardware including several different elements and by means of a suitably programmed computer. In a unit claim that lists several devices, several of these devices may be embodied by the same hardware item. The use of the words first, second, and third, etc. does not indicate any order. These words may be interpreted as names. The steps in the above embodiments, unless otherwise specified, should not be understood as limitations on the order of execution.
Claims
1. A microservice detection method, comprising: Obtain the service source code of the microservice to be tested, perform syntax tree analysis on the source code, and generate a corresponding abstract syntax tree; Traversing all functions of the abstract syntax tree, inserting preset statistical codes into the functions, and generating a microservice image file; Obtaining function call data collected by the preset statistical code after the microservice image file is run online; Analyze the function call data to determine the service activity of the microservice to be detected; It is determined whether the microservice to be detected is a target microservice according to the service activity.
2. The method according to claim 1, wherein: The analyzing the function call data to determine the service activity of the microservice to be detected further includes: The total amount of the function call data is counted, and the service activity of the microservice to be detected is determined according to the total amount of data and the time window corresponding to the function call data.
3. The method according to claim 1 or 2, wherein: The method further includes: if it is determined that the microservice to be detected is not a target microservice, generating a function call relationship link tree diagram according to the function call relationship in the function call data; Determine whether the function call is valid according to the function call relationship link tree diagram; If it is determined that the function call is invalid, it is determined that the microservice to be detected is in an idle running state.
4. The method according to any one of claims 1 to 3, wherein: The method also includes: after the microservice image file is run online, the preset statistical code collects the time when the current function is called, the function name of the current function, the code location of the current function, the package name of the current function, the function name of the upper-layer calling function, and the package name of the upper-layer calling function, and records it in the memory as a function call data.
5. The method according to claim 4, wherein: The preset statistical code includes data reporting logic, which specifies the unit time of data segmentation and the data reporting cycle; The method further includes: the preset statistical code performs data segmentation on the function call data stored in the memory according to the unit time of the data segmentation, and reports the function call data within the unit time to the remote service according to the data reporting cycle; The obtaining of the function call data collected by the preset statistical code after the microservice image file is run online further includes: The remote service obtains the function call data within a unit time reported by the preset statistical code.
6. The method according to any one of claims 1 to 5, wherein: Judging whether the microservice to be detected is a target microservice according to the service activity further includes: Determining whether the service activity is less than a preset service activity threshold; If yes, the microservice to be detected is determined as the target microservice.
7. The method according to any one of claims 1 to 6, wherein: The method further includes: if it is determined that the microservice to be detected is a target microservice, offline processing or capacity reduction processing is performed on the microservice to be detected.
8. A microservice detection device, comprising: A first generation module is adapted to obtain a service source code of a microservice to be detected, perform syntax tree analysis on the source code, and generate a corresponding abstract syntax tree; An insertion module, adapted to traverse all functions of the abstract syntax tree, insert preset statistical codes into the functions, and generate a microservice image file; An acquisition module, adapted to acquire function call data collected by the preset statistical code after the microservice image file is run online; An analysis module, adapted to analyze the function call data to determine the service activity of the microservice to be detected; The first judgment module is adapted to judge whether the microservice to be detected is a target microservice according to the service activity.
9. A computing device comprising: A processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface communicate with each other via the communication bus; The memory is used to store at least one executable instruction, and the executable instruction enables the processor to perform an operation corresponding to the microservice detection method according to any one of claims 1 to 7.
10. A computer storage medium, wherein at least one executable instruction is stored in the storage medium, and the executable instruction enables a processor to perform operations corresponding to the microservice detection method according to any one of claims 1 to 7.
11. A computer program product, comprising at least one executable instruction, wherein the executable instruction enables a processor to perform operations corresponding to the microservice detection method according to any one of claims 1 to 7.
Citation Information
Cited By
Method for detecting destructive change of gRPC interface under micro-service architecture
CN119415408A
