Micro-service log retrieval method, system, control device and storage medium
By determining the execution server to process log information in parallel based on the service call chain in a microservice architecture, the high operation and maintenance costs and low retrieval efficiency of traditional end-to-end log retrieval solutions are solved, achieving efficient log retrieval and problem localization.
Patent Information
- Application Number
- CN202211004887.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-22
- Publication Date
- 2026-01-30
- Estimated Expiration
- 2042-08-22
AI Technical Summary
Traditional end-to-end log retrieval solutions involve numerous components, resulting in high operation and maintenance costs and low retrieval efficiency.
By obtaining the log retrieval request of the target task, the execution server corresponding to each microservice is determined according to the service call chain, and log retrieval requests are sent to these servers to extract and sort the target log information stored on the execution server. Parallel processing is then performed directly on the execution server to obtain the full-link log of the target task.
It simplifies the retrieval process, reduces operation and maintenance costs, improves retrieval efficiency, and reduces log dump management costs, making it suitable for lightweight business scenarios under a microservice architecture.
Smart Images

Figure CN115344533B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of data processing technology, and in particular to a microservice log retrieval method, system, control device, and storage medium. Background Technology
[0002] As intelligent systems become increasingly complex and microservices technology develops, more and more enterprises are using microservice architectures to conduct business and reduce the risk of global failures in intelligent systems. In a distributed microservice architecture, a task is typically broken down into multiple microservices, which are usually deployed on multiple servers to execute. The complete task flow involves processing and transmission through many microservices, making the call chains between microservices quite complex. Therefore, when analyzing task logs for problem resolution, it is necessary to obtain the complete log of the task.
[0003] Traditional end-to-end log retrieval solutions require adding a series of components to complete the entire log retrieval process. Typically, this involves using third-party middleware (such as Kafka, Logstash, or Beats) to collect log data from various servers in a microservice architecture, centrally storing it in a third-party query database (such as Elasticsearch or MySQL), and then using a front-end query interface (Kibana, Grafana) to perform log retrieval. The overall log query process involves numerous components and a complex log flow chain, resulting in high operational costs and low retrieval efficiency. Summary of the Invention
[0004] This invention provides a microservice log retrieval method, system, control device, and storage medium to solve the problems of high operation and maintenance costs and low retrieval efficiency caused by the large number of components and complex log flow chain involved in the log query process in traditional end-to-end log retrieval schemes.
[0005] A method for retrieving microservice logs is provided, including:
[0006] Obtain the log retrieval request for the target task, which includes the tracking identifier of the target task;
[0007] The execution server corresponding to each microservice is determined based on the service call chain of the target task. The service call chain is the execution order of multiple microservices required to execute the target task.
[0008] Send log retrieval requests to each execution server so that each execution server can extract the target log information stored on the execution server according to the tracing identifier and feed back the target log information to the microservice control device;
[0009] Based on the recording time of each target log information, the target log information on each execution server is sorted to obtain the full-link log of the target task.
[0010] Furthermore, before obtaining the log retrieval request for the target task, the method also includes:
[0011] Identify the multiple microservices required to execute the target task and assign a corresponding execution server to each microservice;
[0012] Identify the tracing identifier for the target task and generate a service request containing the tracing identifier based on the microservice;
[0013] Send corresponding service requests to each execution server so that each execution server responds to the service request and executes the corresponding microservice, and records the execution process of the microservice to form log information, which carries a tracking identifier.
[0014] Furthermore, before obtaining the log retrieval request for the target task, the method also includes:
[0015] Identify the tracking identifier of the target task, and generate a task request for the target task based on the target task and the tracking identifier;
[0016] A task request is sent to the first execution server so that the first execution server responds to the service request, executes the target task, and records the execution process of the target task to form log information, which carries a tracking identifier.
[0017] Furthermore, before determining the execution server corresponding to each microservice based on the service call chain of the target task, the method also includes:
[0018] Determine if the service call chain for the target task can be obtained;
[0019] If the service call chain can be obtained, then obtain the service call chain and determine the execution server corresponding to each microservice based on the service call chain of the target task.
[0020] Furthermore, after determining whether the service call chain of the target task can be obtained, the method also includes:
[0021] If the service call chain cannot be obtained, determine the first execution server that receives the task request for the target task sent by the microservice controller.
[0022] Send a log retrieval request to the first execution server so that the first execution server can extract the target log information stored on the first execution server according to the tracking identifier, and receive the target log information fed back by the first execution server.
[0023] A microservice system is provided, including a microservice control unit and multiple execution servers. The microservice control unit is specifically used for:
[0024] Obtain the log retrieval request for the target task, which includes the tracking identifier of the target task;
[0025] The execution server corresponding to each microservice is determined based on the service call chain of the target task. The service call chain is the execution order of multiple microservices required to execute the target task.
[0026] Send log retrieval requests to each execution server so that each execution server can extract the target log information stored on the execution server according to the tracing identifier and feed back the target log information to the microservice control device;
[0027] Based on the recording time of each target log information, the target log information on each execution server is sorted to obtain the full-link log of the target task.
[0028] Furthermore, the execution server is specifically used for:
[0029] Receive log retrieval requests sent by the microservice control device and extract the tracing identifier from the log retrieval requests;
[0030] Retrieve server operation log data from the server's database. The server operation log data includes multiple sets of task log data. Each set of task log data includes the tracking identifier of each task and the log information of the server executing the task.
[0031] Multiple sets of task log data are matched with tracking identifiers to obtain the log information corresponding to the tracking identifiers, which is then used as the target log information.
[0032] Furthermore, before determining the execution server corresponding to each microservice based on the service call chain of the target task, the microservice control device is specifically used for:
[0033] Determine if the service call chain for the target task can be obtained;
[0034] If the service call chain can be obtained, then obtain the service call chain and determine the execution server corresponding to each microservice based on the service call chain of the target task.
[0035] A microservice control device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the steps of the microservice log retrieval method described above.
[0036] Provide one or more readable storage media, which store a computer program that, when executed by a processor, implements the steps of the microservice log retrieval method described above.
[0037] In one solution provided by the aforementioned microservice log retrieval method, system, control device, and storage medium, a log retrieval request for a target task is obtained. This request includes a trace identifier for the target task. Then, the execution server corresponding to each microservice is determined based on the service call chain of the target task. The service call chain represents the execution order of multiple microservices required to execute the target task. Log retrieval requests are then sent to each execution server, enabling them to extract the target log information stored on their respective servers based on the trace identifier. Finally, the target log information on each execution server is sorted according to its recording time to obtain the full-link log of the target task. In this invention, the execution nodes of each microservice are determined through the service call chain. The node log retrieval work for all microservices is then distributed to each node for parallel and independent processing. Finally, the logs are aggregated and sorted to obtain the full-link log information. Compared to traditional full-link log retrieval schemes, this method simplifies the retrieval process, eliminates the need for additional components, reduces operational costs, and improves retrieval efficiency. Attached Figure Description
[0038] To more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the description of the embodiments of the present invention will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0039] Figure 1 This is a schematic diagram of an application environment for a microservice log retrieval method according to an embodiment of the present invention;
[0040] Figure 2 This is a flowchart illustrating a microservice log retrieval method according to an embodiment of the present invention;
[0041] Figure 3 yes Figure 2 A schematic diagram of the implementation process of step S40;
[0042] Figure 4 yes Figure 2 A flowchart illustrating the process preceding step S10;
[0043] Figure 5 yes Figure 2 Another flowchart before step S10;
[0044] Figure 6 This is another flowchart illustrating the microservice log retrieval method in one embodiment of the present invention;
[0045] Figure 7 yes Figure 6 A flowchart following step S61;
[0046] Figure 8 yes Figure 7 A flowchart following step S65;
[0047] Figure 9 This is a schematic diagram of a microservice control device in one embodiment of the present invention;
[0048] Figure 10 This is a schematic diagram of the structure of a computer device according to an embodiment of the present invention. Detailed Implementation
[0049] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0050] The microservice log retrieval method provided in this embodiment of the invention can be applied to, for example... Figure 1 In this application environment, the client communicates with the microservice control device (server) via a network.
[0051] When a user needs to perform log retrieval, the user sends a log retrieval request to the microservice control device through the client. The microservice control device (server) obtains the log retrieval request for the target task, which includes the trace identifier of the target task. Then, based on the service call chain of the target task, it determines the execution server corresponding to each microservice. The service call chain is the execution order of multiple microservices required to execute the target task. The microservice control device then sends log retrieval requests to each execution server so that each execution server can extract the target log information stored on the execution server based on the trace identifier. Finally, based on the recording time of each target log information, the target log information on each execution server is sorted to obtain the full-link log of the target task. In this embodiment, the microservice control device determines the execution node of each microservice through the service call chain, and then distributes the node log retrieval work of all microservices to each node. The nodes perform parallel and independent processing, and finally, the full-link log information is obtained by summarizing and sorting. Compared with the traditional full-link log retrieval scheme, the retrieval process is simple, does not require the introduction of other components, reduces operation and maintenance costs, and improves retrieval efficiency, thereby improving the intelligence of log retrieval in the microservice system.
[0052] Meanwhile, traditional end-to-end log reduction solutions often require collecting and dumping log data from all execution servers before retrieval. The microservice log retrieval solution in this embodiment directly retrieves log information from the execution server itself, reducing log dumping management costs. It is more lightweight and concise, requiring no additional components and thus having no intrusion into the overall microservice architecture. Furthermore, it offers higher retrieval efficiency. Overall, the microservice log retrieval solution in this embodiment has greater applicability and lower usage costs for end-to-end log tracing and problem localization in lightweight business scenarios based on a microservice architecture.
[0053] The target task's tracking identifier and service call chain data are stored in the microservice control device's database, while the target log information on each execution server is stored in its own database. This allows for the direct retrieval of relevant data based on log retrieval requirements during subsequent log retrieval tasks, reducing data processing time and improving log retrieval efficiency.
[0054] In this embodiment, the database is stored in a blockchain network to store data used and generated in the microservice log retrieval method, such as the tracking identifier of the target task and the service call chain, as well as related data such as target log information. The blockchain referred to in this application is a novel application model of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanisms, and encryption algorithms. Essentially, a blockchain is a decentralized database, a chain of data blocks linked using cryptographic methods. Each data block contains information about a batch of network transactions, used to verify the validity of the information (anti-counterfeiting) and generate the next block. A blockchain can include a blockchain underlying platform, a platform product service layer, and an application service layer. Deploying the database on a blockchain can improve the security of data storage.
[0055] The client can be, but is not limited to, various personal computers, laptops, smartphones, tablets, and portable wearable devices. The microservice control unit (server-side) can be implemented using a standalone server or a server cluster consisting of multiple servers.
[0056] In one embodiment, a microservice system is provided, including a microservice control device and multiple execution servers, which are used to implement the steps of a microservice log retrieval method.
[0057] Specifically, the microservice control unit is used to: obtain log retrieval requests for the target task, including the target task's trace identifier; determine the execution servers corresponding to each microservice based on the target task's service call chain, where the service call chain is the execution order of multiple microservices required to execute the target task; send log retrieval requests to each execution server, enabling each execution server to extract the target log information stored on the execution server based on the trace identifier and feed back the target log information to the microservice control unit; and sort the target log information on each execution server according to the recording time of each target log information to obtain the full-link log of the target task. By distributing the node log retrieval work of all microservices to each node, and processing it in parallel and independently on each node, the final summary and sorting yields the full-link log information. Compared to traditional full-link log retrieval schemes, the retrieval process is simpler, requires no additional components, reduces operational costs, and improves retrieval efficiency.
[0058] Specifically, the microservice control device is used to: obtain the log retrieval request of the target task, the log retrieval request including the trace identifier of the target task; determine the execution server corresponding to each microservice according to the service call chain of the target task, the service call chain being the execution order of multiple microservices required to execute the target task; send the log retrieval request to each execution server, so that each execution server can extract the target log information stored on the execution server according to the trace identifier and feed back the target log information to the microservice control device; and sort the target log information on each execution server according to the recording time of each target log information to obtain the full-link log of the target task.
[0059] In one embodiment, such as Figure 2 As shown, a microservice log retrieval method is provided. Taking the application of this method in the aforementioned microservice system as an example, the method includes the following steps:
[0060] S10: The microservice controller obtains the log retrieval request for the target task.
[0061] When a user needs to retrieve logs, the user sends a log retrieval request to the microservice control device through the client. The microservice control device obtains the log retrieval request of the target task sent by the client. The log retrieval request of the target task includes the trace identifier of the target task.
[0062] S20: The microservice control unit determines the execution server corresponding to each microservice based on the service call chain of the target task.
[0063] The service call chain refers to the execution order of multiple microservices required to execute the target task, and includes the execution servers for each microservice. This service call chain can be stored in the database of the microservice control device. During the execution of the target task, as the task request is forwarded between execution servers, the call order and execution servers of each microservice are recorded, resulting in the service call chain of the target task. This service call chain is then stored in the database of the microservice control device for subsequent log queries. Alternatively, the service call chain can be obtained based on the microservice call order of the target task configured by the user. During the execution of the target task, the user configures multiple microservice calls for the target task and determines the call order and execution servers for each microservice, thereby obtaining the service call chain and storing it in the microservice control device. In other embodiments, the service call chain can also be the call chain of each microservice of the target task carried in the log retrieval request of the target task. In the log retrieval request, the service call chain is represented in the form of parameters. For example, the service call chain could be: getLog? service Names = ServiceA, ServiceB, indicating that the log information of execution servers ServiceA and ServiceB is specified for querying. In this embodiment, multiple methods for obtaining service call chains are provided. During the log retrieval process, the corresponding service call chain can be flexibly selected according to the actual situation, making the log retrieval process lighter and faster.
[0064] After the microservice controller obtains the log retrieval request of the target task, it extracts the service call chain of the target task from the database or the log retrieval request, and then determines the execution server corresponding to each microservice based on the service call chain of the target task.
[0065] S30: The microservice control unit sends log retrieval requests to each execution server.
[0066] After determining the execution server corresponding to each microservice based on the service call chain of the target task, the microservice control device sends a log retrieval request to each execution server.
[0067] S40: The execution server extracts the target log information stored on the execution server based on the trace identifier of the log retrieval request, and feeds back the target log information to the microservice control device.
[0068] After the microservice control unit sends log retrieval requests to each execution server, each execution server receives the log retrieval request and, based on the tracing identifier in the log retrieval request, extracts the log information corresponding to the tracing identifier stored on the execution server as the target log information and feeds it back to the microservice control unit. The log information carries a timestamp when it is generated and stored, indicating the time the log information was recorded.
[0069] S50: The microservice control unit sorts the target log information on each execution server according to the recording time of each target log information to obtain the full-link log of the target task.
[0070] The microservice control unit receives target log information from each execution server, and then sorts the target log information on each execution server according to the recording time of the target log information, to obtain the complete microservice call chain log in the target task, that is, the full-chain log of the target task.
[0071] When a user needs to perform log retrieval, the user sends a log retrieval request to the microservice control device through the client. The microservice control device (server) obtains the log retrieval request for the target task, which includes the trace identifier of the target task. Then, based on the service call chain of the target task, it determines the execution server corresponding to each microservice. The service call chain is the execution order of multiple microservices required to execute the target task. The microservice control device then sends log retrieval requests to each execution server so that each execution server can extract the target log information stored on the execution server based on the trace identifier. Finally, based on the recording time of each target log information, the target log information on each execution server is sorted to obtain the full-link log of the target task. In this embodiment, the microservice control device determines the execution node of each microservice through the service call chain, and then distributes the node log retrieval work of all microservices to each node. The nodes perform parallel and independent processing, and finally, the full-link log information is obtained by summarizing and sorting. Compared with the traditional full-link log retrieval scheme, the retrieval process is simple, does not require the introduction of other components, reduces operation and maintenance costs, and improves retrieval efficiency, thereby improving the intelligence of log retrieval in the microservice system.
[0072] Meanwhile, traditional end-to-end log reduction solutions often require collecting and dumping log data from all execution servers before retrieval. The microservice log retrieval solution in this embodiment directly retrieves log information from the execution server itself, reducing log dumping management costs. It is more lightweight and concise, requiring no additional components and thus having no intrusion into the overall microservice architecture. Furthermore, it offers higher retrieval efficiency. Overall, the microservice log retrieval solution in this embodiment has greater applicability and lower usage costs for end-to-end log tracing and problem localization in lightweight business scenarios based on a microservice architecture.
[0073] In other embodiments, after the microservice control device obtains the service call chain of the target task, it does not need to determine all execution servers and send the log retrieval request to all servers. The microservice control device only needs to determine the first execution server in the service call chain, i.e., the first execution server, and then send the log retrieval request to the first execution server. After receiving the log retrieval request, the first execution server extracts the log information corresponding to the tracing identifier in its own database as the target log information based on the tracing identifier. At the same time, it also extracts the service call chain of its own corresponding microservice based on the tracing identifier. If it finds that it has called other servers during the execution of the corresponding microservice, it sends a log retrieval request to the other called servers (the second execution server) so that the other called servers can extract the target log information based on the log retrieval request and determine that they have called other servers during the execution of the corresponding microservice, until the entire service call chain of the target task is retrieved, i.e., until all execution servers of the target task have been traversed. In this retrieval process, each execution server extracts the target log information and obtains the target log information fed back by the next node (i.e., the next execution server). Then, it feeds back the extracted target log information to the previous node (i.e., the previous execution server), and so on, until the root node (i.e., the first execution server) receives the target log information fed back by all execution servers. The root node then sends all the received target log information to the microservice control device, allowing the microservice control device to sort the target log information on each execution server according to the recording time of each target log information, thus obtaining the full-link log of the target task. In this embodiment, the microservice control device only needs to determine which execution server sends the log retrieval request and receive all the target log information fed back by that execution server. Each execution server executes its own node's log retrieval task, reducing the communication process between the microservice control device and other servers, and reducing the load on the microservice control device.
[0074] In one embodiment, such as Figure 3 As shown, step S40, which involves extracting the target log information stored on the execution server based on the tracing identifier, specifically includes the following steps:
[0075] S41: The execution server receives the log retrieval request sent by the microservice control device and extracts the trace identifier from the log retrieval request.
[0076] After the microservice control unit sends log retrieval requests to each execution server, each execution server receives the log retrieval request and extracts a trace identifier from it. This trace identifier is then used to retrieve the target log information stored in the execution server's database. The log information carries a timestamp, indicating the recording time, during its generation and storage.
[0077] S42: The execution server retrieves server runtime log data from its database.
[0078] After extracting the trace identifier from the log retrieval request, the execution server retrieves its server operation log data from its database. This execution server can run different tasks, each with its own corresponding task log information. Therefore, for ease of subsequent querying and management, the trace identifier for each task needs to be bound to its corresponding task log information, forming a set of task log data. In other words, the server operation log data comprises multiple sets of task log data, each set including the trace identifier for each task and the log information from the execution server during that task's execution.
[0079] S43: The execution server performs tracking identifier matching on multiple sets of task log data, and obtains the log information corresponding to the tracking identifier as the target log information.
[0080] After acquiring server runtime log data including multiple sets of task log data, the execution server performs tracking identifier matching on the multiple sets of task log data, obtains the log information corresponding to the tracking identifier as the target log information, and then feeds back the target log information to the microservice control device.
[0081] In other embodiments, after each execution server completes the microservice corresponding to the task, it generates log information for that task and stores the log information in a folder named after the trace identifier of the task. Subsequently, after extracting the trace identifier of the target task in the log retrieval request, the trace identifier of the target task is matched with the names of each folder to obtain the target folder. Then, the data in the target folder is extracted as the target log information, which is simple and convenient and improves the efficiency of target log information extraction.
[0082] In this embodiment, the execution server receives a log retrieval request sent by the microservice control device, extracts the trace identifier from the log retrieval request, and then retrieves server operation log data from the execution server's database. The server operation log data includes multiple sets of task log data. Each set of task log data includes the trace identifier of each task and the log information of the execution server executing the task. Finally, the trace identifiers of the multiple sets of task log data are matched to obtain the log information corresponding to the trace identifier, which is used as the target log information. This clarifies the specific steps for extracting the target log information stored on the execution server based on the trace identifier. By matching the trace identifiers of multiple sets of task log data and obtaining the log information corresponding to the trace identifier as the target log information, the execution server does not need to summarize and re-store different log information, thus reducing the load on the execution server.
[0083] In one embodiment, before step S10, i.e. before obtaining the log retrieval request of the target task, the microservice control device also needs to send a service request to the execution server of the target task so that each execution service executes the corresponding microservice, thereby completing the entire target task, clarifying the execution process of the target task, ensuring that the user's needs are met, and also providing a basis for subsequent log query of the target task.
[0084] In one embodiment, such as Figure 4 As shown, in step S00, the microservice control device also needs to send a service request to the execution server of the target task so that each execution service can execute the corresponding microservice to complete the entire target task. Specifically, this includes the following steps:
[0085] SA01: The microservice control unit determines the multiple microservices required to execute the target task and assigns a corresponding execution server to each microservice.
[0086] After receiving a target task request from a user-provided client, the microservice control unit needs to identify the multiple microservices required to execute the target task and assign corresponding execution servers to each microservice. That is, the target task is broken down into multiple microservices based on its specific content, and then the server for executing each microservice is determined.
[0087] SA02: The microservice control unit determines the trace identifier of the target task and generates a service request containing the trace identifier based on the microservice.
[0088] After allocating corresponding execution servers to each microservice, the microservice control device determines the trace identifier of the target task. This trace identifier is a unique identifier automatically generated by the microservice control device for tracing the target task. After determining the trace identifier of the target task, the microservice control device generates a service request containing the trace identifier according to the microservice. That is, each microservice corresponds to one service request, and each service request has the same trace identifier.
[0089] SA03: The microservice control device sends corresponding service requests to each execution server, so that each execution server responds to the service request, executes the corresponding microservice, and records the execution process of the microservice to form log information.
[0090] After generating a service request containing a tracing identifier based on the microservice, the microservice control device sends the corresponding service request to each execution server, so that each execution server responds to the service request, executes the corresponding microservice, and records the execution process of the microservice to form log information, wherein the log information carries the tracing identifier.
[0091] That is, after the microservice control device sends the corresponding service request to each execution server, each execution server receives the service request sent by the microservice control device, executes the corresponding microservice according to the received service request, and records its own microservice execution process to form log information. The log information is then bound to the trace identifier in the service request, so that the log information carries the trace identifier, which facilitates subsequent log retrieval and tracing.
[0092] In this embodiment, before obtaining the log retrieval request of the target task, the microservice control device determines the multiple microservices required to execute the target task, assigns a corresponding execution server to each microservice, then determines the tracing identifier of the target task, and generates a service request containing the tracing identifier based on the microservice.
[0093] The microservice control device sends corresponding service requests to the execution server, so that the execution server responds to the service requests and executes the corresponding microservices, and records the execution process of the microservices to form log information. The log information carries a tracking identifier; this clarifies the execution process of the target task, ensures that the user's needs are met, and also provides a basis for subsequent log queries of the target task.
[0094] In one embodiment, such as Figure 5 As shown, in step S00, the microservice control device also needs to send a service request to the execution server of the target task so that each execution service can execute the corresponding microservice to complete the entire target task. Specifically, this includes the following steps:
[0095] SB01: The microservice control unit determines the trace identifier of the target task and generates a task request for the target task based on the target task and the trace identifier.
[0096] In this embodiment, after receiving the target task request sent by the user-provided client, the microservice control device does not need to determine the multiple microservices required to execute the target task and allocate corresponding execution servers to each microservice. Instead, it directly determines the tracking identifier of the target task and then generates the task request of the target task based on the target task and the tracking identifier.
[0097] SB02: The microservice control device sends a task request to the first execution server, so that the first execution server responds to the service request, executes the target task, and records the process of executing the target task to form log information.
[0098] After determining the trace identifier of the target task and generating a task request based on the target task and the trace identifier, the microservice control device needs to select a server to execute the target task. This selected server is the first execution server. The microservice control device then sends a task request to the first execution server, causing the first execution server to respond to the service request, execute the target task, and record the execution process to form log information. The log information carries the trace identifier. In other words, after the microservice control device sends the task request to the first execution server, the first execution server receives the task request, executes the target task according to the received task request, records its own execution process to form log information, and binds this log information to the trace identifier in the task request, making the log information carry the trace identifier for subsequent log retrieval and tracing.
[0099] SB03: During the execution of the target task by the first execution server, if the first execution server determines that it needs to call other servers to participate in the execution of the target task, the first execution server determines the service to be executed by the called server and generates a service request based on the service and tracking identifier.
[0100] SB04: The first execution server sends a service request to the calling server, so that the calling server responds to the service request and executes the corresponding service until the entire target task is completed.
[0101] During the execution of the target task by the first execution server, the first execution server needs to determine whether it needs to call other servers to participate in the execution of the target task. If it needs to call other servers, it determines the service that the calling server needs to perform, and generates a service request based on the determined service and tracking identifier. This service request is then sent to the calling server (which can be referred to as the second execution server), so that the calling server responds to the service request, executes the service corresponding to the service request, and generates corresponding log information. During the process of the calling server (the second execution server) responding to the service request and executing the service, this sub-service also needs to determine whether to call other servers to participate in the execution of the target task. If so, it generates a new service request and sends it to the server that needs to be called (referred to as the third execution server), until the entire target task is completed.
[0102] In this embodiment, before obtaining the log retrieval request for the target task, the microservice control device determines the tracking identifier of the target task, generates a task request for the target task based on the target task and the tracking identifier, and sends the task request to the first execution server. This causes the first execution server to respond to the service request and execute the target task, recording the execution process to form log information. During the execution of the target task by the first execution server, if the first execution server determines that it needs to call other servers to participate in the execution of the target task, the first execution server determines the service that the called server needs to execute, generates a service request based on the service and the tracking identifier, and sends the service request to the called server. This causes the called server to respond to the service request and execute the corresponding service until the entire target task is completed. This clarifies the execution process of the target task, ensures that the user's needs are met, provides a basis for subsequent log queries of the target task, and reduces the workload of the microservice control device during the execution of the target task.
[0103] In one embodiment, such as Figure 6 As shown, before step S20, that is, before determining the execution server corresponding to each microservice based on the service call chain of the target task, the method also specifically includes the following steps:
[0104] S61: The microservice controller determines whether the service call chain of the target task can be obtained.
[0105] S62: If the service call chain can be obtained, the microservice control device obtains the service call chain and determines the execution server corresponding to each microservice based on the service call chain of the target task.
[0106] Before determining the execution server corresponding to each microservice based on the service call chain of the target task, the microservice control device needs to determine whether it can obtain the service call chain of the target task. If the microservice control device can obtain the service call chain, it directly retrieves the service call chain from the database or log retrieval request and executes step S20, that is, determining the execution server corresponding to each microservice based on the service call chain of the target task.
[0107] In this embodiment, the microservice control device determines whether the service call chain of the target task can be obtained. If the service call chain can be obtained, the microservice control device acquires the service call chain and determines the execution server corresponding to each microservice based on the service call chain of the target task. Before determining the execution server corresponding to each microservice based on the service call chain of the target task, it is necessary to determine whether the service call chain of the target task can be obtained. Only after determining that the service call chain can be obtained can the service call chain be acquired, and the execution server corresponding to each microservice is determined based on the service call chain of the target task. This ensures that the log retrieval task can be executed normally, thereby reducing system disorder caused by the inability to execute step 20 due to the inability to acquire the service call chain.
[0108] In one embodiment, such as Figure 7 As shown, after step S61, i.e., after determining whether the service call chain of the target task can be obtained, the method further includes the following steps:
[0109] S63: If the service call chain cannot be obtained, the microservice control device determines the first execution server that receives the task request for the target task sent by the microservice control device, and sends a log retrieval request to the first execution server.
[0110] If the microservice control device cannot obtain the service call chain of the target task, it means that the microservice control device has not saved the service call chain of the target task for some reason, and the log retrieval request does not specify the service call chain of the target task. At this time, the microservice control device can determine the server that sent the task request of the target task, that is, the first execution server of the target task. Then, the microservice control device sends a log retrieval request including the trace identifier to the first execution server.
[0111] S64: The first execution server extracts the target log information stored on the first execution server based on the trace identifier in the log retrieval request.
[0112] After the microservice controller sends a log retrieval request including a tracing identifier to the first execution server, the first execution server receives the log retrieval request from the microservice controller and extracts the target log information stored on the first execution server according to the tracing identifier in the log retrieval request.
[0113] S65: The first execution server determines whether it should call other servers to execute the target task.
[0114] While retrieving the target log information stored on the first execution server based on the tracking identifier in the log retrieval request, the first execution server determines whether it should call other servers to execute the target task.
[0115] S66: If the first execution server does not call other servers to execute the target task, the first execution server will feed back the target log information to the microservice control device.
[0116] After determining whether the first execution server calls other servers to execute the target task, if the first execution server does not call other servers to execute the target task, it means that the entire target task is completely executed by the first server. The target log information stored on the first execution server is the full-link log information of the target task. Therefore, when the first execution server does not call other servers to execute the target task, the first execution server feeds back the target log information to the microservice control device, and controls the use of the target log information fed back by the first execution server as the full-link log information of the target task.
[0117] In this embodiment, after determining whether the service call chain of the target task can be obtained, if the microservice control device cannot obtain the service call chain, the microservice control device determines the first execution server that received the task request for the target task sent by the microservice control device. The microservice control device sends a log retrieval request to the first execution server, so that the first execution server can extract the target log information stored on the first execution server according to the tracing identifier, and determine whether the first execution server calls other servers to execute the target task. If the first execution server does not call other servers to execute the target task, the first execution server feeds back the target log information to the microservice control device. This clarifies the specific method for obtaining the full-link log information of the target task when the microservice control device cannot obtain the service call chain, providing an accurate basis for obtaining the full-link log information of the target task.
[0118] In one embodiment, such as Figure 8 As shown, after step S65, that is, after determining whether the first execution server calls other servers to execute the target task, the method further includes the following steps:
[0119] S67: If the first execution server calls another server to execute the target task, the first execution server sends a log retrieval request to the called server and receives the target log information fed back by the called server in response to the log retrieval request.
[0120] After determining whether the first execution server has invoked other servers to execute the target task, if it is determined that the execution of the target task has also invoked other servers, it means that the execution of the target task requires obtaining log information from these other servers regarding the execution of the target task. Therefore, the first execution server sends a log retrieval request to the invoked server and receives the target log information from the invoked server in response to the log retrieval request. That is, the first execution server sends a log retrieval request to the invoked server, and after receiving the log retrieval request, the invoked server extracts the log information related to the target task stored in its own database based on the tracking identifier of the log retrieval request, obtains the target log information, and then sends the extracted target log information back to the first execution server.
[0121] During the process of the server responding to the log retrieval request and feeding back the target log information, the server also needs to determine whether to call other servers to execute the target task. If the server also calls other servers to execute the target task, it sends a log retrieval request to the server it called and receives the target log information from the server it called in response to the log retrieval request. The log retrieval request is then passed down layer by layer until the entire call chain of the target task has been traversed.
[0122] S68: The first execution server sends the target log information of the first execution server to the microservice control device, and sends the target log information returned by the called server.
[0123] After receiving the target log information from the calling server, the first execution server sends the target log information on the first execution server to the microservice control device, and also sends the target log information from the calling server to the microservice control device, so that the microservice control device sorts all the target log information from the first execution server by recording time to obtain the full-link log information of the target task.
[0124] The process involves the first execution server sending a log retrieval request to the called server and receiving target log information from the called server in response to the log retrieval request. Specifically, the first execution server identifies the called server as the second execution server and sends a log retrieval request to it. Upon receiving the log retrieval request, the second execution server extracts the target log information stored on it based on the tracking identifier and determines whether to call another server to execute the target task. If the second execution server does not call another server to execute the target task, it sends the target log information back to the sender of the received log retrieval request (the first execution server). If the second execution server calls another server to execute the target task, it sends a log retrieval request to the called third execution server until the called execution server determines that it has not called another server.
[0125] For example, the entire call chain of the target task includes four execution servers: a first execution server, a second execution server, a third execution server, and a fourth execution server. The first execution server calls the second execution server to execute the target task, the second execution server calls the third execution server to execute the target task, and the third execution server calls the fourth execution server to execute the target task. Then, while the first execution server extracts the target log information stored on its own server based on the tracing identifier, it also sends a log retrieval request to the second execution server. Upon receiving the log retrieval request, the second execution server extracts the target log information stored on its own server based on the tracing identifier and sends a log retrieval request to the third execution server it called. Similarly, the third execution server extracts the target log information stored on its own server based on the tracing identifier and sends a log retrieval request to the fourth execution server it called. The fourth execution server extracts the target log information stored on its own server based on the tracing identifier. After obtaining the target log information, the first, second, third, and fourth execution servers all report the obtained target log information back to the previous node (i.e., the sender of the received log retrieval request), layer by layer, until the microservice control device receives the target log information from all execution servers.
[0126] In this embodiment, after determining whether the first execution server calls other servers to execute the target task, if the first execution server calls other servers to execute the target task, the first execution server sends a log retrieval request to the called server and receives the target log information fed back by the called server in response to the log retrieval request. The first execution server sends the target log information on the first execution server to the microservice control device and sends the target log information fed back by the called server. This clarifies the specific method for obtaining the full-link log information of the target task when the microservice control device cannot obtain the service call chain, providing an accurate basis for obtaining the full-link log information of the target task. Based on this, the instruction transmission of the microservice control device is retrieved. The retrieval of logs of all microservice nodes is performed independently by each node, reducing the load on the microservice control device.
[0127] It should be understood that the sequence number of each step in the above embodiments does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present invention.
[0128] In one embodiment, a microservice log retrieval device is provided, which corresponds one-to-one with the microservice log retrieval method described in the above embodiments. For example... Figure 9 As shown, the microservice control device includes an acquisition module 901, a determination module 902, a sending module 903, and a sorting module 904. Detailed descriptions of each functional module are as follows:
[0129] The acquisition module 901 is used to acquire the log retrieval request of the target task, and the log retrieval request includes the tracking identifier of the target task;
[0130] The determination module 902 is used to determine the execution server corresponding to each microservice based on the service call chain of the target task. The service call chain is the execution order of multiple microservices required to execute the target task.
[0131] The sending module 903 is used to send log retrieval requests to each execution server, so that each execution server can extract the target log information stored on the execution server according to the tracing identifier and feed back the target log information to the microservice control device.
[0132] The sorting module 904 is used to sort the target log information on each execution server according to the recording time of each target log information to obtain the full-link log of the target task.
[0133] Furthermore, the execution server specifically uses the following methods to store target log information on the execution server:
[0134] Receive log retrieval requests sent by the microservice control device and extract the tracing identifier from the log retrieval requests;
[0135] Retrieve server operation log data from the server's database. The server operation log data includes multiple sets of task log data. Each set of task log data includes the tracking identifier of each task and the log information of the server executing the task.
[0136] Multiple sets of task log data are matched with tracking identifiers to obtain the log information corresponding to the tracking identifiers, which is then used as the target log information.
[0137] Furthermore, the microservice control device also includes a task execution module 905, which, before obtaining the log retrieval request of the target task, performs the following:
[0138] Identify the multiple microservices required to execute the target task and assign a corresponding execution server to each microservice;
[0139] Identify the tracing identifier for the target task and generate a service request containing the tracing identifier based on the microservice;
[0140] Send the corresponding service request to the execution server so that the execution server responds to the service request and executes the corresponding microservice, and records the execution process of the microservice to form log information, which carries a trace identifier.
[0141] Furthermore, before obtaining the log retrieval request for the target task, the task execution module 905 is also used for:
[0142] Identify the tracking identifier of the target task, and generate a task request for the target task based on the target task and the tracking identifier;
[0143] A task request is sent to the first execution server so that the first execution server responds to the service request, executes the target task, and records the execution process of the target task to form log information, which carries a tracking identifier.
[0144] Furthermore, before determining the execution server corresponding to each microservice based on the service call chain of the target task, module 901 is also specifically used for:
[0145] Determine if the service call chain for the target task can be obtained;
[0146] If the service call chain can be obtained, then obtain the service call chain and determine the execution server corresponding to each microservice based on the service call chain of the target task.
[0147] Furthermore, after determining whether the service call chain of the target task can be obtained, module 901 is also specifically used for:
[0148] If the service call chain cannot be obtained, determine the first execution server that receives the task request for the target task sent by the microservice controller.
[0149] Send a log retrieval request to the first execution server so that the first execution server can extract the target log information stored on the first execution server according to the tracking identifier, and receive the target log information fed back by the first execution server.
[0150] For specific limitations regarding the microservice control device, please refer to the limitations on the microservice log retrieval method mentioned above, which will not be repeated here. Each module in the aforementioned microservice control device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in the computer device in hardware form, or stored in the memory of the computer device in software form, so that the processor can call and execute the operations corresponding to each module.
[0151] In one embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be as follows: Figure 10 As shown, the computer device includes a processor, memory, network interface, and database connected via a system bus. The processor provides computing and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system, computer programs, and database. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The database stores the data used and generated by the microservice log retrieval method described above. The network interface communicates with external terminals via a network connection. When the computer program is executed by the processor, it implements a microservice log retrieval method.
[0152] In one embodiment, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to perform the following steps:
[0153] Obtain the log retrieval request for the target task, which includes the tracking identifier of the target task;
[0154] The execution server corresponding to each microservice is determined based on the service call chain of the target task. The service call chain is the execution order of multiple microservices required to execute the target task.
[0155] Send log retrieval requests to each execution server so that each execution server can extract the target log information stored on the execution server according to the tracing identifier and feed back the target log information to the microservice control device;
[0156] Based on the recording time of each target log information, the target log information on each execution server is sorted to obtain the full-link log of the target task.
[0157] In one embodiment, a computer-readable storage medium is provided having a computer program stored thereon, the computer program performing the following steps when executed by a processor:
[0158] Obtain the log retrieval request for the target task, which includes the tracking identifier of the target task;
[0159] The execution server corresponding to each microservice is determined based on the service call chain of the target task. The service call chain is the execution order of multiple microservices required to execute the target task.
[0160] Send log retrieval requests to each execution server so that each execution server can extract the target log information stored on the execution server according to the tracing identifier and feed back the target log information to the microservice control device;
[0161] Based on the recording time of each target log information, the target log information on each execution server is sorted to obtain the full-link log of the target task.
[0162] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, storage, databases, or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), Rambus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.
[0163] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the above-described division of functional units and modules is used as an example. In practical applications, the above functions can be assigned to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above.
[0164] The above-described embodiments are only used to illustrate the technical solutions of the present invention, and are not intended to limit it. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be included within the protection scope of the present invention.
Claims
1. A microservice log retrieval method, characterized in that, The method comprises the following steps: obtaining a log retrieval request of a target task, wherein the log retrieval request comprises a tracking identifier of the target task; determining an execution server corresponding to each microservice according to a service call chain of the target task, wherein the service call chain is an execution order of a plurality of microservices required for executing the target task; sending the log retrieval request to each execution server, so that each execution server extracts target log information stored on the execution server according to the tracking identifier, and feeds back the target log information to a microservice control device; sorting the target log information on each execution server according to the recording time of each target log information, to obtain a full-link log of the target task; Before the step of determining an execution server corresponding to each microservice according to a service call chain of the target task, the method further comprises the following steps: determining whether the service call chain of the target task can be obtained; if the service call chain can be obtained, obtaining the service call chain, and determining an execution server corresponding to each microservice according to the service call chain of the target task; if the service call chain cannot be obtained, determining a first execution server that receives a task request of the target task sent by the microservice control device; sending the log retrieval request to the first execution server, so that the first execution server extracts target log information stored on the first execution server according to the tracking identifier, and receives the target log information fed back by the first execution server. 2.The microservice log retrieval method of claim 1, wherein, Before the step of obtaining a log retrieval request of a target task, the method further comprises the following steps: determining a plurality of microservices required for executing the target task, and allocating a corresponding execution server to each microservice; determining the tracking identifier of the target task, and generating a service request containing the tracking identifier according to the microservice; sending the corresponding service request to each execution server, so that each execution server executes the corresponding service in response to the service request, and records the process of executing the microservice to form log information, wherein the log information carries the tracking identifier. 3.The microservice log retrieval method of claim 1, wherein, Before the step of obtaining a log retrieval request of a target task, the method further comprises the following steps: determining the tracking identifier of the target task, and generating a task request of the target task according to the target task and the tracking identifier; sending the task request to a first execution server, so that the first execution server executes the target task in response to the task request, and records the process of executing the target task to form log information, wherein the log information carries the tracking identifier.
4. A microservice system for performing the microservice log retrieval method according to any one of claims 1-3, characterized in that, The system comprises a microservice control device and a plurality of execution servers, and the microservice control device is specifically configured to: obtain a log retrieval request of a target task, wherein the log retrieval request comprises a tracking identifier of the target task; determine an execution server corresponding to each microservice according to a service call chain of the target task, wherein the service call chain is an execution order of a plurality of microservices required for executing the target task; The log retrieval request is sent to each of the execution servers, so that each of the execution servers extracts target log information stored on the execution server according to the tracking identifier; The target log information on each of the execution servers is sorted according to the recording time of each of the target log information, and full-link logs of the target task are obtained.
5. The microservice system of claim 4, wherein, The execution server is specifically used for: receiving the log retrieval request sent by the micro-service control device, and extracting the tracking identifier in the log retrieval request; obtaining server running log data in a database of the execution server, the server running log data including multiple groups of task log data, each group of the task log data including a tracking identifier of each of the tasks and log information of the execution server executing the task; performing tracking identifier matching on the multiple groups of the task log data, and obtaining the log information corresponding to the tracking identifier as the target log information.
6. The microservice system of claim 4, wherein, Before determining the execution server corresponding to each micro-service according to the service call chain of the target task, the micro-service control device is specifically further used for: determining whether the service call chain of the target task can be obtained; if the service call chain can be obtained, obtaining the service call chain and determining the execution server corresponding to each micro-service according to the service call chain of the target task. 7.A micro-service control apparatus comprising a memory, a processor, and a computer program stored in the memory and capable of running on the processor, characterized in that, The processor executes the computer program to implement the steps of the micro-service log retrieval method according to any one of claims 1 to 3.
8. One or more readable storage media storing a computer program, wherein, The computer program is executed by the processor to implement the steps of the micro-service log retrieval method according to any one of claims 1 to 3.
Citation Information
Patent Citations
Service chain log processing method and device based on link tracking and computer equipment
CN112506894A
Log information full-link tracking method and device, computer equipment and storage medium
CN112711496A