Operation Log Generation Method and Related Devices
By generating and storing operation logs carrying operation numbers in the microservice system, the problem of difficulty in querying operation logs in the microservice architecture is solved, and the effect of quickly obtaining complete operation process records is achieved.
Patent Information
- Application Number
- CN202111409625.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-24
- Publication Date
- 2025-07-29
- Estimated Expiration
- 2041-11-24
AI Technical Summary
In microservice architecture, it is difficult for the prior art to quickly and accurately query and locate operation logs, resulting in users being unable to determine specific operation records.
By determining the operation number in the local thread of the microservice module and generating an operation log carrying the operation number, the operation log generation module and the acquisition module are used to generate and store the logs, ensuring that each operation log carries the operation number of its corresponding upstream microservice.
It improves the query efficiency of operation logs, enables users to quickly obtain complete operation process records, and enhances the query convenience and accuracy of operation logs.
Smart Images

Figure CN114138510B_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the field of data processing, and particularly relates to an operation log generation method and related devices. Background Art
[0002] An operation log is a file that records various important information during the operation of a system, and is created and recorded by each process during the operation of the system. The operation log can record the operation process and exception information of the system, and provide detailed information for quickly locating problems occurring during the operation of the system and program debugging problems during the development process. Summary of the Invention
[0003] Embodiments of this application provide an operation log generation method and related devices, in order to improve the efficiency of querying operation logs under a microservices system.
[0004] In a first aspect, embodiments of this application provide an operation log generation method, which is applied to an operation log generation module of a microservices system. The microservices system includes multiple microservice modules, the operation log generation module, and an operation log collection module. The method includes:
[0005] Determine whether a first operation number is included in the local thread of the first microservice module. The first operation number is an operation number for an operation on the second microservice module, and the first operation number is used to indicate a remote service call RPC request, and the RPC request is used to indicate the call relationship of the second microservice module for the first microservice module;
[0006] If the first operation number is included, extract the first operation number from the local thread;
[0007] Generate a first operation log of the first microservice module according to the first operation number;
[0008] Send the first operation log to the operation log collection module.
[0009] In a second aspect, embodiments of this application provide an operation log generation method, which is applied to an operation log collection module of a microservices system. The microservices system includes multiple microservice modules, an operation log generation module, and the operation log collection module. The method includes:
[0010] Obtain the first operation log of the first microservice module from the operation log generation module. The first operation log carries a first operation number, which is the operation number for an operation on the second microservice module. The first operation number is used to indicate a remote service call RPC request, and the RPC request is used to indicate the call relationship of the second microservice module to the first microservice module. Or the first operation log carries a second operation number, which is the operation number for an operation on the first microservice module.
[0011] Store the operation information included in the first operation log in a database.
[0012] In a third aspect, an embodiment of the present application provides an operation log generation device, which is applied to an operation log generation module of a microservice system. The microservice system includes multiple microservice modules, the operation log generation module, and an operation log collection module. The device includes: a determination unit, configured to determine whether a first operation number is included in the local thread of the first microservice module. The first operation number is the operation number for an operation on the second microservice module, and the first operation number is used to indicate a remote service call RPC request, and the RPC request is used to indicate the call relationship of the second microservice module to the first microservice module; an extraction unit, configured to extract the first operation number from the local thread if the first operation number is included; a generation unit, configured to generate a first operation log of the first microservice module according to the first operation number; and a sending unit, configured to send the first operation log to the operation log collection module.
[0013] In a fourth aspect, an embodiment of the present application provides an operation log collection device, which is applied to an operation log collection module of a microservice system. The microservice system includes multiple microservice modules, an operation log generation module, and the operation log collection module. The device includes: an acquisition unit, configured to acquire a first operation log of the first microservice module from the operation log generation module. The first operation log carries a first operation number, which is the operation number for an operation on the second microservice module, and the first operation number is used to indicate a remote service call RPC request, and the RPC request is used to indicate the call relationship of the second microservice module to the first microservice module. Or the first operation log carries a second operation number, which is the operation number for an operation on the first microservice module; a storage unit, configured to store the operation information included in the first operation log in a database.
[0014] Fifth aspect, an embodiment of the present application provides an electronic device, including a processor, a memory, a communication interface, and one or more programs. The one or more programs are stored in the memory and are configured to be executed by the processor. The programs include instructions for performing the steps in the first aspect or the second aspect of the embodiments of the present application.
[0015] Sixth aspect, an embodiment of the present application provides a computer storage medium, characterized in that it stores a computer program for electronic data exchange, wherein the computer program enables a computer to execute some or all of the steps described in the first aspect or the second aspect of this embodiment.
[0016] Seventh aspect, an embodiment of the present application provides a computer program product. The computer program product includes a non-transitory computer-readable storage medium storing a computer program. The computer program is operable to enable a computer to execute some or all of the steps described in the first aspect or the second aspect of the embodiments of the present application. The computer program product can be a software installation package.
[0017] It can be seen that in the embodiment of the present application, the operation log generation module first determines whether the first operation number is included in the local thread of the first microservice module. If the first operation number is included, the first operation number is extracted from the local thread, and then the first operation log of the first microservice module is generated according to the first operation number. Finally, the first operation log is sent to the operation log collection module. In this way, the operation logs of a series of microservices corresponding to a user operation all include a corresponding first operation number. It can be seen that since each microservice operation log sent to the operation log collection module carries the operation number of its corresponding most upstream microservice, a user's operation on a microservice will generate a series of operation logs with the same operation number. This can improve the subsequent query efficiency of operation logs, enabling the user to quickly obtain the operation records corresponding to a complete operation process. Description of the Drawings
[0018] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, the following drawings are only some embodiments of the present application. For those of ordinary skill in the art, without creative efforts, other drawings can be obtained based on these drawings.
[0019] Figure 1a It is a schematic diagram of the architecture of a microservice system provided by an embodiment of the present application;
[0020] Figure 1bIt is a schematic structural diagram of an electronic device provided by an embodiment of the present application;
[0021] Figure 1c It is a framework diagram of a microservice system provided by an embodiment of the present application;
[0022] Figure 2a It is a schematic flowchart of an operation log generation method provided by an embodiment of the present application;
[0023] Figure 2b It is a schematic diagram of the timing of operation log collection provided by an embodiment of the present application;
[0024] Figure 2c It is a schematic diagram of an operation log generation method provided by an embodiment of the present application;
[0025] Figure 2d It is a schematic diagram of another operation log generation method provided by an embodiment of the present application
[0026] Figure 2e It is a schematic flowchart of an operation log storage process provided by an embodiment of the present application;
[0027] Figure 3 It is a block diagram of the functional units of an operation log generation device provided by an embodiment of the present application;
[0028] Figure 4 It is a block diagram of the functional units of another operation log generation device provided by an embodiment of the present application;
[0029] Figure 5 It is a block diagram of the functional units of another operation log generation device provided by an embodiment of the present application;
[0030] Figure 6 It is a block diagram of the functional units of another operation log generation device provided by an embodiment of the present application. Detailed implementation manners
[0031] In order to enable those skilled in the art to better understand the solutions of the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without making creative efforts shall fall within the protection scope of the present application.
[0032] In the description, claims and the above-mentioned drawings of this application, terms such as "first", "second", etc. are used to distinguish different objects rather than to describe a specific order. In addition, the terms "comprising" and "having" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, product or device that includes a series of steps or units is not limited to the listed steps or units, but optionally further includes steps or units not listed, or optionally further includes other steps or units inherent to these processes, methods, products or devices.
[0033] Reference to "embodiment" herein means that a specific feature, structure or characteristic described in connection with the embodiment can be included in at least one embodiment of this application. The phrase appears in various places in the specification and does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment mutually exclusive with other embodiments. Those skilled in the art will explicitly and implicitly understand that the embodiments described herein can be combined with other embodiments.
[0034] Current operation log recording schemes often only occur within a single service. However, with the development of technology, the microservices architecture has become increasingly popular. Currently, when a user clicks a button, it may require many downstream microservices to process sequentially, and each microservice may have operated on the database. Therefore, when a user queries the operation logs collected by the current method, it is impossible to quickly and accurately determine the specific log corresponding to which operation.
[0035] In view of the above problems, embodiments of this application provide an operation log generation method and related device. The embodiments of this application will be introduced in detail below with reference to the drawings.
[0036] Please refer to Figure 1a , Figure 1a which is a schematic diagram of the architecture of a microservices system provided by an embodiment of this application. The microservices system 10 includes a plurality of microservices modules 101, an operation log generation module 102, and an operation log collection module 103. The operation log generation module 102 can obtain operation information from each microservices module 101 respectively, generate an operation log for the microservices module 101 based on the obtained operation information, and send the generated operation log to the operation log collection module 103. The operation log collection module 103 is used to store the collected operation logs in a database.
[0037] The above-mentioned plurality of microservices modules 101, operation log generation module 102, and operation log collection module 103 can be located in the same electronic device or in different electronic devices respectively. The structure of the electronic device is as Figure 1b shown, Figure 1bIt is a schematic structural diagram of an electronic device provided by an embodiment of the present application. The electronic device 110 includes an application processor 120, a memory 130, a communication interface 140, and one or more programs 131. Among them, the one or more programs 131 are stored in the memory 130 and are configured to be executed by the application processor 120. The one or more programs 131 include instructions for executing any step in the following method embodiments. Specifically, the application processor 120 is used to execute any step executed by the electronic device in the following method embodiments, and when performing data transmission such as sending, the communication interface 140 can be selectively called to complete the corresponding operation.
[0038] Please refer to Figure 1c , Figure 1c It is a framework diagram of a microservice system provided by an embodiment of the present application. As shown in the figure, the microservice system includes an access layer, a service layer, a middleware layer, and an infrastructure layer. The access layer includes an operation front desk and an operation log generation module. The service layer includes an operation log operation module and an operation log collection module. The middleware layer includes a message queue module. The infrastructure layer includes a database and a remote service call (Remote Procedure Call, RPC). During the log collection process, first, the operation front desk generates operation information based on user operations. The operation log generation module can obtain the corresponding operation information according to the buried points in the operation front desk. Then, the operation log generation module generates an operation log based on the operation information and sends the operation log to the operation log collection module through the message queue module. The operation log collection module writes the operation log into the database. The operation log management service module reads the operation log from the database and sends it to the back end of the business management background through RPC. Then, the back end of the business management background sends it to the front end of the business management background. It can be seen that in terms of the overall architecture, the generation of operation logs is mainly divided into an operation log generation module that generates operation logs, an operation log collection module that obtains operation logs and writes the operation logs after parameter verification and data structure conversion into the database, and an operation log management module that provides the ability to query and differentiate operation logs in multiple dimensions, exposes an RPC interface externally, and also provides the ability to process expired operation logs. The expired logs are deleted in the form of a scheduled task.
[0039] Please refer to Figure 2a , Figure 2a It is a schematic flowchart of an operation log generation method provided by an embodiment of the present application. As shown in the figure, the operation log generation method includes the following steps:
[0040] Step 201, the operation log generation module determines whether the thread local variable of the first microservice module includes a first operation number.
[0041] Among them, the first operation number is the operation number for an operation of the second microservice module. The first operation number is used to indicate a Remote Procedure Call (RPC) request, and the RPC request is used to indicate the call relationship of the second microservice module for the first microservice module. When the business operator performs addition, deletion, or modification operations in the management background, multiple microservice modules involved in this operation will, in addition to the main logic, send additional operation logs through the operation log generation module. The uppermost microservice module first generates an operation number through the Universally Unique IDentifier (UUID) algorithm, and then encapsulates the RPC calls between microservice modules, so that each call will pass the operation number of the upstream to the downstream. At the same time, when the downstream microservice module receives the request, it will write the operation number into the thread local variable (threadLocal). In this way, when sending the operation log, the operation number can be obtained from threadLocal. The variable filled in threadLocal belongs to the current thread, and this variable is isolated from other threads. That is to say, when performing cross-layer transfer of objects, using threadLocal can avoid multiple transfers and break the constraints between layers. Therefore, the second microservice module is the upstream microservice module of the first microservice module. When the second microservice module schedules the first microservice module through an RPC request, it will simultaneously send the operation number of the current operation of the second microservice module to the first microservice module.
[0042] Step 202, if the first operation number is included, the operation log generation module extracts the first operation number from the thread local variable.
[0043] Among them, if the first microservice module includes the first operation number, it means that the second microservice module has called the first microservice module through an RPC request.
[0044] Step 203, the operation log generation module generates the first operation log of the first microservice module according to the first operation number.
[0045] Among them, the first operation log is the operation log carrying the first operation number. As long as it is a downstream microservice module of the second microservice module, the operation logs of the corresponding same operation will include the first operation number.
[0046] Step 204, the operation log generation module sends the first operation log to the operation log collection module;
[0047] Step 205, the operation log collection module obtains the first operation log of the first microservice module from the operation log generation module.
[0048] Among them, the first operation log carries a first operation number, which is the operation number for an operation on the second microservice module. The first operation number is used to indicate a Remote Procedure Call (RPC) request, and the RPC request is used to indicate the call relationship of the second microservice module to the first microservice module. Or the first operation log carries a second operation number, which is the operation number for an operation on the first microservice module.
[0049] Step 206, the operation log collection module stores the operation information included in the first operation log in a database.
[0050] Among them, the operation log collection module can perform verification and data structure conversion on the obtained parameters and then write them into the database. It can concatenate the operations of a series of other microservice modules corresponding to the second microservice module into a complete operation record according to the first operation number, which is convenient for users to find the operation record through the database.
[0051] It can be seen that in this example, the operation log generation module first determines whether the first operation number is included in the local thread of the first microservice module. If the first operation number is included, it extracts the first operation number from the local thread, then generates the first operation log of the first microservice module according to the first operation number, and finally sends the first operation log to the operation log collection module. In this way, the operation logs of a series of microservices corresponding to a user operation all include a corresponding first operation number. It can be seen that in the embodiments of this application, since each microservice operation log sent to the operation log collection module carries the operation number of its corresponding most upstream microservice, for a certain operation of a microservice by a user, a series of operation logs with the same operation number will be generated. This can improve the subsequent query efficiency of the operation logs, enabling users to quickly obtain the operation records corresponding to a complete operation process.
[0052] In a possible example, the method further includes: if the first operation number is not included, generating a second operation number for an operation on the first microservice module; generating the first operation log of the first microservice module according to the second operation number; and sending the first operation log to the operation log collection module.
[0053] Among them, if the first operation number is not found in the thread-local variable, it can be determined that the first microservice module has not been called by other microservice modules. At this time, the first microservice module is the most upstream microservice module. Therefore, a second operation number corresponding to an operation of the first microservice module can be generated according to the UUID algorithm, and a first operation log corresponding to the first microservice module can be generated according to the second operation number. It should be noted that if the first microservice module calls other microservice modules, the first microservice module will pass the second operation number to other microservice modules according to RPC.
[0054] It can be seen that in this example, if the first microservice module does not have a first operation number, a second operation number is generated for it, so that the operation log of each microservice module carries an operation number for indicating each operation, which is convenient for users to query operation records.
[0055] In a possible example, the microservice system further includes a message queue module. Sending the first operation log to the operation log collection module includes: sending the first operation log to the message queue module.
[0056] Among them, the operation log generation module can wrap the first operation log carrying the first operation number into a message queue (Message Queue, mq) message and send it, and then the operation log collection module consumes the operation log in the message queue module. As Figure 2b shown, the operation log collection timing at this time is that the operation user performs business operations on the operation platform, and then the business operation platform generates operation records. The operation log generation module generates an operation log according to the operation record message of the business operation platform, and then sends the operation log to the message queue module. The operation log collection module can asynchronously consume the operation log from the message queue module and store the obtained operation log in the database.
[0057] It can be seen that in this example, using asynchronous mq messages to send and collect operation logs can improve the flexibility and stability of the system.
[0058] In a possible example, generating the first operation log of the first microservice module according to the first operation number includes: obtaining buried point information from the first microservice module to obtain a plurality of operation information, where the plurality of operation information includes first operation information for indicating operation parameters and second operation information for indicating operation content; generating the first operation log of the first microservice module according to the first operation information, the second operation information, and the first operation number.
[0059] Among them, the operation information of the operation log can include two components, namely the first operation information and the second operation information. The second operation information can be called info information, including secondary information such as input parameters, return values, interface addresses, operation remarks, etc. The first operation information can be called body information, including main information such as the content of the data before and after the operation, the status of the data, etc. Since for any business operation, multiple buried points can be set to generate operation records, an operation log can be generated from multiple buried point information. The operation information corresponding to each buried point information can be different. For example, one buried point information corresponds to the first operation information, and another buried point information corresponds to the second operation information.
[0060] It can be seen that in this example, by jointly generating the operation log from multiple buried point information and the first operation number, the generated operation log can be made more accurate and convenient for users to query the operation log subsequently.
[0061] In a possible example, obtaining the buried point information from the first microservice module to obtain multiple operation information includes: obtaining the buried point information once from the first microservice module according to the first operation number to obtain one piece of the first operation information and one piece of the second operation information; generating the first operation log of the first microservice module according to the first operation information, the second operation information, and the first operation number includes: generating the first operation log according to one piece of the first operation information, one piece of the second operation information, and the first operation number.
[0062] Among them, in the way of single-step acquisition, all the information for generating the operation log can be obtained simultaneously when obtaining the buried point information once, that is, a complete log can be generated according to the multiple operation information obtained from the buried point information acquired once.
[0063] It can be seen that in this example, only by obtaining the buried point information once, the operation information required to generate a complete log can be obtained, which can improve the generation efficiency of the operation log.
[0064] In a possible example, obtaining the buried point information from the first microservice module to obtain multiple operation information includes: obtaining the buried point information from the first microservice module multiple times according to the first operation number to obtain one piece of the first operation information and multiple second operation sub-information, and the second operation information includes the second operation sub-information; generating the first operation log of the first microservice module according to the first operation information, the second operation information, and the first operation number includes: generating the first operation log according to one piece of the first operation information, multiple pieces of the second operation sub-information, and the first operation number.
[0065] Among them, since a complete operation log needs to include both the first operation information and the second operation information at the same time, and when obtaining the buried point information once, only a part of the information included in the operation log can be obtained, that is, the operation information can be obtained step by step. For example, the second operation information can be collected once or multiple times, and the first operation information can be collected another time. For example Figure 2c as shown Figure 2c is a schematic diagram of a method for generating an operation log provided by an embodiment of the present application. It can be seen that the buried point information is obtained three times in total. The buried point information obtained for the first time is the second operation sub-information used to indicate the operation parameters, which can include information such as the request method name and the request value. The buried point information obtained for the second time is the first operation information used to indicate the operation content, which can include information such as the product id, the operation content, and the operator. The buried point information obtained for the third time is also the second operation sub-information used to indicate the operation parameters, which can include information such as the return value and the execution result. The multiple obtained second operation sub-informations can form the complete second operation information. That is, the operation log generation module can converge the buried point information obtained multiple times into a complete operation log. It should be noted that the operation numbers corresponding to the buried point information obtained multiple times are all the first operation numbers, that is, the operation information corresponding to the buried point information obtained multiple times is the operation information generated by the first microservice module for the current operation.
[0066] It can be seen that in this example, the buried point information can be obtained multiple times, and then the buried point information obtained multiple times is converged into a complete operation log, which can improve the flexibility of operation log generation.
[0067] In a possible example, the buried point information is obtained from the first microservice module multiple times to obtain M pieces of the first operation information and N pieces of the second operation sub-information. The M pieces of the first operation information all correspond to the same second operation information, and the second operation information includes multiple pieces of the second operation sub-information; generating the first operation log of the first microservice module according to the first operation information, the second operation information, and the first operation number includes: generating M second operation logs according to the M pieces of the first operation information, the N pieces of the second operation sub-information, and the operation number corresponding to each piece of the first operation information; determining the second operation log including the first operation number among the M second operation logs as the first operation log.
[0068] Among them, a microservice module can generate multiple second operation parameters corresponding to the same first operation parameter according to multiple operations, that is, these multiple second operation parameters have common data such as request values and return values. That is, N pieces of the second operation sub-information form a second operation information, and the M pieces of the first operation information are respectively the operation information generated by different operations of the first microservice module. For example Figure 2dAs shown, the buried point information obtained multiple times may include two second operation sub-information and three first operation information. These three first operation information correspond to the same second operation information. Therefore, an operation log can be generated based on one first operation information and two second operation sub-information. By analogy, three complete operation logs can be generated based on these three first operation information. That is, the buried point information with common request values, return values, etc. data is mapped into multiple complete operation logs.
[0069] It can be seen that in this example, the buried point information can be obtained batch by batch and step by step, and multiple complete operation logs can be generated, which can improve the efficiency and flexibility of log generation.
[0070] In a possible example, the microservice system further includes a message queue module. The obtaining of the first operation log of the first microservice module from the operation log generation module includes: obtaining the first operation log from the message queue module.
[0071] Among them, the operation log collection module can asynchronously consume operation logs from the message queue module.
[0072] It can be seen that in this example, the operation log collection module obtains the first operation log from the message queue module, which improves the flexibility of collecting and storing operation logs.
[0073] In a possible example, the storing of the operation information included in the first operation log in the database includes: determining the information type of the operation information included in the first operation log; storing the operation information included in the first operation log in the database in separate tables according to the information type.
[0074] Among them, the operation type of the operation information may include a first type and a second type. The first type corresponds to the first operation information, and the second type corresponds to the second operation information. That is, the first type may be the body type, and the second type may be the info type. When storing the operation log, the operation records of the operation type of the first type are recorded in one table, and the operation records of the operation type of the second type are recorded in one table.
[0075] It can be seen that in this example, storing the operation information in separate tables according to different operation types can facilitate subsequent query and management of operation logs.
[0076] In a possible example, the storing of the operation information included in the first operation log in the database in separate tables according to the information type includes: determining whether the operation information of the preset type is the operation information corresponding to the preset service; if so, storing the preset operation information in the operation information in the database according to a separate data table, and the fields of the preset operation information are greater than the preset fields.
[0077] Among them, the operation information can also be stored in sub-tables according to the business corresponding to the specific operation data. In particular, when the operation type of the operation information is the second operation type, it can also be determined whether the operation information is the operation information corresponding to the preset business. If so, the corresponding preset operation information in the operation information is stored in sub-tables again. The preset operation information can be the operation information whose content fields before and after the operation are greater than the preset fields. As Figure 2e shown Figure 2e FIG. is a schematic diagram of an operation log storage process provided by an embodiment of the present application. After the operation log collection module consumes the operation log from the mq, it can first determine whether the business (bussiness, biz) allows recording. If so, it determines whether the message type is the second type, that is, whether the message type is the info type. If it is the info type, the operation information is inserted into the "biz_info" table. If the message type is not the info type, it determines whether the message type is the body type. If so, it further determines whether biz is a sub-table business, that is, whether the business corresponding to the operation information is the preset business. If it is not a sub-table business, all fields of the operation information are stored in the "biz_body" table. If it is a sub-table business, the content before and after the operation is stored in the "biz_detail" table, and other fields are stored in the "biz_body" table.
[0078] It can be seen that in this example, for the operation information with relatively large field content in the preset business, storing it separately in a data table can facilitate subsequent query and management of the operation log.
[0079] Consistent with the above embodiment, please refer to Figure 3 , Figure 3 FIG. is a block diagram of the functional units of an operation log generation device provided by an embodiment of the present application. The operation log generation device 30 is applied to the operation log generation module of the microservice system. The microservice system includes multiple microservice modules, the operation log generation module and the operation log collection module. The device 30 includes: a determination unit 301, configured to determine whether the thread local variable of the first microservice module includes a first operation number, where the first operation number is the operation number for an operation on the second microservice module, and the first operation number is used to indicate a remote service call RPC request, and the RPC request is used to indicate the call relationship of the second microservice module to the first microservice module; an extraction unit 302, configured to extract the first operation number from the thread local variable if the first operation number is included; a generation unit 303, configured to generate a first operation log of the first microservice module according to the first operation number; a sending unit 304, configured to send the first operation log to the operation log collection module.
[0080] In a possible example, the device 30 is further configured to: if the first operation number is not included, generate a second operation number for an operation of the first microservice module; generate the first operation log of the first microservice module according to the second operation number; and send the first operation log to the operation log collection module.
[0081] In a possible example, when the microservice system further includes a message queue module, in terms of sending the first operation log to the operation log collection module, the sending unit 304 is specifically configured to: send the first operation log to the message queue module.
[0082] In a possible example, in terms of generating the first operation log of the first microservice module according to the first operation number, the generating unit 303 is specifically configured to: obtain buried point information from the first microservice module to obtain a plurality of operation information, where the plurality of operation information includes first operation information for indicating operation content and second operation information for indicating operation parameters; and generate the first operation log of the first microservice module according to the first operation information, the second operation information, and the first operation number.
[0083] In a possible example, in terms of obtaining buried point information from the first microservice module to obtain a plurality of operation information, the generating unit 303 is specifically configured to: obtain once buried point information from the first microservice module according to the first operation number to obtain one piece of the first operation information and one piece of the second operation information; and the generating the first operation log of the first microservice module according to the first operation information, the second operation information, and the first operation number includes: generating the first operation log according to one piece of the first operation information, one piece of the second operation information, and the first operation number.
[0084] In a possible example, in terms of obtaining buried point information from the first microservice module to obtain a plurality of operation information, the generating unit 303 is specifically configured to: obtain the buried point information from the first microservice module multiple times according to the first operation number to obtain one piece of the first operation information and a plurality of second operation sub-information, where the second operation information includes the second operation sub-information; and the generating the first operation log of the first microservice module according to the first operation information, the second operation information, and the first operation number includes: generating the first operation log according to one piece of the first operation information, a plurality of the second operation sub-information, and the first operation number.
[0085] In a possible example, in terms of obtaining the buried point information from the first microservice module to obtain multiple operation information, the generating unit 303 is specifically configured to: obtain the buried point information from the first microservice module multiple times to obtain M pieces of the first operation information and N pieces of second operation sub-information, where the M pieces of the first operation information all correspond to the same second operation information, and the second operation information includes multiple pieces of the second operation sub-information; generating the first operation log of the first microservice module according to the first operation information, the second operation information, and the first operation number includes: generating M second operation logs according to the M pieces of the first operation information, the N pieces of second operation sub-information, and the operation number corresponding to each piece of the first operation information; determining the second operation log including the first operation number among the M second operation logs as the first operation log.
[0086] It can be understood that since the method embodiment and the device embodiment are different presentation forms of the same technical concept, therefore, the content of the method embodiment part in this application should be synchronously adapted to the device embodiment part, and will not be elaborated here.
[0087] In the case of adopting an integrated unit, as Figure 4 shown, Figure 4 is the functional unit composition block diagram of another operation log generation device provided by the embodiment of the present application. In Figure 4 , the operation log generation device 400 includes: a processing module 412 and a communication module 411. The processing module 412 is used to control and manage the actions of the operation log generation device. For example, it executes the steps of the determination unit 301, the extraction unit 302, the generation unit 303, and the sending unit 304, and / or is used to execute other processes of the technologies described herein. The communication module 411 is used for the interaction between the operation log generation device and other devices. As Figure 4 shown, the operation log generation device may further include a storage module 413, and the storage module 413 is used to store the program code and data of the operation log generation device.
[0088] Among them, the processing module 412 can be a processor or a controller. For example, it can be a Central Processing Unit (CPU), a general-purpose processor, a Digital Signal Processor (DSP), an ASIC, an FPGA, or other programmable logic devices, transistor logic devices, hardware components, or any combination thereof. It can implement or execute various exemplary logic blocks, modules, and circuits described in connection with the disclosure of this application. The processor can also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of a DSP and a microprocessor, and so on. The communication module 411 can be a transceiver, an RF circuit, a communication interface, etc. The storage module 413 can be a memory.
[0089] Among them, all relevant contents of each scenario involved in the above method embodiment can be cited in the function description of the corresponding functional module, and will not be elaborated here. The above operation log generation device 400 can execute the operation log generation method shown in FIG. 2a above.
[0090] Consistent with the above embodiments, please refer to Figure 5 , Figure 5 FIG. 50 is a block diagram of the functional units of an operation log generation device provided by an embodiment of the present application. The operation log generation device 50 is applied to the operation log collection module of a microservice system. The microservice system includes a plurality of microservice modules, an operation log generation module, and the operation log collection module. The device 50 includes: an acquisition unit 501, configured to acquire a first operation log of a first microservice module from the operation log generation module. The first operation log carries a first operation number, and the first operation number is an operation number for an operation on a second microservice module. The first operation number is used to indicate a Remote Procedure Call (RPC) request, and the RPC request is used to indicate the call relationship of the second microservice module to the first microservice module, or the first operation log carries a second operation number, and the second operation number is an operation number for an operation on the first microservice module; a storage unit 502, configured to store the operation information included in the first operation log in a database.
[0091] In a possible example, when the microservice system further includes a message queue module, in terms of acquiring the first operation log of the first microservice module from the operation log generation module, the acquisition unit 501 is specifically configured to: acquire the first operation log from the message queue module.
[0092] In a possible example, in terms of storing the operation information included in the first operation log in the database, the storage unit 502 is specifically configured to: determine the information type of the operation information included in the first operation log; and store the operation information included in the first operation log in separate tables in the database according to the information type.
[0093] In a possible example, in terms of storing the operation information included in the first operation log in separate tables in the database according to the information type, the storage unit 502 is specifically configured to: determine whether the operation information whose operation type is a preset type is the operation information corresponding to a preset service; if so, store the preset operation information in the operation information in the database according to a separate data table, and the fields of the preset operation information are greater than the preset fields.
[0094] It can be understood that since the method embodiment and the device embodiment are different presentation forms of the same technical concept, the content of the method embodiment part in this application should be synchronously adapted to the device embodiment part, and will not be elaborated here.
[0095] In the case of adopting an integrated unit, as Figure 6 shown, Figure 6 is the functional unit composition block diagram of another operation log generation device provided by an embodiment of the present application. In Figure 6 , the operation log generation device 600 includes: a processing module 612 and a communication module 611. The processing module 612 is used to control and manage the actions of the operation log generation device. For example, it executes the steps of the acquisition unit 501 and the storage unit 502, and / or is used to execute other processes of the technologies described herein. The communication module 611 is used for the interaction between the operation log generation device and other devices. As Figure 6 shown, the operation log generation device may further include a storage module 613, and the storage module 613 is used to store the program code and data of the operation log generation device.
[0096] Among them, the processing module 612 can be a processor or a controller. For example, it can be a Central Processing Unit (CPU), a general-purpose processor, a Digital Signal Processor (DSP), an ASIC, an FPGA, or other programmable logic devices, transistor logic devices, hardware components, or any combination thereof. It can implement or execute various exemplary logic blocks, modules, and circuits described in connection with the disclosure of this application. The processor can also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of a DSP and a microprocessor, and so on. The communication module 611 can be a transceiver, an RF circuit, a communication interface, or the like. The storage module 613 can be a memory.
[0097] Among them, all relevant contents of each scenario involved in the above method embodiments can be cited in the function descriptions of the corresponding functional modules, and will not be elaborated here. The above operation log generation device 600 can execute the above Figure 2a shown operation log generation method.
[0098] The above embodiments can be implemented in whole or in part by software, hardware, firmware, or any other arbitrary combination. When implemented using software, the above embodiments can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions or computer programs. When the computer instructions or computer programs are loaded or executed on a computer, the processes or functions described in the embodiments of this application are generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center in a wired or wireless manner. The computer-readable storage medium can be any available medium that the computer can access, or a data storage device such as a server or data center that includes one or more collections of available media. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a magnetic tape), an optical medium (e.g., a DVD), or a semiconductor medium. The semiconductor medium can be a solid-state drive.
[0099] The embodiments of this application also provide a computer storage medium. Among them, this computer storage medium stores a computer program for electronic data exchange, and this computer program enables a computer to execute some or all of the steps of any method described in the above method embodiments. The above computer includes an electronic device.
[0100] The embodiments of the present application also provide a computer program product. The computer program product includes a non-transitory computer-readable storage medium storing a computer program, and the computer program is operable to cause a computer to execute some or all of the steps of any of the methods described in the above method embodiments. The computer program product may be a software installation package, and the computer includes an electronic device.
[0101] It should be understood that in various embodiments of the present application, the order numbers of the above processes do not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation to the implementation process of the embodiments of the present application.
[0102] In several embodiments provided by the present application, it should be understood that the disclosed methods, devices and systems can be implemented in other ways. For example, the device embodiments described above are merely illustrative; for example, the division of the units is only a logical function division, and there may be other division methods in actual implementation; for example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point, the displayed or discussed coupling or direct coupling or communication connection to each other can be through some interfaces, and the indirect coupling or communication connection of the device or unit can be in electrical, mechanical or other forms.
[0103] The units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or may be distributed to multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0104] In addition, in each embodiment of the present invention, the functional units can be integrated in a processing unit, or each unit can be physically included separately, or two or more units can be integrated in one unit. The above integrated unit can be implemented in the form of hardware, or in the form of hardware plus software functional units.
[0105] The integrated units implemented in the form of software functional units can be stored in a computer-readable storage medium. The above-mentioned software functional units are stored in a storage medium and include several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute some steps of the methods described in various embodiments of the present invention. The aforementioned storage medium includes: USB flash drives, mobile hard disks, magnetic disks, optical disks, volatile memories, or non-volatile memories. Among them, the non-volatile memory can be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory can be a random access memory (RAM), which is used as an external cache. By way of example but not limitation, many forms of random access memory (RAM) are available, such as static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDR SDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchlink dynamic random access memory (SLDRAM), and direct rambus random access memory (DR RAM). And other various media that can store program codes.
[0106] Although the present invention is disclosed as above, the present invention is not limited thereto. Any person skilled in the art can easily think of changes or substitutions without departing from the spirit and scope of the present invention, and can make various changes and modifications, including combinations of the above different functions and implementation steps, including software and hardware implementation manners, all within the protection scope of the present invention.
Claims
1. A method for generating operation logs, characterized in that, An operation log generation module applied to a microservice system, the microservice system including a plurality of microservice modules, the operation log generation module, and an operation log collection module, the method comprising: Determine whether a first operation number is included in the thread local variable of the first microservice module, the first operation number being the operation number for an operation on the second microservice module, the first operation number being used to indicate a Remote Procedure Call (RPC) request, and the RPC request being used to indicate the call relationship of the second microservice module to the first microservice module; If the first operation number is included, extract the first operation number from the thread local variable; and, obtain M first operation information and N second operation sub-information by obtaining tracing information from the first microservice module multiple times, where the M first operation information all correspond to the same second operation information, the second operation information includes the N second operation sub-information, the first operation information is used to indicate the operation content, the M first operation information are respectively the operation information generated by different operations of the first microservice module, and the second operation information is used to indicate the operation parameters; and, generate M second operation logs according to the M first operation information, the N second operation sub-information, and the first operation number corresponding to each first operation information; and, determine the second operation log including the first operation number among the M second operation logs as the first operation log of the first microservice module; and, If the first operation number is not included, generate a second operation number for an operation on the first microservice module; and, generate the first operation log according to the second operation number; Send the first operation log to the operation log collection module.
2. The method according to claim 1, wherein The microservice system further includes a message queue module, and the sending the first operation log to the operation log collection module includes: Send the first operation log to the message queue module.
3. The method according to claim 2, wherein The obtaining tracing information from the first microservice module multiple times, the method further includes: Obtain tracing information once from the first microservice module according to the first operation number, to obtain one first operation information and one second operation information; Generate the first operation log according to one first operation information, one second operation information, and the first operation number.
4. The method according to claim 3, characterized in that, The obtaining tracing information from the first microservice module multiple times includes: Obtain the tracing information from the first microservice module multiple times according to the first operation number, to obtain one first operation information and multiple second operation sub-information, and the second operation information includes the second operation sub-information; Generate the first operation log according to one first operation information, multiple second operation sub-information, and the first operation number.
5. A method for generating operation logs, characterized in that, An operation log collection module applied to the microservice system according to any one of claims 1 - 4, the microservice system including a plurality of microservice modules, an operation log generation module, and the operation log collection module, the method comprising: Obtain the first operation log of the first microservice module from the operation log generation module. The first operation log carries a first operation number, which is the operation number for an operation on the second microservice module. The first operation number is used to indicate a Remote Procedure Call (RPC) request, and the RPC request is used to indicate the call relationship of the second microservice module to the first microservice module. Alternatively, the first operation log carries a second operation number, which is the operation number for an operation on the first microservice module. Store the operation information included in the first operation log in a database.
6. The method according to claim 5, characterized in that, The microservice system further includes a message queue module. The obtaining of the first operation log of the first microservice module from the operation log generation module includes: Obtain the first operation log from the message queue module.
7. The method according to claim 5 or 6, characterized in that, The storing of the operation information included in the first operation log in a database includes: Determine the information type of the operation information included in the first operation log. Store the operation information included in the first operation log in different tables in the database according to the information type.
8. The method according to claim 7, wherein The storing of the operation information included in the first operation log in different tables in the database according to the information type includes: Determine whether the operation information with a preset operation type is the operation information corresponding to a preset service. If so, store the preset operation information in the operation information in the database according to a separate data table, and the fields of the preset operation information are greater than the preset fields.
9. An operation log generation device, characterized in that, Applied to the operation log generation module of a microservice system, the microservice system includes multiple microservice modules, the operation log generation module, and an operation log collection module. The device includes: A determination unit, configured to determine whether a first operation number is included in the thread local variable of the first microservice module. The first operation number is the operation number for an operation on the second microservice module. The first operation number is used to indicate a Remote Procedure Call (RPC) request, and the RPC request is used to indicate the call relationship of the second microservice module to the first microservice module. An extraction unit, configured to extract the first operation number from the thread local variable if the first operation number is included. A generating unit, configured to obtain buried point information from the first microservice module multiple times, to obtain M first operation information and N second operation sub-information. The M first operation information all correspond to the same second operation information, and the second operation information includes the N second operation sub-information. The first operation information is used to indicate the operation content, and the M first operation information are respectively operation information generated by different operations of the first microservice module. The second operation information is used to indicate operation parameters; and, generate M second operation logs according to the M first operation information, the N second operation sub-information, and the first operation number corresponding to each first operation information; and, determine the second operation log including the first operation number among the M second operation logs as the first operation log of the first microservice module; and, if the first operation number is not included, generate a second operation number for an operation of the first microservice module; and, generate the first operation log according to the second operation number. A sending unit, configured to send the first operation log to the operation log collection module.
10. An operation log generation device, characterized in that An operation log collection module applied to the microservice system as claimed in claim 9. The microservice system includes a plurality of microservice modules, an operation log generation module, and the operation log collection module. The device includes: An obtaining unit, configured to obtain the first operation log of the first microservice module from the operation log generation module. The first operation log carries a first operation number, and the first operation number is the operation number for an operation of the second microservice module. The first operation number is used to indicate a remote service call RPC request, and the RPC request is used to indicate the call relationship of the second microservice module to the first microservice module, or the first operation log carries a second operation number, and the second operation number is the operation number for an operation of the first microservice module. A storage unit, configured to store the operation information included in the first operation log in a database.
11. A microservices system, characterized in that, It includes a processor, a memory, and one or more programs. The one or more programs are stored in the memory and are configured to be executed by the processor. The programs include instructions for performing the steps in the method as claimed in any one of claims 1 - 4 or any one of claims 5 - 8.
12. A computer-readable storage medium, characterized in that, A computer program stored for electronic data exchange, wherein the computer program causes a computer to execute the method as claimed in any one of claims 1 - 4 or any one of claims 5 - 8.
Citation Information
Patent Citations
Method and system for micro-service invocation tracking based on log burial point
CN109460307A