Method and device for detecting circular dependency based on micro-service platform

By parsing service source files and constructing a directed graph in the microservice platform, the accuracy of circular dependency detection in microservice systems is solved, enabling efficient detection and low-cost repair during the development phase.

CN115481040BActive Publication Date: 2026-07-14HUNDSUN TECH

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
HUNDSUN TECH
Filing Date
2022-09-29
Publication Date
2026-07-14

AI Technical Summary

Technical Problem

Existing technologies struggle to accurately detect circular dependencies during the development phase of microservice systems, leading to missed detections by humans and costly system repairs.

Method used

By obtaining the service source files of the microservice platform, parsing the service nodes, constructing a simplified directed graph, generating the target directed graph, and performing circular dependency detection, the dependency on the service call process is avoided.

Benefits of technology

It achieves non-intrusive circular dependency detection during the development phase, improving detection accuracy and reducing manual missed detections and system defect repair costs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115481040B_ABST
    Figure CN115481040B_ABST
Patent Text Reader

Abstract

The application provides a cyclic dependency detection method and device based on a micro-service platform, wherein the cyclic dependency detection method based on the micro-service platform comprises: in response to a cyclic dependency detection request for the micro-service platform, obtaining service source files of each micro-service unit in the micro-service platform; parsing the service source files of each micro-service unit to determine service nodes of each micro-service unit; based on the service nodes of each micro-service unit, constructing a simplified directed graph of each micro-service unit; generating a target directed graph of the micro-service platform according to the simplified directed graph of each micro-service unit; and performing cyclic dependency detection on the micro-service platform based on the target directed graph to obtain a cyclic dependency detection result, thereby not only avoiding the problem of manual missed detection, but also improving the accuracy of cyclic dependency detection and reducing the cost of system defect repair and rollback.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and in particular to a method for detecting circular dependencies based on a microservice platform. This application also relates to a device for detecting circular dependencies based on a microservice platform, a computing device, and a computer-readable storage medium. Background Technology

[0002] Microservices break down a complete system into several smaller, more granular service units. Each service unit interacts with other service units through network interfaces to jointly complete business functions. Most business requirements require the cooperation of multiple service units, and this cooperation can potentially lead to circular dependencies.

[0003] To avoid circular dependencies between services that could lead to service anomalies, circular dependency detection can be performed on the entire microservice system. Currently, in addition to manual detection, the execution requests and service call paths can be checked during system testing or maintenance to identify circular dependency issues in the microservice system. However, as the number of service units in a microservice system continues to increase, performing circular dependency detection only on the service call process may result in missed cases, significantly impacting the accuracy of circular dependency detection in the microservice system. Summary of the Invention

[0004] In view of this, embodiments of this application provide a circular dependency detection method based on a microservice platform. This application also relates to a circular dependency detection apparatus based on a microservice platform, a computing device, and a computer-readable storage medium, to solve the aforementioned problems existing in the prior art.

[0005] According to a first aspect of the embodiments of this application, a circular dependency detection method based on a microservice platform is provided, comprising:

[0006] In response to a circular dependency detection request for the microservice platform, the service source file of each microservice unit in the microservice platform is obtained;

[0007] Parse the service source file of each microservice unit to determine the service node of each microservice unit;

[0008] Based on the service nodes of each microservice unit, a simplified directed graph of each microservice unit is constructed;

[0009] Based on the simplified directed graph of each microservice unit, the target directed graph of the microservice platform is generated;

[0010] Based on the target directed graph, the microservice platform is subjected to circular dependency detection to obtain the circular dependency detection results.

[0011] According to a second aspect of the embodiments of this application, a circular dependency detection device based on a microservice platform is provided, comprising:

[0012] The source file acquisition module is configured to acquire the service source file of each microservice unit in the microservice platform in response to a circular dependency detection request for the microservice platform.

[0013] The source file parsing module is configured to parse the service source file of each microservice unit and determine the service node of each microservice unit;

[0014] The first construction module is configured to construct a simplified directed graph of each microservice unit based on the service node of each microservice unit;

[0015] The second building module is configured to generate the target directed graph of the microservice platform based on the simplified directed graph of each microservice unit;

[0016] The dependency detection module is configured to perform circular dependency detection on the microservice platform based on the target directed graph and obtain the circular dependency detection result.

[0017] According to a third aspect of the embodiments of this application, a computing device is provided, including a memory, a processor, and computer instructions stored in the memory and executable on the processor, wherein the processor executes the computer instructions to implement the steps of the circular dependency detection method based on a microservice platform.

[0018] According to a fourth aspect of the embodiments of this application, a computer-readable storage medium is provided that stores computer instructions, which, when executed by a processor, implement the steps of the circular dependency detection method based on a microservice platform.

[0019] The circular dependency detection method based on a microservice platform provided in this application, in response to a circular dependency detection request for the microservice platform, obtains the service source file of each microservice unit in the microservice platform; parses the service source file of each microservice unit to determine the service node of each microservice unit; constructs a simplified directed graph of each microservice unit based on the service node of each microservice unit; generates a target directed graph of the microservice platform based on the simplified directed graph of each microservice unit; and performs circular dependency detection on the microservice platform based on the target directed graph to obtain the circular dependency detection result.

[0020] One embodiment of this application obtains the service source files of each microservice unit in a microservice platform, parses the service source files to determine the service nodes providing services in each microservice unit, constructs a corresponding simplified directed graph for each service node in the microservice unit, and finally merges the simplified directed graphs corresponding to each microservice unit in the microservice platform to obtain a target directed graph. This allows for the detection of circular dependencies in the entire microservice platform from the target directed graph. This method, through static code scanning, detects circular dependencies in service calls without intruding on the existing code of the entire microservice platform, and during the development phase of the microservice platform, without requiring the microservice platform to request services. This not only avoids the problem of manual omissions but also improves the accuracy of circular dependency detection and reduces the cost of system defect repair and rollback. Attached Figure Description

[0021] Figure 1 This is a schematic diagram illustrating a scenario of a circular dependency detection method based on a microservice platform provided in an embodiment of this application;

[0022] Figure 2 This is a flowchart of a circular dependency detection method based on a microservice platform provided in an embodiment of this application;

[0023] Figure 3a This is a schematic diagram of a simplified directed graph of an account module generated by a microservice platform-based circular dependency detection method applied to an e-commerce platform, provided in an embodiment of this application.

[0024] Figure 3b This is a schematic diagram of a simplified directed graph for generating an order module, which is a circular dependency detection method based on a microservice platform and applied to an e-commerce platform, according to an embodiment of this application.

[0025] Figure 3c This is a schematic diagram of a method for detecting circular dependencies based on a microservice platform and applied to an e-commerce platform, provided in an embodiment of this application, to generate a simplified directed graph of the inventory module;

[0026] Figure 4 This is a schematic diagram illustrating a circular dependency detection method based on a microservice platform applied to an e-commerce platform, provided in an embodiment of this application, for generating a merged directed graph.

[0027] Figure 5 This is a schematic diagram of the structure of a circular dependency detection device based on a microservice platform provided in an embodiment of this application;

[0028] Figure 6 This is a structural block diagram of a computing device provided in one embodiment of this application. Detailed Implementation

[0029] Many specific details are set forth in the following description to provide a full understanding of this application. However, this application can be implemented in many other ways different from those described herein, and those skilled in the art can make similar extensions without departing from the spirit of this application; therefore, this application is not limited to the specific embodiments disclosed below.

[0030] The terminology used in one or more embodiments of this application is for the purpose of describing particular embodiments only and is not intended to limit the scope of one or more embodiments of this application. The singular forms “a,” “the,” and “the” used in one or more embodiments of this application and in the appended claims are also intended to include the plural forms unless the context clearly indicates otherwise. It should also be understood that the term “and / or” used in one or more embodiments of this application refers to and includes any or all possible combinations of one or more associated listed items.

[0031] It should be understood that although the terms first, second, etc., may be used to describe various information in one or more embodiments of this application, such information should not be limited to these terms. These terms are only used to distinguish information of the same type from one another. For example, first may also be referred to as second without departing from the scope of one or more embodiments of this application, and similarly, second may also be referred to as first. Depending on the context, the word "if" as used herein may be interpreted as "when," "when," or "in response to a determination."

[0032] First, the terms and concepts involved in one or more embodiments of this application will be explained.

[0033] Microservices: A software development technique—a variation of the Service-Oriented Architecture (SOA) style—that divides a single application into a set of small services that coordinate and cooperate with each other to provide end-value to the user. Each service runs in its own independent process, and services communicate with each other using lightweight communication mechanisms (typically HTTP-based RESTful APIs).

[0034] Directed graph: A directed graph is a graph with directionality, consisting of a vertex and a set of directed edges, with each directed edge connecting to an ordered pair of vertices.

[0035] A directed cycle is a directed path that has at least one edge and has the same starting and ending points.

[0036] A directed path is a series of vertices, for each of which there exists a directed edge pointing to the next vertex in the sequence.

[0037] Abstract Syntax Tree (AST): A syntax tree is an abstract representation of the syntactic structure of source code. It represents the syntactic structure of a programming language in a tree-like structure, where each node in the tree represents a structure in the source code.

[0038] Microservices are a popular software architecture widely used in the development of distributed systems. Microservices break down a complete system into several smaller, more granular service units. Each service unit interacts with other service units through network interfaces to jointly complete business functions. Microservice architecture advocates for small, independent services. A software system often has many service units, and most business requirements require the cooperation of multiple service units. The main advantage of microservices stems from the principle of independent deployability. Independent deployability requires that each service has complete autonomy over its development, deployment, and operation. To achieve this, it is crucial to avoid circular dependencies between services. For example, if services A and B have a circular dependency, when either A or B needs to release new features or crashes due to abnormal conditions, it will affect the other's functionality, forcing the two services to coordinate consistent lifecycle operations.

[0039] Circular dependencies between microservices are similar to circular dependencies between classes. When a dependency cycle forms, it can cause numerous problems. Currently, most methods for detecting circular dependencies between microservices involve obtaining call information reported by each service executing a request task during system runtime. Based on this information, a directed graph of service calls is generated, and the existence of circular dependencies is determined using this graph. However, because this method detects circular dependencies during system runtime, problems can only be discovered during the testing or maintenance phase, leading to high costs for system repair and rollback. Furthermore, this method analyzes services that have executed requests; if some services have not been called, circular dependencies may be missed. Additionally, when circular dependencies are detected, this method cannot directly locate the source code files, causing significant difficulties for subsequent system investigations.

[0040] Based on this, the embodiments of this application provide a circular dependency detection method based on a microservice platform. By processing the source files of the microservice platform, dependency detection can be completed during the development stage, enabling the early detection of system defects in the service platform and reducing repair costs. In addition, the detection can be completed without requesting services during the development stage, which not only avoids missed detections caused by human error but also improves the accuracy of circular dependency detection. At the same time, this method can directly locate the source code file or line number when discovering circular dependencies, helping developers to fix defects more quickly.

[0041] This application provides a circular dependency detection method based on a microservice platform. This application also relates to a circular dependency detection device based on a microservice platform, a computing device, and a computer-readable storage medium, which will be described in detail in the following embodiments.

[0042] Figure 1 The illustration shows a scenario diagram of a circular dependency detection method based on a microservice platform according to an embodiment of this application.

[0043] Figure 1 This includes a microservice platform 100 and a circular dependency detection system 200 for the microservice platform; wherein, the microservice platform 100 includes multiple microservice units, including microservice unit 1, microservice unit 2, microservice unit 3, and microservice unit 4, and the various microservice units make service calls to each other, such as... Figure 1 The arrows in the microservice platform 100 indicate the service call process. The circular dependency detection system 200 of the microservice platform is used to detect whether circular dependency problems occur in the service calls in the microservice platform 100.

[0044] Specifically, the circular dependency detection system 200 can obtain the service source files of each microservice unit in the microservice platform 100, and determine the service nodes of each microservice unit by parsing the service source files; construct a simplified directed graph of each microservice unit based on the service nodes of each microservice unit, and generate a target directed graph based on the simplified directed graph of each microservice unit; finally, perform circular dependency detection based on the target directed graph to obtain the circular dependency detection result.

[0045] The circular dependency detection method based on a microservice platform provided in this embodiment can detect circular dependencies during the microservice platform development stage by obtaining the source files of each microservice unit. At the same time, it can obtain the service call process of all microservice units in the microservice platform without relying on the service call execution process, which also improves the accuracy of circular dependency detection and avoids the problem of manual omission.

[0046] Figure 2The flowchart illustrates a circular dependency detection method based on a microservice platform according to an embodiment of this application, which specifically includes the following steps:

[0047] It should be noted that the execution subject of the circular dependency detection method for the microservice platform provided in this embodiment can be an additional circular detection system or the microservice platform itself. The following embodiments only describe the specific circular dependency detection process and do not limit the execution subject in any way.

[0048] Step 202: In response to the circular dependency detection request of the microservice platform, obtain the service source file of each microservice unit in the microservice platform.

[0049] In this context, a microservice platform can be understood as a system architecture that requires multiple service units to work together to fulfill business requirements, and the various service units in the platform cooperate with each other through service calls.

[0050] A microservice unit can be understood as multiple service units divided within a microservice platform. When executing a certain business requirement, each microservice unit processes the business by calling each other's services. For example, in an e-commerce platform, modules such as account management, order management, and inventory management can all be understood as microservice units.

[0051] Service source files can be understood as the development source files of each microservice unit in the microservice platform, including source code files, various configuration files, etc.

[0052] In practical applications, the executing entity can respond to a circular dependency detection request for a certain microservice platform and initiate the circular dependency detection process. It should be noted that the entire microservice platform is currently still in the system development stage and has not yet entered the system testing or maintenance stage. Furthermore, the executing entity can scan the service source files of all microservice units in the microservice platform to detect whether there are circular dependencies among the various microservice units.

[0053] Step 204: Parse the service source file of each microservice unit to determine the service node of each microservice unit.

[0054] In this context, a service node can be understood as a method node in the source code of a microservice unit that provides the service invocation method.

[0055] In practical applications, the executing entity can parse the service source files of all microservice units obtained by scanning to determine each service node in each microservice unit. The number of service nodes can be at least one, which can be determined according to the system development requirements. This embodiment does not make a specific limitation on this.

[0056] Furthermore, to avoid missed detections in circular dependency detection of the microservice platform, the executing entity can scan various types of service source files in all microservice units to determine the service node of each microservice unit; specifically, parsing the service source file of each microservice unit to determine the service node of each microservice unit includes:

[0057] Determine the file type of the service source file for each microservice unit;

[0058] Based on the file type, file parsing rules are determined, and the service source files of each microservice unit are parsed according to the file parsing rules to determine the service node of each microservice unit.

[0059] The file type can be understood as the file type of the source files scanned by the executing entity, such as source code files, configuration files, etc.

[0060] File parsing rules can be understood as different parsing rules determined for different file types of service source files.

[0061] In practical applications, the executing entity categorizes the service source files of all scanned microservice units, identifies multiple file types, and then performs classification and parsing processing on the service source files of different types. Next, it determines the file parsing rules corresponding to each file type, and then parses the service source files of each microservice unit according to the corresponding file parsing rules to determine the service node of each microservice unit.

[0062] It should be noted that different file parsing rules are used for different types of source files, which can not only improve the efficiency of file parsing, but also reduce a lot of redundant calculations and save computing resources.

[0063] This embodiment provides a process for parsing and processing service source files of the service code file type; wherein, the file type is the service code file type.

[0064] Accordingly, based on the file type, file parsing rules are determined, and the service source file of each microservice unit is parsed according to the file parsing rules to determine the service node of each microservice unit, including:

[0065] The syntax structure parsing rules are determined based on the service code file type;

[0066] The service source file of each microservice unit is parsed according to the syntax structure parsing rules to determine the service node of each microservice unit.

[0067] The service code file type can be understood as the source code file in the microservice unit, such as Java source files.

[0068] Syntax structure parsing rules can be understood as rules for parsing the syntax structure of microservice unit development code, such as abstract syntax tree technology.

[0069] In practical applications, when the executing entity determines that the service source file A is a service code file type, it can determine that the file parsing rule corresponding to the service source file A is the syntax structure parsing rule, and parse the service source file A according to the syntax structure parsing rule, thereby determining each service node in the microservice unit.

[0070] Specifically, the step of parsing the service source file of each microservice unit according to the syntax structure parsing rules and determining the service node of each microservice unit includes:

[0071] The service source file of each microservice unit is parsed according to the syntax structure parsing rules to determine the method node tree of each service source file;

[0072] The method nodes with service identifiers in each method node tree are identified as the service nodes of each microservice unit, wherein the service identifiers include service declaration identifiers and service reference identifiers.

[0073] The method node tree of the service source file can be understood as the syntax tree structure obtained after parsing the code file according to the abstract syntax tree technique. This syntax tree structure includes multiple method nodes, and there are calling and called relationships between the method nodes.

[0074] In practical applications, when the execution entity processes service source files of the service code file type, it uses abstract syntax tree technology to parse the Java source files. The methods executed in the service source files of each microservice unit are constructed as a method node tree. Each node in this method node tree can be understood as a method node and can be identified as a method identifier. The method identifier generation strategy is: class name + method name + number of parameters. If a method is overridden and has the same method identifier, it is considered the same method. Since this embodiment needs to determine whether each method node in the microservice unit is a service provider, it is necessary to traverse all method nodes in the service source file to identify the method nodes with service identifiers. These method nodes with service identifiers are then identified as service nodes for each microservice unit. Additionally, the identified service nodes can be tagged with an identifier containing "service provider".

[0075] It should be noted that a service identifier can be understood as an identifier that contains service functionality within a method, such as an identifier that the method contains a service declaration or an identifier that the called method contains a service reference.

[0076] Based on this, this embodiment parses the service source file of the service code file type to determine the method node containing the service function, and uses the method node as the service node of the microservice unit, so as to determine the service role played by the microservice unit in the service call process of the whole microservice platform, so as to accurately determine the method node of circular dependency call.

[0077] Another embodiment of this application also provides a process for parsing and processing a service source file of service configuration type, specifically, the file type is a service configuration file type;

[0078] Accordingly, based on the file type, file parsing rules are determined, and the service source file of each microservice unit is parsed according to the file parsing rules to determine the service node of each microservice unit, including:

[0079] The configuration item parsing rules are determined based on the service configuration file type;

[0080] The service source file of each microservice unit is parsed according to the configuration item parsing rules to determine the service node of each microservice unit.

[0081] The configuration item parsing rules can be understood as the rules for parsing the project configuration file in each microservice unit to obtain configuration item information corresponding to each type of method.

[0082] In practical applications, when the executing entity determines that the service source file A is a service configuration file type, it can determine that the file parsing rule corresponding to the service source file A is the configuration item parsing rule, and then parse the service source file A according to the configuration item parsing rule, thereby determining each service node in the microservice unit.

[0083] Furthermore, the executing entity only needs to traverse all configuration file information to determine whether it contains configuration items for service declarations, thereby determining the service nodes of each microservice unit; specifically, the step of parsing the service source file of each microservice unit according to the configuration item parsing rules to determine the service node of each microservice unit includes:

[0084] The service source file of each microservice unit is parsed according to the configuration item parsing rules to determine the configuration item information containing service declarations in each service source file;

[0085] The method corresponding to the configuration item information in each service source file is identified as the service node of each microservice unit.

[0086] In practical applications, the execution entity can parse the service source file of each microservice unit according to the configuration item parsing rules. This service source file can be a project configuration file. Therefore, the execution entity can traverse all the information content in the project configuration file, find the configuration item information with service declarations, and identify the method corresponding to the configuration item information as the service node of each microservice unit. It should be noted that the project configuration file includes various method declarations, configurations, parameters, and other information. Therefore, configuration items with service declarations can be found in the project configuration file to determine the method that provides the service, and thus determine the service node of each microservice unit.

[0087] It is important to emphasize that the above-mentioned scanning and parsing of two types of service source files in all microservice units to obtain the corresponding service nodes can be performed in parallel or sequentially. The results of these two methods of determining service nodes can complement each other. In other words, the service nodes determined from the service source files of the service code file type and the service nodes determined from the service source files of the service configuration file type can complement each other in order to more comprehensively determine all service nodes of the microservice unit and avoid missed detections of circular dependencies in subsequent operations.

[0088] Step 206: Based on the service nodes of each microservice unit, construct a simplified directed graph for each microservice unit.

[0089] In this context, a directed graph is a graph consisting of vertices and directed edges. The simplified directed graph in this embodiment can be understood as a directed graph consisting of the service nodes of each microservice unit as vertices and the service call relationships between the service units as edges.

[0090] In practical applications, in order to detect circular dependency calls between service nodes in a microservice unit, after the execution entity determines the service node of each microservice unit in the above manner, it can construct a simplified directed graph of the microservice unit for each service node. This facilitates the subsequent determination of whether circular dependency calls exist between the microservice units based on the simplified directed graph of each microservice unit.

[0091] Furthermore, the simplified directed graph of each microservice unit is derived from the simplified directed graph of call relationships constructed from all method nodes of the microservice unit; specifically, constructing the simplified directed graph of each microservice unit based on its service nodes includes:

[0092] Parse the service source file of each microservice unit to determine the initial call relationship directed graph of each microservice unit;

[0093] Based on the initial call relationship directed graph of each microservice unit and the service nodes of each microservice unit, a simplified directed graph of each microservice unit is constructed.

[0094] The initial directed graph of call relationships includes method nodes in each microservice unit and the call relationships between method nodes. The method nodes include service nodes and non-service nodes. The simplified directed graph includes service nodes in each microservice unit and the call relationships between service nodes.

[0095] The initial call relationship directed graph can be understood as a directed graph composed of all method nodes in each microservice unit and the call relationships between method nodes.

[0096] In practical applications, the executing entity can determine the method nodes in each service source file and the call relationships between them by parsing the service source file of each microservice unit, thereby generating an initial directed graph of call relationships for the service source file. Further, the service nodes and call relationships between them in the initial directed graph of each microservice unit are copied to construct a simplified directed graph for each microservice unit. The initial directed graph includes multiple method nodes and their call relationships; nodes with service identifiers are identified as service nodes, while those without are identified as non-service nodes. The simplified directed graph only contains method nodes with service identifiers (i.e., service nodes) and their call relationships.

[0097] It should be noted that the process of generating a simplified directed graph from the initial directed graph of call relationships will retain all service nodes in the initial directed graph of call relationships, as well as the call relationships between all service nodes. If two service nodes have a call relationship in the initial directed graph of call relationships, the corresponding call relationship will also be retained in the simplified directed graph.

[0098] Furthermore, the construction of a simplified directed graph for each microservice unit based on the initial call relationship directed graph of each microservice unit and the service nodes of each microservice unit includes:

[0099] Traverse each method node in the directed graph of the initial call relationship of each microservice unit, and extract the service nodes with service identifiers and service call relationships in each microservice unit;

[0100] Based on the service nodes and the service call relationships, a simplified directed graph is constructed for each microservice unit.

[0101] In practical applications, the executing entity can traverse each method node in the initial call relationship directed graph corresponding to each microservice unit to determine whether it is a service node with a service identifier, so as to extract the corresponding service node and the service call relationship between each service node, and then construct a simplified directed graph for each microservice unit.

[0102] For example, select any method node A in the initial directed graph of call relationships, and start a depth-first traversal from method node A. If the visited method node B has a service identifier, it is a service node B. Then, service node B can be copied to the simplified directed graph. If there is a recently visited service node C with a service identifier, and service node C has a call relationship with service node B, then create a directed edge from service node C to service node B and insert it into the simplified directed graph. Save service node B as the service node with the most recently visited service identifier. If the visited method node does not have a service identifier, skip it. Mark the visited method node as visited. Repeat the above operation until all method nodes are marked as visited.

[0103] See below Figure 3a , Figure 3b as well as Figure 3c These are schematic diagrams illustrating the process of generating simplified directed graphs for the circular dependency detection process of a microservice platform applied to an e-commerce platform, including generating simplified directed graphs for the account module, order module, and inventory module.

[0104] Specifically, Figure 3a A schematic diagram illustrating the generation of a simplified directed graph for the account module in a circular dependency detection method based on a microservice platform.

[0105] Figure 3a The upper part is the directed graph of the account module, that is, the directed graph of the initial call relationship, which includes all method nodes of the microservice unit of the account module. Among them, the three method nodes user#query, user#modify and order#modify have the "service provider" identifier, so these three method nodes are service nodes. The other three method nodes are non-service nodes. The arrows indicate the service call relationship. Figure 3a The lower half is a simplified directed graph of the account module, which retains only three service nodes with "service provider identifiers" and the service call relationships between the service nodes.

[0106] Specifically, Figure 3b A schematic diagram illustrating the generation of a simplified directed graph for the order module using a circular dependency detection method based on a microservices platform.

[0107] Figure 3bThe upper part is the directed graph of the order module, that is, the directed graph of the initial call relationship, which includes all method nodes of the microservice unit of the order module. Among them, the five method nodes of order#save, user#query, user#modify, order#modify and stock#modify have the "service provider" identifier, so these five method nodes are service nodes. The other two method nodes are non-service nodes. The arrows indicate the service call relationship. Figure 3b The lower half is a simplified directed graph of the order module, which retains only five service nodes with the "service provider" identifier, as well as the service call relationships between the service nodes.

[0108] Specifically, Figure 3c A schematic diagram illustrating the generation of a simplified directed graph for the inventory module in a circular dependency detection method based on a microservices platform.

[0109] Figure 3c The upper part is the directed graph of the inventory module, that is, the directed graph of the initial call relationship, which includes all method nodes of the inventory module microservice unit. Among them, the three method nodes stock#query, stock#modify and user#modify have the "service provider" identifier, so these three method nodes are service nodes. The other two method nodes are non-service nodes. The arrows indicate the service call relationship. Figure 3c The lower half is a simplified directed graph of the inventory module, which retains only three service nodes with the "service provider" identifier, as well as the service call relationships between the service nodes.

[0110] The above three simplified directed graphs illustrate that each simplified directed graph contains only service nodes and the calling relationships between service nodes.

[0111] Step 208: Generate the target directed graph of the microservice platform based on the simplified directed graph of each microservice unit.

[0112] The target directed graph can be understood as a merged directed graph resulting from merging multiple simplified directed graphs.

[0113] In practical applications, the executing entity can merge the simplified directed graphs of each microservice unit to generate the target directed graph of the microservice platform, thereby realizing the process of visually representing all service nodes in the microservice platform and the calling relationships between service nodes.

[0114] Specifically, generating the target directed graph of the microservice platform based on the simplified directed graph of each microservice unit includes:

[0115] Read the simplified directed graph of each microservice unit to determine the target service node and target service call relationship of the microservice platform;

[0116] Based on the target service node and the target service call relationship, a target directed graph of the microservice platform is generated.

[0117] In practical applications, the execution entity can traverse and read the simplified directed graph of each microservice unit, select the simplified directed graph containing a large number of service nodes as the directed graph to be processed, and then compare the service nodes and the call relationships between service nodes in each simplified directed graph. If the corresponding service node exists in the directed graph to be processed, it is skipped; if the corresponding service node does not exist in the directed graph to be processed, the service node is copied into the directed graph to be processed. The call relationships between service nodes can also be obtained in this way. Finally, the process of merging all simplified directed graphs is completed to generate the target directed graph of the microservice platform.

[0118] It should be noted that the above merging method is only one implementation method, and other processing methods for merging multiple simplified directed graphs may also be included. This embodiment does not limit this in any way.

[0119] See Figure 4 , Figure 4 This illustration shows a schematic diagram of the circular dependency detection method based on a microservice platform for e-commerce platforms, provided in this embodiment, generating a merged directed graph.

[0120] Figure 4 For the above Figure 3a , Figure 3b as well as Figure 3c The merged directed graph is the result of merging the three simplified directed graphs. It includes all service nodes from the three simplified directed graphs, as well as the call relationships between all service nodes; it should be noted that... Figure 4 The service node `stock#query` in the three simplified directed graphs mentioned above does not have any service call relationships with other service nodes. Therefore, it will also not have any call relationships with other service nodes in the merged directed graph after merging the simplified directed graphs. Furthermore, the other service nodes can generate the merged directed graph based on their respective call relationships, and then circular dependency detection can be performed based on the merged directed graph.

[0121] Step 210: Perform circular dependency detection on the microservice platform based on the target directed graph to obtain the circular dependency detection result.

[0122] In practical applications, in order to detect whether there are circular dependencies between service nodes in a microservice platform, the target directed graph can be used for detection to determine the calling relationship between service nodes, that is, the relationship between each edge in the target directed graph, and thus obtain the circular dependency detection result for the microservice platform.

[0123] Furthermore, the step of performing circular dependency detection on the microservice platform based on the target directed graph to obtain the circular dependency detection result includes:

[0124] Based on a preset node cycle path detection rule, the target directed graph is subjected to cycle path detection to obtain the target cycle path of the target directed graph.

[0125] The circular dependency detection result of the microservice platform is generated based on the target ring path, wherein the circular dependency detection result includes the ring service nodes of the target ring path and the ring service call relationship.

[0126] The preset node cycle path detection rule can be understood as the rule for detecting directed cycles in the target directed graph, i.e., the algorithm for finding cycles, such as the Johnson algorithm. This embodiment does not limit this in any way.

[0127] In practical applications, the executing entity uses preset node path switching detection rules to perform cycle path detection on the target directed graph to determine whether a target cycle path exists in the target directed graph. If a target cycle path exists, it indicates that there is a circular call dependency in the microservice platform; if no target cycle path exists, it indicates that there is no circular call dependency in the microservice platform. It should be noted that a cycle path can be understood as the path composed of the service nodes that form a directed cycle in the target directed graph. Furthermore, after obtaining the target cycle path of the target directed graph, the circular dependency detection results of the microservice platform are generated based on the target cycle path, thus obtaining all existing circular dependencies in the microservice platform.

[0128] Furthermore, to facilitate developers in identifying circular dependency calls and directly locating the source code file or line number, thus helping them quickly fix system defects, the circular dependency detection results can also be stored. Specifically, after obtaining the circular dependency detection results by performing circular dependency detection on the microservice platform based on the target directed graph, the process further includes:

[0129] Store the ring service nodes and ring service call relationships of the target ring path.

[0130] In practical applications, the executing entity can store the ring service nodes and ring service call relationships in the target ring path in the database. Here, the ring service node can be understood as the service node that has a circular dependency call relationship, and the ring service call relationship can be understood as the circular dependency call relationship between service nodes.

[0131] In summary, the circular dependency detection device based on a microservice platform provided in this application obtains the service source files of each microservice unit in the microservice platform, parses the service source files to determine the service nodes providing services in each microservice unit, constructs a corresponding simplified directed graph for each service node in the microservice unit, and finally merges the simplified directed graphs corresponding to each microservice unit in the microservice platform to obtain a target directed graph. This allows for the detection of circular dependencies in the entire microservice platform from the target directed graph. In this way, without intruding on the existing code of the entire microservice platform, the microservice platform can complete the detection of circular dependencies in service calls without requesting services during the development phase. This not only avoids the problem of manual omissions but also improves the accuracy of circular dependency detection and reduces the cost of system defect repair and rollback.

[0132] Corresponding to the above method embodiments, this application also provides an embodiment of a circular dependency detection device based on a microservice platform. Figure 5 The diagram shows a schematic of a circular dependency detection device based on a microservice platform according to an embodiment of this application.

[0133] like Figure 5 As shown, the device includes:

[0134] The source file acquisition module 502 is configured to acquire the service source file of each microservice unit in the microservice platform in response to a circular dependency detection request for the microservice platform.

[0135] The source file parsing module 504 is configured to parse the service source file of each microservice unit and determine the service node of each microservice unit;

[0136] The first construction module 506 is configured to construct a simplified directed graph of each microservice unit based on the service nodes of each microservice unit;

[0137] The second construction module 508 is configured to generate the target directed graph of the microservice platform based on the simplified directed graph of each microservice unit;

[0138] The dependency detection module 510 is configured to perform circular dependency detection on the microservice platform based on the target directed graph and obtain the circular dependency detection result.

[0139] Optionally, the source file parsing module 504 is further configured as follows:

[0140] Determine the file type of the service source file for each microservice unit;

[0141] Based on the file type, file parsing rules are determined, and the service source files of each microservice unit are parsed according to the file parsing rules to determine the service node of each microservice unit.

[0142] Optionally, the file type is a service code file type;

[0143] Optionally, the source file parsing module 504 is further configured as follows:

[0144] The syntax structure parsing rules are determined based on the service code file type;

[0145] The service source file of each microservice unit is parsed according to the syntax structure parsing rules to determine the service node of each microservice unit.

[0146] Optionally, the source file parsing module 504 is further configured as follows:

[0147] The service source file of each microservice unit is parsed according to the syntax structure parsing rules to determine the method node tree of each service source file;

[0148] The method nodes with service identifiers in each method node tree are identified as the service nodes of each microservice unit, wherein the service identifiers include service declaration identifiers and service reference identifiers.

[0149] Optionally, the file type is a service configuration file type;

[0150] Optionally, the source file parsing module 504 is further configured as follows:

[0151] The configuration item parsing rules are determined based on the service configuration file type;

[0152] The service source file of each microservice unit is parsed according to the configuration item parsing rules to determine the service node of each microservice unit.

[0153] Optionally, the source file parsing module 504 is further configured as follows:

[0154] The service source file of each microservice unit is parsed according to the configuration item parsing rules to determine the configuration item information containing service declarations in each service source file;

[0155] The method corresponding to the configuration item information in each service source file is identified as the service node of each microservice unit.

[0156] Optionally, the first building module 506 is further configured to:

[0157] Parse the service source file of each microservice unit to determine the initial call relationship directed graph of each microservice unit;

[0158] Based on the initial call relationship directed graph of each microservice unit and the service nodes of each microservice unit, a simplified directed graph of each microservice unit is constructed.

[0159] The initial directed graph of call relationships includes method nodes in each microservice unit and the call relationships between method nodes. The method nodes include service nodes and non-service nodes. The simplified directed graph includes service nodes in each microservice unit and the call relationships between service nodes.

[0160] Optionally, the first building module 506 is further configured to:

[0161] Traverse each method node in the directed graph of the initial call relationship of each microservice unit, and extract the service nodes with service identifiers and service call relationships in each microservice unit;

[0162] Based on the service nodes and the service call relationships, a simplified directed graph is constructed for each microservice unit.

[0163] Optionally, the second building module 508 is further configured as follows:

[0164] Read the simplified directed graph of each microservice unit to determine the target service node and target service call relationship of the microservice platform;

[0165] Based on the target service node and the target service call relationship, a target directed graph of the microservice platform is generated.

[0166] Optionally, the dependency detection module 510 is further configured to:

[0167] Based on a preset node cycle path detection rule, the target directed graph is subjected to cycle path detection to obtain the target cycle path of the target directed graph.

[0168] The circular dependency detection result of the microservice platform is generated based on the target ring path, wherein the circular dependency detection result includes the ring service nodes of the target ring path and the ring service call relationship.

[0169] Optionally, the device further includes a storage module, which is further configured to:

[0170] Store the ring service nodes and ring service call relationships of the target ring path.

[0171] The circular dependency detection device based on a microservice platform provided in this application obtains the service source files of each microservice unit in the microservice platform, parses the service source files to determine the service nodes providing services in each microservice unit, constructs a corresponding simplified directed graph for the service nodes in each microservice unit, and finally merges the simplified directed graphs corresponding to each microservice unit in the microservice platform to obtain a target directed graph. This allows for the detection of circular dependencies in the entire microservice platform from the target directed graph. In this way, without intruding on the existing code of the entire microservice platform, the microservice platform can complete the detection of circular dependencies in service calls without requesting services during the development phase. This not only avoids the problem of manual omissions but also improves the accuracy of circular dependency detection and reduces the cost of system defect repair and rollback.

[0172] The above is an illustrative scheme of a circular dependency detection device based on a microservice platform according to this embodiment. It should be noted that the technical solution of this circular dependency detection device based on a microservice platform and the technical solution of the circular dependency detection method based on a microservice platform described above belong to the same concept. For details not described in detail in the technical solution of the circular dependency detection device based on a microservice platform, please refer to the description of the technical solution of the circular dependency detection method based on a microservice platform described above.

[0173] Figure 6 A structural block diagram of a computing device 600 according to an embodiment of this application is shown. The components of the computing device 600 include, but are not limited to, a memory 610 and a processor 620. The processor 620 is connected to the memory 610 via a bus 630, and a database 650 is used to store data.

[0174] The computing device 600 also includes an access device 640, which enables the computing device 600 to communicate via one or more networks 660. Examples of these networks include a Public Switched Telephone Network (PSTN), a Local Area Network (LAN), a Wide Area Network (WAN), a Personal Area Network (PAN), or a combination of communication networks such as the Internet. The access device 640 may include one or more of any type of wired or wireless network interface (e.g., a Network Interface Card (NIC)), such as an IEEE 802.11 Wireless Local Area Network (WLAN) interface, a Wi-MAX interface, an Ethernet interface, a Universal Serial Bus (USB) interface, a cellular network interface, a Bluetooth interface, a Near Field Communication (NFC) interface, and so on.

[0175] In one embodiment of this application, the aforementioned components of the computing device 600 and Figure 6 Other components, not shown, can also be connected to each other, for example, via a bus. It should be understood that... Figure 6 The block diagram of the computing device shown is for illustrative purposes only and is not intended to limit the scope of this application. Those skilled in the art can add or replace other components as needed.

[0176] The computing device 600 can be any type of stationary or mobile computing device, including mobile computers or mobile computing devices (e.g., tablet computers, personal digital assistants, laptop computers, notebook computers, netbooks, etc.), mobile phones (e.g., smartphones), wearable computing devices (e.g., smartwatches, smart glasses, etc.) or other types of mobile devices, or stationary computing devices such as desktop computers or PCs. The computing device 600 can also be a mobile or stationary server.

[0177] Specifically, the processor 620 implements the steps of the circular dependency detection method based on the microservice platform when executing the computer instructions.

[0178] The above is an illustrative scheme of a computing device according to this embodiment. It should be noted that the technical solution of this computing device belongs to the same concept as the technical solution of the circular dependency detection method based on the microservice platform described above. For details not described in detail in the technical solution of the computing device, please refer to the description of the technical solution of the circular dependency detection method based on the microservice platform described above.

[0179] An embodiment of this application also provides a computer-readable storage medium storing computer instructions that, when executed by a processor, implement the steps of the circular dependency detection method based on a microservice platform as described above.

[0180] The above is an illustrative scheme of a computer-readable storage medium according to this embodiment. It should be noted that the technical solution of this storage medium belongs to the same concept as the technical solution of the circular dependency detection method based on the microservice platform described above. For details not described in detail in the technical solution of the storage medium, please refer to the description of the technical solution of the circular dependency detection method based on the microservice platform described above.

[0181] The foregoing has described specific embodiments of this application. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims may be performed in a different order than that shown in the embodiments and may still achieve the desired results. Furthermore, the processes depicted in the drawings do not necessarily require the specific or sequential order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0182] The computer instructions include computer program code, which may be in the form of source code, object code, executable file, or some intermediate form. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording media, USB flash drive, portable hard drive, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signals, telecommunication signals, and software distribution media, etc. It should be noted that the content included in the computer-readable medium may be appropriately added to or subtracted according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media may not include electrical carrier signals and telecommunication signals.

[0183] It should be noted that, for the sake of simplicity, the foregoing method embodiments are all described as a series of actions. However, those skilled in the art should understand that this application is not limited to the described order of actions, as some steps may be performed in other orders or simultaneously according to this application. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are preferred embodiments, and the actions and modules involved are not necessarily essential to this application.

[0184] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions of other embodiments.

[0185] The preferred embodiments disclosed above are merely illustrative of this application. The optional embodiments do not exhaustively describe all details, nor do they limit the invention to the specific implementations described. Clearly, many modifications and variations can be made based on the content of this application. These embodiments are selected and specifically described in this application to better explain the principles and practical applications of this application, thereby enabling those skilled in the art to better understand and utilize this application. This application is limited only by the claims and their full scope and equivalents.

Claims

1. A method for detecting circular dependencies based on a microservice platform, characterized in that, include: In response to a circular dependency detection request for the microservice platform, the service source file of each microservice unit in the microservice platform is obtained; Parse the service source file of each microservice unit to determine the service node and initial call relationship directed graph of each microservice unit; Based on the initial call relationship directed graph of each microservice unit and the service nodes of each microservice unit, a simplified directed graph of each microservice unit is constructed. The initial call relationship directed graph includes the method nodes in each microservice unit and the call relationships between the method nodes. The method nodes include service nodes and non-service nodes. The simplified directed graph includes the service nodes in each microservice unit and the call relationships between the service nodes. Based on the simplified directed graph of each microservice unit, a target directed graph of the microservice platform is generated, wherein the target directed graph is a merged directed graph obtained by merging each simplified directed graph. Based on the target directed graph, the microservice platform is subjected to circular dependency detection to obtain the circular dependency detection results.

2. The method according to claim 1, characterized in that, The step of parsing the service source file of each microservice unit and determining the service node of each microservice unit includes: Determine the file type of the service source file for each microservice unit; Based on the file type, file parsing rules are determined, and the service source files of each microservice unit are parsed according to the file parsing rules to determine the service node of each microservice unit.

3. The method according to claim 2, characterized in that, The file type is a service code file type; Accordingly, based on the file type, file parsing rules are determined, and the service source file of each microservice unit is parsed according to the file parsing rules to determine the service node of each microservice unit, including: The syntax structure parsing rules are determined based on the service code file type; The service source file of each microservice unit is parsed according to the syntax structure parsing rules to determine the service node of each microservice unit.

4. The method according to claim 3, characterized in that, The step of parsing the service source file of each microservice unit according to the syntax structure parsing rules to determine the service node of each microservice unit includes: The service source file of each microservice unit is parsed according to the syntax structure parsing rules to determine the method node tree of each service source file; The method nodes with service identifiers in each method node tree are identified as the service nodes of each microservice unit, wherein the service identifiers include service declaration identifiers and service reference identifiers.

5. The method according to claim 2, characterized in that, The file type is a service configuration file type; Accordingly, based on the file type, file parsing rules are determined, and the service source file of each microservice unit is parsed according to the file parsing rules to determine the service node of each microservice unit, including: The configuration item parsing rules are determined based on the service configuration file type; The service source file of each microservice unit is parsed according to the configuration item parsing rules to determine the service node of each microservice unit.

6. The method according to claim 5, characterized in that, The step of parsing the service source file of each microservice unit according to the configuration item parsing rules to determine the service node of each microservice unit includes: The service source file of each microservice unit is parsed according to the configuration item parsing rules to determine the configuration item information containing service declarations in each service source file; The method corresponding to the configuration item information in each service source file is identified as the service node of each microservice unit.

7. The method according to claim 1, characterized in that, The construction of a simplified directed graph for each microservice unit, based on the initial call relationship directed graph of each microservice unit and the service nodes of each microservice unit, includes: Traverse each method node in the directed graph of the initial call relationship of each microservice unit, and extract the service nodes with service identifiers and service call relationships in each microservice unit; Based on the service nodes and the service call relationships, a simplified directed graph is constructed for each microservice unit.

8. The method according to claim 1, characterized in that, The step of generating the target directed graph of the microservice platform based on the simplified directed graph of each microservice unit includes: Read the simplified directed graph of each microservice unit to determine the target service node and target service call relationship of the microservice platform; Based on the target service node and the target service call relationship, a target directed graph of the microservice platform is generated.

9. The method according to claim 1, characterized in that, The step of performing circular dependency detection on the microservice platform based on the target directed graph to obtain circular dependency detection results includes: Based on a preset node cycle path detection rule, the target directed graph is subjected to cycle path detection to obtain the target cycle path of the target directed graph. The circular dependency detection result of the microservice platform is generated based on the target ring path, wherein the circular dependency detection result includes the ring service nodes of the target ring path and the ring service call relationship.

10. The method according to claim 9, characterized in that, After performing circular dependency detection on the microservice platform based on the target directed graph and obtaining the circular dependency detection result, the method further includes: Store the ring service nodes and ring service call relationships of the target ring path.

11. A circular dependency detection device based on a microservice platform, characterized in that, include: The source file acquisition module is configured to acquire the service source file of each microservice unit in the microservice platform in response to a circular dependency detection request for the microservice platform. The source file parsing module is configured to parse the service source file of each microservice unit and determine the service node and initial call relationship directed graph of each microservice unit. The first construction module is configured to construct a simplified directed graph for each microservice unit based on the initial call relationship directed graph of each microservice unit and the service nodes of each microservice unit. The initial call relationship directed graph includes the method nodes in each microservice unit and the call relationships between the method nodes. The method nodes include service nodes and non-service nodes. The simplified directed graph includes the service nodes in each microservice unit and the call relationships between the service nodes. The second construction module is configured to generate a target directed graph of the microservice platform based on the simplified directed graph of each microservice unit, wherein the target directed graph is a merged directed graph after merging each simplified directed graph; The dependency detection module is configured to perform circular dependency detection on the microservice platform based on the target directed graph and obtain the circular dependency detection result.

12. A computing device, comprising a memory, a processor, and computer instructions stored in the memory and executable on the processor, characterized in that, When the processor executes the computer instructions, it implements the steps of the method according to any one of claims 1-10.

13. A computer-readable storage medium storing computer instructions, characterized in that, When executed by a processor, the computer instructions implement the steps of the method according to any one of claims 1-10.