A method for detecting destructive changes to gRPC interfaces in a microservice architecture
By automatically scanning and analyzing microservice source code, we identify destructive changes in the gRPC interface, solving the problem of time-consuming and error-prone manual detection, and achieving efficient and accurate interface change detection and dependency analysis.
Patent Information
- Application Number
- CN202510020899.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-07
- Publication Date
- 2025-04-29
- Estimated Expiration
- 2045-01-07
AI Technical Summary
In microservice architectures, manually writing automated test scripts to detect destructive changes to gRPC interfaces is time-consuming and error-prone, especially when the number of microservices is huge, tracking interface dependencies becomes complicated.
By automatically scanning the source code and analyzing the gRPC interface definition information, an abstract syntax tree is built, matching method declaration and call information, identifying destructive changes, and generating a gRPC interface dependency diagram.
It realizes automatic detection of destructive changes in the gRPC interface, reduces manual maintenance workload, improves detection efficiency and accuracy, and ensures that the potential impact range can be quickly identified after the interface is modified.
Smart Images

Figure CN119415408B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer application technology, and in particular to a gRPC interface destructive change detection method under a microservice architecture. Background Art
[0002] In a microservice architecture, multiple microservices rely on each other and collaborate to achieve complete functionality, forming complex dependencies between these services. When microservices use gRPC as a data interaction protocol, efficient and reliable communication can be achieved. However, when there are many microservices in the system, the dependencies between them become extremely complex. When gRPC interfaces are implemented in different microservices, changes to the interfaces, especially destructive changes, must accurately inform developers which microservices depend on the interface. When the system is built, it should be able to automatically identify which gRPC interfaces have undergone destructive changes, and clearly indicate whether these interfaces are called by microservices that have not been updated to the latest version.
[0003] In the existing microservice architecture development, especially in the writing of automated test scripts, the following technical problems often occur:
[0004] Existing testing solutions usually rely on manually written automated test scripts to simulate and collect the calling relationships between gRPC interfaces. For complex microservice systems with a large number of gRPC interfaces, manually collecting and maintaining the calling relationships of these interfaces is time-consuming and error-prone. Especially when the number of microservices is large, tracking the dependencies between gRPC interfaces becomes particularly complicated. Summary of the invention
[0005] The summary of the invention is used to introduce concepts in a brief form, which will be described in detail in the detailed implementation section below. The summary of the invention is not intended to identify the key features or essential features of the technical solution claimed for protection, nor is it intended to limit the scope of the technical solution claimed for protection.
[0006] The present invention proposes a gRPC interface destructive change detection method under a microservice architecture to solve one or more of the technical problems mentioned in the above background technology part.
[0007] The present invention provides a method for detecting destructive changes of a gRPC interface under a microservice architecture, comprising: obtaining a gRPC interface definition information file according to a configuration file, wherein the gRPC interface definition information file includes a gRPC interface definition source code;
[0008] Parse the gRPC interface definition source code to obtain the gRPC interface declaration information, and obtain the gRPC interface definition information from the gRPC interface declaration information;
[0009] According to the configuration file, the source code of each sub-service of the microservice included in the product package to be detected and the multiple sub-services included in the microservice is obtained to obtain a source code group;
[0010] Parsing multiple source codes in the source code group, constructing an abstract syntax tree corresponding to each source code in the multiple source codes, and obtaining multiple abstract syntax trees, each of the multiple abstract syntax trees including multiple method information, the multiple method information including multiple method declaration information and multiple method call information;
[0011] Traversing multiple abstract syntax trees, matching multiple method declaration information with gRPC interface definition information, determining the successfully matched method declaration information as the gRPC interface implementation information, and obtaining the gRPC interface implementation information group;
[0012] Traversing multiple abstract syntax trees, matching multiple method call information with gRPC interface definition information, determining the successfully matched method call information as the gRPC interface call information, and obtaining the gRPC interface call information group;
[0013] The method information corresponding to each implementation gRPC interface information in the implementation gRPC interface information group is matched with the method information corresponding to each call gRPC interface information in the call gRPC interface information group to determine whether the method corresponding to each method information has a destructive change, and the gRPC interface corresponding to the method that has a destructive change and is called is determined as the gRPC interface affected by the destructive change, to obtain the destructive change gRPC interface group.
[0014] Optionally, each method information in the multiple abstract syntax trees includes a method name, method parameters, and a return type.
[0015] Optionally, matching method information corresponding to each gRPC interface implementation information in the gRPC interface implementation information group with method information corresponding to each gRPC interface call information in the gRPC interface call information group includes:
[0016] Match the method name of the method information corresponding to the gRPC interface information with the method name of the gRPC interface definition information; or
[0017] Match the method parameters of the method information corresponding to the gRPC interface information with the method parameters of the gRPC interface definition information; or
[0018] Match the return type of the method information corresponding to the gRPC interface information with the return type of the gRPC interface definition information.
[0019] Optionally, each gRPC interface call information in the gRPC interface call information group is identified to determine whether the gRPC interface call information is called by the microservice, including:
[0020] Each call gRPC interface information in the call gRPC interface information group is matched with each method call information in multiple abstract syntax trees. If the call gRPC interface information matches the method call information successfully, it is determined that a call relationship exists between the gRPC interface information, and the call relationship is saved as a gRPC interface dependency table.
[0021] Optionally, each piece of gRPC interface information implemented in the gRPC interface information group and each piece of gRPC interface calling information in the gRPC interface calling information group are identified to determine whether a method corresponding to the method information has a destructive change, including:
[0022] Each implementation gRPC interface information in the implementation gRPC interface information group and each call gRPC interface information in the call gRPC interface information group are identified. If at least one of the following is met, it is determined that the method has a destructive change:
[0023] The number of method parameters of the method is inconsistent with the number of method parameters of the gRPC interface definition information;
[0024] The type of the method parameter of the method is inconsistent with the type of the method parameter of the gRPC interface definition information;
[0025] The return type of the method is inconsistent with the return type of the gRPC interface definition information.
[0026] Optionally, according to the configuration file, obtain a gRPC interface definition information file, the gRPC interface definition information file includes a gRPC interface definition source code, including:
[0027] Determine whether there is configuration file cache information locally;
[0028] If the configuration file cache information does not exist locally, obtain the gRPC interface definition information file according to the configuration file. The gRPC interface definition information file includes the gRPC interface definition source code.
[0029] Optionally, a gRPC interface destructive change detection method under a microservice architecture of the present invention further includes:
[0030] If there is configuration file cache information locally, the version number in the configuration file cache information is compared with the version number in the configuration file to obtain a configuration file comparison result;
[0031] If the comparison result indicates that the version number in the configuration file cache information is inconsistent with the version number in the configuration file, then compare whether the version number in the gRPC interface definition information cache information is consistent with the version number in the gRPC interface definition information to obtain the definition information comparison result;
[0032] If the definition information comparison result indicates that the version number in the gRPC interface definition information cache information is consistent with the version number in the gRPC interface definition information, the local cache file is used as the abstract syntax tree, and the gRPC interface destructive change identification step is performed;
[0033] If the definition information comparison result indicates that the version number in the gRPC interface definition information cache information is inconsistent with the version number in the gRPC interface definition information, the gRPC interface destructive change detection method under the microservice architecture is executed.
[0034] Optionally, a gRPC interface destructive change detection method under a microservice architecture of the present invention further includes:
[0035] Export the gRPC interface dependency table to obtain the gRPC interface dependency graph.
[0036] Optionally, a gRPC interface destructive change detection method under a microservice architecture of the present invention further includes:
[0037] According to the preset notification method, the destructive change interface information group and the gRPC interface dependency graph are sent to the corresponding user terminal.
[0038] The present invention has the following beneficial effects:
[0039] 1. By automatically scanning the source code and analyzing the gRPC interface definition information, it can automatically discover and identify the interface call relationship between multiple sub-services included in the microservice in the product package to be tested, avoiding the tedious and error-prone problems of manual script writing, improving development efficiency, and ensuring the accuracy of the call relationship;
[0040] 2. Through the automatic detection method based on source code parsing and abstract syntax tree, the changes of interface information, especially the detection of destructive changes, can be identified in real time. There is no need to manually adjust the script, which reduces the maintenance workload, effectively avoids omissions and errors, and ensures the comprehensiveness and accuracy of the test;
[0041] 3. Through source code analysis and abstract syntax tree comparison, destructive changes of gRPC interfaces can be detected without running the system, which significantly reduces the time and resource consumption during the test process and improves detection efficiency and system performance;
[0042] 4. By automatically parsing the source code and generating a gRPC interface dependency graph, the gRPC interface dependencies and destructive changes between multiple sub-services included in the microservices in the product package to be tested can be accurately identified without running the system, which significantly improves the timeliness and efficiency of detection, ensuring that the potential impact scope can be quickly identified after the interface is modified, thereby avoiding problems during system operation. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] The above and other features, advantages and aspects of the embodiments of the present invention will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings. Throughout the accompanying drawings, the same or similar reference numerals represent the same or similar elements. It should be understood that the drawings are schematic and that components and elements are not necessarily drawn to scale.
[0044] Figure 1 It is a flowchart of a gRPC interface destructive change detection method under a microservice architecture of the present invention. DETAILED DESCRIPTION
[0045] The present invention will be described in more detail below with reference to the accompanying drawings. Although certain embodiments of the present invention are shown in the accompanying drawings, it should be understood that the present invention can be implemented in various forms and should not be construed as being limited to the embodiments set forth herein. On the contrary, these embodiments are provided to provide a more thorough and complete understanding of the present invention. It should be understood that the drawings and embodiments of the present invention are only for exemplary purposes and are not intended to limit the scope of protection of the present invention.
[0046] It should also be noted that, for ease of description, only the parts related to the invention are shown in the drawings. In the absence of conflict, the embodiments of the present invention and the features in the embodiments can be combined with each other.
[0047] It should be noted that the concepts such as "first" and "second" mentioned in the present invention are only used to distinguish different devices, modules or units, and are not used to limit the order or interdependence of the functions performed by these devices, modules or units.
[0048] It should be noted that the modifications of "one" and "plurality" mentioned in the present invention are illustrative rather than restrictive, and those skilled in the art should understand that, unless otherwise clearly indicated in the context, it should be understood as "one or more".
[0049] The names of the messages or information exchanged between multiple devices of the present invention are only for illustrative purposes, and are not used to limit the scope of these messages or information.
[0050] The present invention will be described in detail below with reference to the accompanying drawings and in conjunction with embodiments.
[0051] like Figure 1As shown, it is a flowchart of a method for detecting destructive changes of a gRPC interface under a microservice architecture of the present invention, which specifically includes the following steps:
[0052] Step 101, according to the configuration file, obtain a gRPC interface definition information file, the gRPC interface definition information file includes a gRPC interface definition source code.
[0053] In some embodiments, the execution subject may be a server. The execution subject reads the configuration information of the gRPC interface definition information file and the remote code library login password from the configuration file, and the configuration information includes the version information of the gRPC interface definition information file. Subsequently, the remote code library login password is used to log in to the remote code library, so as to synchronize the gRPC interface definition information file to the local, and obtain the gRPC interface definition source code from the gRPC interface definition information file. In practice, the gRPC interface definition information file may be a proto file. The gRPC interface definition information may include method name, method parameters, and return type. Among them, the proto file is a file written using Protocol Buffers, which is used to describe the communication interface between microservices, including information such as message type, method, service, etc., and each gRPC interface definition information can be obtained by parsing these files. Protocol Buffers is a protocol for data exchange and storage, which aims to provide an efficient and reliable way to serialize data so that it can be transmitted between different systems. gRPC is a modern open source high-performance remote procedure call framework that can run in any environment. It can efficiently connect services within and across data centers, and supports load balancing, tracking, health checks, and authentication. The gRPC interface is a communication interface between microservices and is widely used in microservice architecture as a communication method between services.
[0054] Step 102, parse the gRPC interface definition source code, obtain the gRPC interface declaration information, and obtain the gRPC interface definition information from the gRPC interface declaration information.
[0055] In some embodiments, the execution subject reads the gRPC interface declaration information from the gRPC interface definition source code, and obtains the gRPC interface definition information from the gRPC interface declaration information. Among them, the gRPC interface declaration information refers to the specific description and definition of the gRPC interface in the gRPC interface definition file, which contains the detailed structure of the interface, including the method name, method parameters, and return type. A method is an executable code used to complete a specific task or calculation. The method name is a name used to identify the method, usually a verb or verb phrase that describes the operation performed by the method. The method parameter is the input value passed to the method for use during the execution of the method. The method parameter is specified when the method is defined, and the specific parameter value is provided when the method is called. Each method parameter contains a method parameter type and a method parameter name. The return type is the type of value returned to the caller after the method is executed. It is specified when the method is defined, indicating the output type of the method. It can return any type of value or no return value.
[0056] Step 103: According to the configuration file, the source code of each sub-service of the microservice included in the product package to be detected and the multiple sub-services included in the microservice is obtained to obtain a source code group.
[0057] In some embodiments, the execution subject reads the configuration information of the microservice in the product package to be detected and the remote code library login password from the configuration file, and the configuration information includes the name and version information of the microservice to be detected. Subsequently, the remote code library login password is used to log in to the remote code library, so that the source code of each subservice in the multiple subservices included in the microservice to be detected in the remote code library is synchronized to the local to obtain a source code group. In practice, the configuration file includes the configuration information of the microservice to be detected, and also includes the configuration information of multiple subservices, and the configuration information of multiple subservices is stored in the sub-configuration file of the configuration file. The remote code library may include the source code of all subservices included in the microservice to be detected. Among them, the remote code library refers to a collection of source code, binary files or related resources stored on a remote server; the source code is the core content of software development, and all functions, logic and behaviors of the program are defined in the source code.
[0058] Step 104, parse multiple source codes in the source code group, construct an abstract syntax tree corresponding to each source code in the multiple source codes, and obtain multiple abstract syntax trees, each of the multiple abstract syntax trees includes multiple method information, and the multiple method information includes multiple method declaration information and multiple method call information.
[0059] In some embodiments, a tool or library for building an abstract syntax tree can be deployed on the execution subject, and multiple source codes in the source code group can be parsed to build an abstract syntax tree corresponding to each source code. In practice, Java code can use the JavaParser library, and Python code can use the AST module. Among them, the abstract syntax tree is a tree data structure used to represent the source code structure, which is usually used in compilers, interpreters, static analysis tools, etc. It represents the grammatical structure in the source code in a tree-like manner, and can abstractly represent the logical structure of the code without caring about the specific grammatical details. The various elements of the code are converted into tree nodes, and the relationship between the nodes represents the hierarchy and grammatical rules of the code. The nodes of the abstract syntax tree can represent annotations, access modifiers, fields, interface information, exception types, construction methods and other information in the source code to be loaded. Annotation is a mechanism for providing metadata in programming languages. The annotation itself does not directly change the behavior of the program, but it can be used by the compiler, runtime environment or development tools to implement some specific functions; access modifiers are used to control the access rights of classes, methods, and fields, and determine whether other classes can access these members. Class is a basic concept in object-oriented programming. It is a template or blueprint for an object. A class can be regarded as an abstract data type used to describe a collection of objects with common characteristics and behaviors. Field refers to a member variable in a class, which is used to store the state or data of an object. A constructor is a special method used to initialize the state of an object when it is created. The name of the constructor is the same as the class name and has no return type. An interface is a special class that contains abstract methods and constants. An abstract method is a method without a method body. It only has a method signature and does not provide a specific implementation. A constant is a variable whose value does not change in a program. A method signature is a unique identifier used to identify a method, which contains a method name, a parameter list, and a return type. JavaParser is a powerful Java library for parsing, analyzing, and manipulating Java source code. It can convert Java source code into an abstract syntax tree and provide various tools to manipulate and modify these tree structures. The AST module is a Python module used to process the abstract syntax tree of Python code. It can parse Python source code into an abstract syntax tree or compile an abstract syntax tree back into Python code. Method declaration information refers to the information included when defining a method in the source code, usually including: method name, method parameters, return type and method body. The method body is the specific implementation logic of the method. Method call information refers to the information included when calling a method in the source code, usually including: calling method name, calling parameters, and calling location. The calling method name is the name of the called method. The calling parameters are the method parameters passed to the method when calling, including the type and value of the parameters. The calling location is the specific calling location in the source code, usually including the file name and line number.
[0060] Step 105, traverse multiple abstract syntax trees, match multiple method declaration information with gRPC interface definition information, determine the successfully matched method declaration information as the gRPC interface implementation information, and obtain the gRPC interface implementation information group.
[0061] In some embodiments, the execution subject traverses the constructed multiple abstract syntax trees, matches the multiple method declaration information in the multiple abstract syntax trees with the gRPC interface definition information, obtains the method declaration information matching result, and if the method declaration information matching result represents consistency, the method declaration information is determined as the implementation of the gRPC interface information, and the multiple implementation gRPC interface information is determined as the implementation of the gRPC interface information group. In practice, the conditions for matching the method declaration information with the gRPC interface definition information are the consistency of the method name, method parameters and return type, including: the method name of the method declaration information is consistent with the method name of the gRPC interface definition information; the method parameters of the method declaration information are consistent with the method parameters of the gRPC interface definition information, wherein the consistency of the method parameters includes the consistency of the type of the method parameters, the consistency of the number of method parameters and the consistency of the order of the method parameters; the return type of the method declaration information is consistent with the return type of the gRPC interface definition information. If the method name, method parameters and return type matched by the method declaration information and the gRPC interface definition information are consistent, the match is successful.
[0062] Step 106, traverse multiple abstract syntax trees, match multiple method call information with gRPC interface definition information, determine the successfully matched method call information as the calling gRPC interface information, and obtain the calling gRPC interface information group.
[0063] In some embodiments, the execution subject traverses the constructed multiple abstract syntax trees, matches the multiple method call information in the multiple abstract syntax trees with the gRPC interface definition information, and obtains the method call information matching result. If the method call information matching result representation is consistent, the method call information is determined as calling gRPC interface information, and the multiple calling gRPC interface information is determined as calling gRPC interface information group. In practice, the condition for matching the method call information with the gRPC interface definition information is the consistency of the method name and method parameters, including: the method name of the method call information is consistent with the method name of the gRPC interface definition information; the method parameters of the method call information are consistent with the method parameters of the gRPC interface definition information, wherein the consistency of the method parameters includes the consistency of the type of the method parameters, the consistency of the number of method parameters, and the consistency of the order of the method parameters. If the method name and method parameters matched by the method call information and the gRPC interface definition information are consistent, the match is successful.
[0064] Step 107, match the method information corresponding to each implementation gRPC interface information in the implementation gRPC interface information group with the method information corresponding to each call gRPC interface information in the call gRPC interface information group to determine whether the method corresponding to each method information has a destructive change, and determine the gRPC interface corresponding to the method that has a destructive change and is called as the gRPC interface affected by the destructive change, to obtain a destructive change gRPC interface group.
[0065] In some embodiments, the execution subject matches the method information corresponding to each implementation gRPC interface information in the implementation gRPC interface information group and the method information corresponding to each call gRPC interface information in the call gRPC interface information group to obtain the gRPC method implementation and call matching results. If the gRPC method implementation and call matching results are inconsistent, the method corresponding to the method information has a destructive change, and the method that has a destructive change and is called is determined as a gRPC interface that has a destructive change impact, and multiple gRPC interfaces that have a destructive change impact are determined as a destructive change gRPC interface group. In practice, the condition for matching the implementation gRPC interface information group and the call gRPC interface information group is the consistency of the method name and method parameters, including: the method name of the method information of the implementation gRPC interface information group is consistent with the method name of the method information of the call gRPC interface information group; the method parameters of the method information of the implementation gRPC interface information group are consistent with the method parameters of the method information of the call gRPC interface information group, wherein the consistency of the method parameters includes the consistency of the type of the method parameters, the consistency of the number of the method parameters, and the consistency of the order of the method parameters. If any of the above conditions is not met, it is determined that the method corresponding to the method information has a destructive change.
[0066] Optionally, each method information in the multiple abstract syntax trees includes a method name, method parameters, and a return type.
[0067] In some embodiments, each method information in the plurality of abstract syntax trees includes the following: method name, method parameters, and return type.
[0068] Optionally, matching method information corresponding to each gRPC interface implementation information in the gRPC interface implementation information group with method information corresponding to each gRPC interface call information in the gRPC interface call information group includes:
[0069] Match the method name of the method information corresponding to the gRPC interface information with the method name of the gRPC interface definition information; or
[0070] Match the method parameters of the method information corresponding to the gRPC interface information with the method parameters of the gRPC interface definition information; or
[0071] Match the return type of the method information corresponding to the gRPC interface information with the return type of the gRPC interface definition information.
[0072] In some embodiments, the execution entity matches the method information corresponding to each gRPC interface information implemented in the gRPC interface information group with the method information corresponding to each gRPC interface information called in the gRPC interface information group, and the matching content is: matching the method name of the method information corresponding to the gRPC interface information implemented with the method name of the gRPC interface definition information; matching the method parameters of the method information corresponding to the gRPC interface information implemented with the method parameters of the gRPC interface definition information, wherein the matching of the method parameters includes the type matching of the method parameters, the number matching of the method parameters, and the order matching of the method parameters; matching the return type of the method information corresponding to the gRPC interface information implemented with the return type of the gRPC interface definition information.
[0073] Optionally, each gRPC interface call information in the gRPC interface call information group is identified to determine whether the gRPC interface call information is called by the microservice, including:
[0074] Each call gRPC interface information in the call gRPC interface information group is matched with each method call information in multiple abstract syntax trees. If the call gRPC interface information matches the method call information successfully, it is determined that a call relationship exists between the gRPC interface information, and the call relationship is saved as a gRPC interface dependency table.
[0075] In some embodiments, the execution subject matches each call gRPC interface information in the call gRPC interface information group with each method call information in multiple abstract syntax trees, including: the method name of the call gRPC interface information in the call gRPC interface information group is consistent with the method name of the method call information in the abstract syntax tree; the method parameters of the call gRPC interface information in the call gRPC interface information group are consistent with the method parameters of the method call information in the abstract syntax tree, wherein the consistency of the method parameters includes the consistency of the type of the method parameters, the consistency of the number of method parameters, and the consistency of the order of the method parameters. If all of the above conditions are met, it is determined that the gRPC interface information has a call relationship, and the call relationship is saved as a gRPC interface dependency table.
[0076] Optionally, each piece of gRPC interface information implemented in the gRPC interface information group and each piece of gRPC interface calling information in the gRPC interface calling information group are identified to determine whether a method corresponding to the method information has a destructive change, including:
[0077] Each implementation gRPC interface information in the implementation gRPC interface information group and each call gRPC interface information in the call gRPC interface information group are identified. If at least one of the following is met, it is determined that the method has a destructive change:
[0078] The number of method parameters of the method is inconsistent with the number of method parameters of the gRPC interface definition information;
[0079] The type of the method parameter of the method is inconsistent with the type of the method parameter of the gRPC interface definition information;
[0080] The return type of the method is inconsistent with the return type of the gRPC interface definition information.
[0081] In some embodiments, the execution subject identifies each implementation gRPC interface information in the implementation gRPC interface information group and each call gRPC interface information in the call gRPC interface information group, including: the method name of the method information of the implementation gRPC interface information group is consistent with the method name of the method information of the call gRPC interface information group; the method parameters of the method information of the implementation gRPC interface information group are consistent with the method parameters of the method information of the call gRPC interface information group, wherein the consistency of the method parameters includes the consistency of the type of the method parameters, the consistency of the number of the method parameters, and the consistency of the order of the method parameters. If one of the above conditions is not met, it is determined that the method corresponding to the method information has a destructive change.
[0082] Optionally, according to the configuration file, obtain a gRPC interface definition information file, the gRPC interface definition information file includes a gRPC interface definition source code, including:
[0083] Determine whether there is configuration file cache information locally;
[0084] If the configuration file cache information does not exist locally, obtain the gRPC interface definition information file according to the configuration file. The gRPC interface definition information file includes the gRPC interface definition source code.
[0085] In some embodiments, the execution entity first detects whether there is configuration file cache information locally. If there is no configuration file cache information locally, the configuration file is determined as the configuration file cache information, and the configuration information of the gRPC interface definition information file and the remote code library login password are read from the configuration file. The remote code library login password is used to log in to the remote code library, thereby synchronizing the gRPC interface definition information file to the local, and obtaining the gRPC interface definition source code from the gRPC interface definition information file.
[0086] Optionally, a gRPC interface destructive change detection method under a microservice architecture of the present invention further includes:
[0087] If there is configuration file cache information locally, the version number in the configuration file cache information is compared with the version number in the configuration file to obtain a configuration file comparison result;
[0088] If the comparison result indicates that the version number in the configuration file cache information is inconsistent with the version number in the configuration file, then compare whether the version number in the gRPC interface definition information cache information is consistent with the version number in the gRPC interface definition information to obtain the definition information comparison result;
[0089] If the definition information comparison result indicates that the version number in the gRPC interface definition information cache information is consistent with the version number in the gRPC interface definition information, the local cache file is used as the abstract syntax tree, and the gRPC interface destructive change identification step is performed;
[0090] If the definition information comparison result indicates that the version number in the gRPC interface definition information cache information is inconsistent with the version number in the gRPC interface definition information, the gRPC interface destructive change detection method under the microservice architecture is executed.
[0091] In some embodiments, if there is configuration file cache information locally, the version number in the configuration file cache information is compared with the version number in the configuration file to obtain the configuration file comparison result. If the version number in the configuration file cache information is inconsistent with the version number in the configuration file, first determine whether there is gRPC interface definition information cache information locally. If not, the gRPC interface definition information is determined as gRPC interface definition information cache information. If it exists, further compare whether the version number in the gRPC interface definition information cache information is consistent with the version number in the gRPC interface definition information to obtain the definition information comparison result. If the version number in the gRPC interface definition information cache information is consistent with the version number in the gRPC interface definition information, use the local cache file as the abstract syntax tree to execute the gRPC interface destructive change identification step, and the gRPC interface destructive change identification step includes steps 104, 105, 106, and 107 of the gRPC interface destructive change detection method under the microservice architecture. If the version number in the configuration file cache information is inconsistent with the version number in the configuration file, step 104 of the gRPC interface destructive change detection method under the microservice architecture is executed to build an abstract syntax tree, and the abstract syntax tree is serialized to obtain a local cache file, and finally steps 105, 106 and 107 of the gRPC interface destructive change detection method under the microservice architecture are executed.
[0092] In practice, the local cache file is obtained by serializing the historical abstract syntax tree; the historical target abstract syntax tree is the abstract syntax tree generated by the last execution of the gRPC interface destructive change detection method under the microservice architecture; serialization is the process of converting a data structure or object into a format that can be stored or transmitted. The objects and data structures used in the program are converted into a series of bytes so that they can be saved to disk, sent over the network, or shared between processes. When the data needs to be reused, it is restored to the original data structure through deserialization.
[0093] Optionally, export the gRPC interface dependency table to obtain a gRPC interface dependency graph.
[0094] In some embodiments, the execution entity converts the gRPC interface dependency table into a format suitable for visualization tools using a JavaScript library, which is usually represented in the form of nodes and edges, where nodes represent microservices or interfaces and edges represent dependencies. In practice, the JavaScript library vis-network.min.js can be used. This JavaScript library can dynamically present dependencies between interfaces, support interactive behaviors, and enhance developers' understanding of dependencies and analysis of potential problems. Among them, JavaScript is a widely used programming language, mainly used for web development; vis-network.min.js is a compressed version of the Vis.js library, which is mainly used to build and operate graphical networks; the Vis.js library is a powerful JavaScript library for creating, operating and presenting graphics, networks and other complex data structures.
[0095] Optionally, the destructive change interface information group and the gRPC interface dependency graph are sent to the corresponding user terminal according to a preset notification method.
[0096] In some embodiments, after collecting the destructive change interface information group and the gRPC interface dependency graph, the execution subject sends it to the user terminal according to a preset notification method. In practice, the preset notification method can be to use the SMTP (Simple Mail Transfer Protocol) protocol to send emails through the JavaScript library nodemailer. Among them, nodemailer is a widely used JavaScript library that supports multiple email transmission protocols; the SMTP protocol is an Internet standard protocol for transmitting emails, which defines the way emails are transmitted between email servers so that emails can be correctly delivered in the network.
[0097] In these embodiments, by automatically scanning the microservice source code and analyzing the gRPC interface, the interface call relationship between microservices is automatically identified, the tediousness and error problems of manual script writing are avoided, and the development efficiency and accuracy are improved; based on the source code parsing and abstract syntax tree methods, interface changes, especially destructive changes, are identified in real time without manual script adjustment, reducing maintenance workload and ensuring the comprehensiveness of the test; through static source code analysis, destructive changes of the gRPC interface are detected without running the system, saving time and resources and improving efficiency; at the same time, a gRPC interface dependency graph is automatically generated to accurately identify interface dependencies and destructive changes, ensuring rapid identification of potential impacts and avoiding system runtime problems; and by caching files locally, the scanning speed is improved.
[0098] The above descriptions are only some preferred embodiments of the present invention and the explanation of the technical principles used. Those skilled in the art should understand that the scope of the invention involved in the present invention is not limited to the technical solutions formed by the specific combination of the above technical features, but also should cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the above inventive concept. For example, the above features are replaced with the technical features with similar functions disclosed in the present invention (but not limited to) to form a technical solution.
Claims
1. A method for detecting destructive changes of gRPC interfaces in a microservice architecture, characterized in that: include: According to the configuration file, a gRPC interface definition information file is obtained, wherein the gRPC interface definition information file includes a gRPC interface definition source code; Parse the gRPC interface definition source code to obtain gRPC interface declaration information, and obtain gRPC interface definition information from the gRPC interface declaration information; According to the configuration file, the source code of each of the microservices included in the product package to be detected and the multiple subservices included in the microservice is obtained to obtain a source code group; Parsing multiple source codes in the source code group, constructing an abstract syntax tree corresponding to each source code in the multiple source codes, and obtaining multiple abstract syntax trees, each of the multiple abstract syntax trees including multiple method information, the multiple method information including multiple method declaration information and multiple method call information; Each method information in the plurality of abstract syntax trees includes a method name, method parameters, and a return type; Traversing the multiple abstract syntax trees, matching the multiple method declaration information with the gRPC interface definition information, where a condition for successful matching is that the method name, method parameters, and return type in the method declaration information are consistent with the method name, method parameters, and return type in the gRPC interface definition information; determining the successfully matched method declaration information as the gRPC interface implementation information, and obtaining the gRPC interface implementation information group; Traversing the multiple abstract syntax trees, matching the multiple method call information with the gRPC interface definition information, where a condition for successful matching is that the method name, method parameters, and return type in the method call information are consistent with the method name, method parameters, and return type in the gRPC interface definition information; determining the successfully matched method call information as the calling gRPC interface information, and obtaining the calling gRPC interface information group; Match the method information corresponding to each implementation gRPC interface information in the implementation gRPC interface information group with the method information corresponding to each call gRPC interface information in the call gRPC interface information group to determine whether the method corresponding to each method information has a destructive change, and determine the gRPC interface corresponding to the method that has a destructive change and is called as the gRPC interface affected by the destructive change, to obtain a destructive change gRPC interface group; According to the configuration file, a gRPC interface definition information file is obtained, wherein the gRPC interface definition information file includes a gRPC interface definition source code, including: Determine whether there is configuration file cache information locally; If the configuration file cache information does not exist locally, obtain the gRPC interface definition information file according to the configuration file, wherein the gRPC interface definition information file includes the gRPC interface definition source code; If the configuration file cache information exists locally, the version number in the configuration file cache information is compared with the version number in the configuration file to obtain a configuration file comparison result; If the comparison result indicates that the version number in the configuration file cache information is inconsistent with the version number in the configuration file, compare whether the version number in the gRPC interface definition information cache information is consistent with the version number in the gRPC interface definition information to obtain a definition information comparison result; If the definition information comparison result indicates that the version number in the gRPC interface definition information cache information is consistent with the version number in the gRPC interface definition information, the local cache file is used as an abstract syntax tree, and the gRPC interface destructive change identification step is performed; If the definition information comparison result indicates that the version number in the gRPC interface definition information cache information is inconsistent with the version number in the gRPC interface definition information, the gRPC interface destructive change detection method under the microservice architecture is executed.
2. According to the gRPC interface destructive change detection method under the microservice architecture of claim 1, it is characterized in that: Matching the method information corresponding to each gRPC interface implementation information in the gRPC interface implementation information group with the method information corresponding to each gRPC interface call information in the gRPC interface call information group includes: Matching the method name of the method information corresponding to the gRPC interface information with the method name of the gRPC interface definition information; or Matching the method parameters of the method information corresponding to the gRPC interface information with the method parameters of the gRPC interface definition information; or The return type of the method information corresponding to the gRPC interface information is matched with the return type of the gRPC interface definition information.
3. According to the gRPC interface destructive change detection method under the microservice architecture of claim 1, it is characterized in that: Identifying each gRPC interface call information in the gRPC interface call information group to determine whether the gRPC interface call information is called by the microservice, including: Each calling gRPC interface information in the calling gRPC interface information group is matched with each method calling information in the multiple abstract syntax trees. If the calling gRPC interface information matches the method calling information successfully, it is determined that a calling relationship exists between the gRPC interface information, and the calling relationship is saved as a gRPC interface dependency table.
4. According to the gRPC interface destructive change detection method under the microservice architecture of claim 1, it is characterized in that: Identifying each piece of gRPC interface implementation information in the gRPC interface implementation information group and each piece of gRPC interface call information in the gRPC interface call information group to determine whether a method corresponding to the method information has a destructive change, including: Each piece of implemented gRPC interface information in the implemented gRPC interface information group and each piece of called gRPC interface information in the called gRPC interface information group are identified, and if at least one of the following is satisfied, it is determined that the method has a destructive change: The number of method parameters of the method is inconsistent with the number of method parameters of the gRPC interface definition information; The type of the method parameter of the method is inconsistent with the type of the method parameter of the gRPC interface definition information; The return type of the method is inconsistent with the return type of the gRPC interface definition information.
5. According to the gRPC interface destructive change detection method under the microservice architecture of claim 1, it is characterized in that: Also includes: The gRPC interface dependency table is exported to obtain a gRPC interface dependency graph.
6. According to the gRPC interface destructive change detection method under the microservice architecture of claim 5, it is characterized in that: Also includes: According to the preset notification method, the destructive change interface information group and the gRPC interface dependency graph are sent to the corresponding user terminal.
Citation Information
Patent Citations
Interface influence detection method and related equipment
CN114579452A
Micro-service architecture granularity peculiar smell detection method based on business theme clustering
CN117390469A