CN112202598B - Log recording method and device - Google Patents
Log recording method and device Download PDFInfo
- Publication number
- CN112202598B CN112202598B CN202010949189.4A CN202010949189A CN112202598B CN 112202598 B CN112202598 B CN 112202598B CN 202010949189 A CN202010949189 A CN 202010949189A CN 112202598 B CN112202598 B CN 112202598B
- Authority
- CN
- China
- Prior art keywords
- service
- micro
- request
- business
- microservice
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Images
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L41/00—Arrangements for maintenance, administration or management of data switching networks, e.g. of packet switching networks
- H04L41/06—Management of faults, events, alarms or notifications
- H04L41/069—Management of faults, events, alarms or notifications using logs of notifications; Post-processing of notifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/50—Network services
- H04L67/51—Discovery or management thereof, e.g. service location protocol [SLP] or web services
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/50—Network services
- H04L67/60—Scheduling or organising the servicing of application requests, e.g. requests for application data transmissions using the analysis and optimisation of the required network resources
Landscapes
- Engineering & Computer Science (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Debugging And Monitoring (AREA)
Abstract
The embodiment of the invention relates to the technical field of computers, in particular to a log recording method and device, which are used for realizing unified, centralized and non-invasive log recording. The method comprises the following steps: the gateway micro-service acquires a user request aiming at the business micro-service; the gateway micro-service determines a first preset field and a second preset field from the user request; the gateway micro-service acquires a third preset field corresponding to the first preset field from the request interface dictionary; the request interface dictionary is obtained by the gateway micro service through each service micro service; and the gateway micro-service generates a log record of the user request at least according to the second preset field and the third preset field.
Description
Technical Field
The embodiment of the invention relates to the technical field of computers, in particular to a log recording method and device.
Background
At present, with the increasingly complex and huge business systems, the single architecture creates a huge challenge for the development, operation and maintenance of the system, and then the micro-service architecture is generated. In the current micro-service architecture development, each micro-service is subjected to log recording and maintenance in a respective module, so that each micro-service needs to be configured or a log recording method is called, the development workload is large and dispersed, and if log processing is changed, all configuration places need to be modified, so that great development and maintenance cost is caused; meanwhile, the log records are embedded in the micro-service, so that the micro-service is strongly invaded. In addition, each micro service may be developed by different teams, a uniform log specification is difficult to form among the micro services, and the log formats recorded by each micro service may also be completely different, so that the data quality of log data is reduced, and great difficulty is caused to statistics and analysis of the log data.
Therefore, a solution is needed to solve the problem of the log record dispersion and the development and maintenance cost under the micro service architecture.
Disclosure of Invention
The embodiment of the invention provides a log recording method and device, which are used for solving the problems of log record dispersion and high development and maintenance cost under a micro-service architecture.
In a first aspect, an embodiment of the present invention provides a log recording method, including:
the gateway micro service acquires a user request aiming at the business micro service;
the gateway micro-service determines a first preset field and a second preset field from the user request;
the gateway micro-service acquires a third preset field corresponding to the first preset field from a request interface dictionary; the request interface dictionary is obtained by the gateway micro service through each service micro service;
and the gateway micro-service generates a log record of the user request at least according to the second preset field and the third preset field.
By the method, after the user request aiming at the business micro-service is obtained, the gateway micro-service is used for recording the logs, so that the unified centralized processing of the user request logs is realized, the log recording and management of each business micro-service is not required, the development and maintenance cost of each business micro-service is reduced, meanwhile, the consistency of log formats can be ensured by the centralized processing, the problem that the logs cannot be analyzed due to format disorder in subsequent log statistics and analysis is solved, the log data quality is improved, and the efficiency of statistical analysis is improved.
In one possible design, the request interface dictionary is obtained by the gateway microservice through a business microservice, and includes:
the gateway micro service is registered to a service discovery center, and registered information of each registered service micro service is acquired from the service discovery center;
aiming at any business microservice, the gateway microservice pulls request interface description information of the business microservice from the business microservice according to the registration information of the business microservice;
and the gateway micro service forms the request interface dictionary according to the description information of the micro service request interface of each service.
By the method, the gateway micro-service acquires the registered information of each registered service micro-service through the service discovery center, so that the gateway micro-service can accurately acquire each service micro-service of the opened service, and dynamic management of each service micro-service is facilitated. In addition, the gateway micro-service pulls the request interface description information of the business micro-service from the business micro-service according to the registration information of the business micro-service and a set mode, thereby avoiding the strong invasion of the business micro-service in the prior art.
In one possible design, obtaining registration information of each registered business microservice from the service discovery center includes:
and the gateway micro-service acquires the registered information of each service micro-service from the acquisition service interface through a monitoring mechanism.
By the method, the acquired registration information is the real-time updated data according to the monitoring mechanism of the gateway microservice, and the validity of the registration information is ensured.
In one possible design, the registration information of the business microservice includes a microservice name, an IP address where the microservice is located, and a PORT where the microservice is located;
the gateway micro-service pulling request interface description information of the business micro-service from the business micro-service according to the registration information of the business micro-service, and the method comprises the following steps:
the gateway micro-service generates a pulling request according to the IP address of the micro-service of the business micro-service and the PORT PORT of the micro-service of the business micro-service;
and the gateway micro-service pulls the request interface description information of the business micro-service from the business micro-service through the pulling request.
Through the method, the pull request is generated by utilizing the IP address and PORT PORT of the micro service of the business micro service in the registration information, and then the gateway micro service pulls the request interface description information of the business micro service from the business micro service, so that the consistency of the request interface description information and the business micro service is ensured, and the non-invasive acquisition of the request interface description information is realized.
In one possible design, the method further includes:
the gateway micro service sends the user request to a micro service system;
the gateway micro-service receives a user response fed back by the micro-service system;
and the gateway micro-service generates a log record of the user response.
By the method, the user request is distributed through the gateway micro-service, so that the user request is uniformly processed, and the user response fed back by the service system is uniformly recorded through the gateway micro-service, so that the log record is more comprehensive.
In one possible design, the first preset field includes: request path address, request mode;
the second preset field comprises at least one of: request parameters, user identification, request IP address and request time;
the third preset field comprises at least one of: request parameter format, request module name, and request function description.
Through the method, the final recordable content of the log can be obtained through the information contained in the first preset field, the second preset field and the third preset field, and the log record with a uniform format is realized.
In one possible design, each business microservice conforms to the swagger interface document generation tool architecture specification and starts swagger annotations.
By the mode, the swagger architecture specification is used for configuring the service micro-service, so that the acquisition of the interface request description data of each service micro-service can be realized without accessing the service micro-service source code or understanding the internal working mechanism, and the non-invasive acquisition of the interface description information is realized.
In one possible design, the method further includes:
the gateway micro-service monitors the business micro-services through a monitoring mechanism of the service discovery center;
and if monitoring the on-line of each business micro-service, pulling the request interface description information of each business micro-service, and updating the request interface dictionary.
By the method, the service discovery center is used for monitoring the on-line of each service microservice, the request interface description information of each service microservice is pulled, the request interface dictionary is updated, and the effectiveness of the request interface dictionary is guaranteed.
In a second aspect, an embodiment of the present invention provides a log recording apparatus, including: the device comprises an acquisition module and a recording module;
the acquisition module is used for acquiring a user request aiming at the business microservice;
determining a first preset field and a second preset field from the user request;
acquiring a third preset field corresponding to the first preset field from a request interface dictionary; the request interface dictionary is obtained by the obtaining module through each business microservice;
and the recording module is used for generating a log record of the user request at least according to the second preset field and the third preset field.
In one possible design, further comprising:
the registration module is used for registering the gateway micro-service to a service discovery center and acquiring the registration information of each registered service micro-service from the service discovery center;
the pulling module is used for pulling request interface description information of the business microservice from the business microservice according to the registration information of the business microservice aiming at any business microservice;
and the dictionary module is used for forming the request interface dictionary according to the description information of each service microservice request interface.
In one possible design, further comprising:
and the monitoring module is used for acquiring the registered information of each service microservice from the service acquisition interface through a monitoring mechanism.
In one possible design, the registration information of the business micro-service comprises a micro-service name, an IP address where the micro-service is located, and a PORT PORT where the micro-service is located;
the pull module is specifically configured to generate a pull request according to the IP address of the micro service of the service micro service and the PORT of the micro service of the service micro service;
and pulling request interface description information of the business microservice from the business microservice through the pulling request.
In one possible design, the obtaining module is further configured to send the user request to a micro-service system;
the recording module is also used for receiving user response fed back by the micro service system; generating a log record of the user response.
In a possible design, the dictionary module is further configured to determine, through a monitoring mechanism, a changed business microservice; and pulling the request interface description information of the changed business microservice, and updating the request interface dictionary.
In a third aspect, an embodiment of the present invention further provides a computing device, including: a memory for storing a computer program; a processor for calling the computer program stored in said memory and executing the method as described in the various possible designs of the first aspect according to the obtained program.
In a fourth aspect, embodiments of the present invention also provide a computer-readable non-volatile storage medium, which includes a computer-readable program, which, when read and executed by a computer, causes the computer to perform the method as set forth in the various possible designs of the first aspect.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed to be used in the description of the embodiments will be briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present application, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without inventive exercise.
Fig. 1 is a schematic diagram of a microservice system architecture for logging provided in an embodiment of the present invention;
fig. 2 is a flowchart of a log recording method according to an embodiment of the present invention;
fig. 3 is a flowchart of generating a request interface dictionary according to an embodiment of the present invention;
fig. 4 is a flowchart of a specific logging method according to an embodiment of the present invention;
fig. 5 is a schematic structural diagram of a log recording apparatus according to an embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application clearer, the present application will be described in further detail with reference to the accompanying drawings, and it is obvious that the described embodiments are only a part of the embodiments of the present application, and not all embodiments. All other embodiments obtained by a person of ordinary skill in the art based on the embodiments in the present application without making any creative effort belong to the protection scope of the present application.
Fig. 1 is a schematic diagram of a microservice system architecture for logging provided in an embodiment of the present invention. As shown in fig. 1, the microservice system 100 includes a gateway microservice 101, which implements uniform receiving and sending of user requests and user responses; business microservices 103 to 105, which are used for solving different business requests; the service discovery center 102 is used for performing registration management on each microservice (including the gateway microservice 101 and the business microservices 103 to 105).
Specifically, the micro service system 100 may be an application system developed based on a Spring Cloud micro service architecture of Java language, that is, all systems under the micro service architecture can use the log recording method to record the system request log. The Spring Cloud is derived from Spring, so that the stability and the continuity are good, the Spring Cloud is based on the Spring Boot, a whole set of solution is provided for the architecture problem of micro-service system development, compared with other frames, the Spring Cloud has the greatest support to the peripheral environment of the micro-service, the service landing is more convenient, and the framework is very suitable for being used as the micro-service in the Java field.
The GateWay microservice 101 may be a GateWay service in a Spring Cloud microservice system, and currently, mainstream gateways include Zuul and Spring Cloud GateWay.
The business microservices 103 to 105 can be developed by different teams, and then are configured with a uniform address of the service discovery center 102, so that the business microservices can be registered in the service discovery center 102. The service microservices 103 to 105 in the embodiment of the present invention may be service microservices of the same type in different fields or service microservices of different types in different fields, which is not limited in the present invention.
The service discovery center 102 may be eureka, nacos, etc., and may be implemented to register each microservice thereon for management; meanwhile, the gateway microservice 101 may obtain registration information for the business microservice from the service discovery center 102.
Based on the system architecture shown in fig. 1, as shown in fig. 2, a method for logging provided by an embodiment of the present invention includes the following steps:
and 204, generating a log record of the user request by the gateway micro-service at least according to the second preset field and the third preset field.
In the specific implementation process of step 201, since all user requests need to be uniformly distributed through the gateway due to the joining of the gateway microservice, the gateway microservice can receive the user request for the business microservice; meanwhile, the gateway micro-service is introduced, so that the problems of service dispersion, complex calling and the like caused by splitting of the micro-service are solved.
In step 202, the gateway microservice determines a first preset field and a second preset field in the user request obtained in step 201, specifically, the user request includes a plurality of fields, where the first preset field is used to search for a microservice corresponding to the user request, so that the user request can be processed through the corresponding microservice; the second preset field may be a field related to the log record in the user request, that is, some fields may be defined as the second preset field according to the log record requirement.
In the specific implementation process of step 203, the gateway microservice obtains a third preset field corresponding to the first preset field from the request interface dictionary, specifically, the log record usually needs some field information closely related to the service microservice, and these information needs to be obtained from the service microservice. Therefore, the third preset field information acquired from each service microservice in advance is stored in the request interface dictionary by introducing the request interface dictionary, so that the function of logging the gateway microservice is completed. In other words, the third preset field is a field in the log record that needs to be obtained from the service microservice.
In step 204, the gateway microserver generates a log record of the user request at least according to the second preset field determined by the gateway microserver in step 202 and according to the third preset field obtained by the gateway microserver in step 203. The log record is generated according to the second preset field and the third preset field, so that the recorded log is information with a uniform format. The specific format of the log record is based on the actual use requirement and can be designed by self-definition.
After the gateway micro-service is used for obtaining the user request aiming at the business micro-service, the gateway micro-service records the log, so that the unified format recording of the user request log and the centralized processing of the gateway micro-service are realized, log recording and management are not required to be carried out by each business micro-service, the development and maintenance cost of each business micro-service is reduced, the problem that the log cannot be analyzed due to format disorder in subsequent log statistics and analysis is solved, the log data quality is improved, and the efficiency of statistical analysis is improved. Compared with the mode that the log is subjected to log standardized processing according to a user-defined processing method in the public SDK by calling the public SDK, the method can realize log recording of different types of micro services in different fields, in other words, no requirement is made on the types of the micro services.
For the formation of the request interface dictionary, a specific implementation is provided as follows:
before step 201, the gateway micro-service registers to a service discovery center, and acquires registered information of each service micro-service from the service discovery center; aiming at any business microservice, the gateway microservice pulls request interface description information of the business microservice from the business microservice according to the registration information of the business microservice; and the gateway micro-service forms the request interface dictionary according to the description information of each service micro-service request interface.
For example, if the business microservices registered in the service discovery center are the business microservices A, B and C, the registration information A1, B1 and C1 are respectively provided for the business microservices A, B and C. Since the gateway microservice is registered to the service discovery center, the gateway microservice can obtain the registration information A1, B1 and C1 corresponding to the business microservices A, B and C through the service discovery center. Then, the gateway micro-service pulls the request interface description information of the business micro-service A from the corresponding business micro-service A aiming at the registration information A1 of the business micro-service A, pulls the request interface description information of the business micro-services B and C in the same way, and further combines the obtained request description information of the business micro-services A, B and C to obtain a request interface dictionary with the request description information of the business micro-services A, B and C.
It should be understood that before the gateway microservice is registered to the service discovery center, the service discovery center needs to be created to ensure that each service microservice is registered to the same service discovery center, and a request interface dictionary for the gateway microservice to form a user request is used for support by pulling request interface description information of each service microservice.
Another possible implementation manner is that after the service is started, each service microservice actively registers to the gateway microservice according to the address of the gateway microservice configured in advance; and then the gateway micro-service pulls the request interface description information of the business micro-service from the business micro-service according to the registration information of each business micro-service so as to form a request interface dictionary. Or after the service is started, each service micro service actively sends respective request interface description information to the gateway micro service according to the address of the gateway micro service configured in advance so as to form a request interface dictionary.
Aiming at the registration information of the business micro-services acquired from the service discovery center, in order to ensure the accuracy of the acquired registration information of each business micro-service, one possible implementation manner is as follows: and the gateway micro-service monitors the service discovery center through a monitoring mechanism. For example, the gateway microservice acquires the registration information A1, B1 and C1 of the business microservices A, B and C registered in the service discovery center at the previous moment, and a newly added business microservice D is registered in the service discovery center at the current moment, and the gateway microservice monitors the service discovery center in real time according to a monitoring mechanism of the gateway microservice, that is, the gateway microservice can monitor the newly added business microservice D, so that the registration information D1 of the business microservice D acquired by the gateway microservice ensures the accuracy of the acquired registration information of each business microservice.
Aiming at gateway micro service, pulling request interface description information of the service micro service, wherein one possible implementation mode is that the registration information of the service micro service comprises a micro service name, an IP address of the micro service and a PORT PORT of the micro service; the gateway micro service generates a pulling request according to the IP address of the micro service of the business micro service and the PORT PORT of the micro service of the business micro service; and the gateway micro-service pulls the request interface description information of the business micro-service from the business micro-service through the pulling request.
For example, when the gateway micro service acquires the registration information A1 of the service micro service a, a pull request is generated according to the registration information A1 including the IP address of the service micro service a and the PORT of the service micro service, and the gateway micro service pulls the request interface description information in the service micro service a from the service micro service through the pull request of the service micro service a.
For each service micro-service registered to the service discovery center, one possible implementation is that the service micro-service generates a tool architecture specification for complying with the swagger interface document and starts swagger annotation. Therefore, complete and uniform request interface description information is provided for the gateway micro-service through each service micro-service following swagger, and a request interface dictionary is formed for the gateway micro-service to extract the required request interface description information for supporting. That is, the gateway microservice pulls the request interface description information of each service from each service microservice conforming to the swagger architecture specification, and further generates a log record of the user request according to step 203 and step 204.
The swagger architecture is a simple and powerful Application Programming Interface (API) document generation tool. The tool is integrated in the project, an API document display page can be automatically generated for the user according to the configuration information of the user, the interface information in the project can be directly accessed and viewed in a browser, simultaneously each API interface can be tested, the API document generated by the Swagger is updated in real time, and the API interface can be timely displayed in the document after any change.
Through the mode, each service micro service following the swagger architecture specification is configured, so that the request interface description information of each service micro service can be acquired by using the IP address and PORT PORT of the micro service of each service micro service without accessing a service micro service source code or understanding an internal working mechanism, the information is prevented from being directly called from each service micro service, the non-invasive interface description information acquisition is realized, meanwhile, the acquired registration information is real-time updated data according to the monitoring mechanism of the gateway micro service, and the validity of the registration information is ensured; the gateway micro-service forms a request interface dictionary according to the description information of each service micro-service request interface, and has the characteristics of high readability and convenience for generating a subsequent user request log.
For the first preset field and the second preset field determined by the gateway microservice from the user request and the third preset field corresponding to the second preset field, a possible implementation manner is that the first preset field includes: the second preset field comprises at least one of request parameters, user identification, request IP address and request time; the third preset field comprises at least one of a request parameter format, a request module name and a request function description.
The gateway microservice further determines a first preset field and a second preset field in the user request by acquiring a Uniform Resource Locator (Uniform Resource Locator) URL of the user request according to analysis of the URL, and since the gateway microservice acquires the URL of the user request and can analyze and determine various types of data information of the user request, a person skilled in the art can modify or add other information to the second preset field information based on understanding of log records, which is not particularly limited in the present invention. As long as the second preset field information recorded in the generated log is consistent with the second preset field determined from the user request. It should be noted that the request interface dictionary may include five types of static information data, i.e., a request path address, a request mode, a request parameter format, a request module name, and a request function description, and in an actual log record, a third preset field corresponding to the second preset field may be determined as needed.
For example, the current user request URL is: https:// xueshu.baidu.com/usercenter/paper/showppageid = e78ecbb367627234e29b0f6235e7dfdd, after the gateway micro-service acquires the user request, the gateway micro-service analyzes the user request URL, and can determine a first preset field and a second preset field, namely, the request path can be analyzed as follows: /usercenter/paper/show; because the request parameter methods carried by different request modes are different, and the request parameters submitted by the Get method are directly filled in the URL of the request message, that is, it can be directly known from the URL that paper id = e78ecbb367627234e29b0f6235e7dfdd is the request parameter, therefore, it can be known that the request mode is the Get method. It should be noted that there are various request modes requested by the user, such as Get, post, and Head, and different request modes carry different request parameter methods, some request parameters can be directly known from the URL, some request parameters are attached to the code and need to be parsed from the code. The embodiments of the present invention are not described in detail. The user identification, the request IP address and the request time can be known when the gateway micro service acquires the user request, the request time refers to the time when the gateway micro service acquires the user request, and the user identification and the request IP address information realize that the user request acquired by the gateway micro service corresponds to the corresponding micro service one by one.
After step 202, according to the external unified user request forwarding function of the gateway microservice, one possible implementation manner is: the gateway micro service sends the user request to a micro service system; the gateway micro-service receives a user response fed back by the micro-service system; and the gateway microservice generates a log record of the user response.
Aiming at the log record of the user response, after the user request is processed by the micro-service system, the micro-service system still can pass the feedback user response through the gateway micro-service and then return the user response to the user. Therefore, according to the requirement, after receiving the user response fed back by the micro service system through the gateway micro service, the log record of the user response can be generated.
The log record of the user response is not limited, for example, the time consumed by the request can be recorded to determine the duration of the gateway micro-service from the moment when the user request is received to the moment when the gateway micro-service is processed by the micro-service system and returns to the moment when the gateway micro-service is returned; the request status may also be recorded to determine whether the user requested logging is complete, for example, the request status is 200, which indicates logging was successful, the request status is 500, and logging failed. The log records of the user response are not repeated in the embodiment of the application.
Fig. 3 is a flowchart of generating a request interface dictionary according to an embodiment of the present invention, which specifically includes the following steps:
in the development of the micro-services, in order to facilitate the communication among the micro-services of each service, the micro-services provide a service discovery and registration center component, and each micro-service of the service can be registered on the service discovery center to realize the service discovery and realize the unified access and management.
in the embodiment of the invention, each business microservice can be developed by different teams, and only needs to configure a uniform service discovery center address and register the service discovery center address to the service discovery center after the business microservice is completed. And each business micro service does not need to develop related functions of logs, only needs to follow the swagger architecture specification, and enables the @ EnablSwagger configuration when the micro service is started. Meanwhile, each service micro service is registered to a uniform service center, the gateway micro service can be ensured to access each service micro service registered to the service discovery center, and then the gateway micro service forms the request interface dictionary according to the description information of each service micro service request interface.
it should be noted that, in the above steps, step 302 and step 303 may be executed synchronously, and are not in sequence. The gateway micro service is developed based on a micro service gateway component, and the gateway micro service is mainly used as an externally unified request forwarding service, so that the functions of shielding various business micro services externally, providing unified access and the like are realized.
Step 304, the gateway micro-service pulls the request interface description data of the business micro-service to form a request interface dictionary;
the gateway micro-service and each business micro-service are registered in the same service discovery center, so that the gateway micro-service can access the service discovery center, all business micro-services registered in the service discovery center are acquired by using a getInstance () method, registration information is acquired, a pulling request is generated according to an IP address where the micro-service of the business micro-service is located and a PORT PORT where the micro-service of the business micro-service is located, all business micro-services are traversed, HTTP:// IP is accessed, PORT/swagger-ui/index. For example, an embodiment of the present invention provides an example of a request interface dictionary, where the request interface dictionary includes five types of static information data: request path address, request mode, request parameter format, request module name and request function description.
Table 1 request interface dictionary example
As shown in table 1, the request interface dictionary includes five types of static information data, and the gateway microserver obtains a third preset field corresponding to a first preset field from the request interface dictionary according to the first preset field, that is, a request path address, a request mode and the request interface dictionary, that is, at least one log of a request parameter format, a request module name and a request function description can be obtained.
And 305, monitoring the online of each service microservice by the gateway microservice, and updating the request interface dictionary in time.
Aiming at the possible real-time change of the interface information of each business micro-service, the gateway micro-service starts a monitoring mechanism for the service discovery center, monitors the online of each business micro-service in the service discovery center by using a Lister () method, pulls the latest request interface description information and replaces and covers the original request interface dictionary when the business micro-service is discovered to be online, thereby ensuring the effectiveness of the request interface dictionary.
Fig. 4 is a flowchart of a specific log recording method provided in an embodiment of the present invention, which specifically includes the following steps:
steps 402-405 (synchronization steps 201-204) enable logging of user requests through the gateway microservice.
and logging in the gateway micro service, and simultaneously executing and distributing the user request to the corresponding micro service system, so that the user request is processed by the corresponding micro service.
and returning the user response processed by the micro service system to the gateway micro service, wherein the gateway micro service can record the required user response according to actual needs after receiving the user response fed back by the micro service system, namely, the step 409 can be executed, so that the log record of the user response by the gateway micro service is realized. It is understood that step 409 may not be executed if the user response does not need to be logged, and the embodiment of the present invention is not limited thereto.
The user response is returned to the user, step 410.
The user response processed by the micro service system is uniformly forwarded by the gateway micro service, so that the user response is returned to the user.
From the above, it can be seen that: the embodiment of the invention provides a log recording method and a log recording device.A gateway micro-service acquires a user request aiming at a business micro-service; the gateway micro-service determines a first preset field and a second preset field from the user request; the gateway micro-service acquires a third preset field corresponding to the first preset field from the request interface dictionary; the request interface dictionary is obtained by the gateway micro service through each service micro service; and the gateway micro-service generates a log record of the user request at least according to the second preset field and the third preset field. After a user request aiming at the business microservice is obtained, the gateway microservice is used for log recording, so that unified format recording and centralized processing of user request logs are realized, log recording and management are not required to be carried out by each business microservice, development and maintenance cost of each business microservice is reduced, the problem that analysis cannot be carried out due to format disorder in follow-up log statistics and analysis is solved, log data quality is improved, and statistical analysis efficiency is improved.
Fig. 5 is a schematic structural diagram of a logging apparatus according to an embodiment of the present invention.
Based on the same conception, the embodiment of the invention provides a log recording device, which is used for realizing any log recording method in the above embodiments. As shown in fig. 5, the logging apparatus 500 includes: an obtaining module 501 and a recording module 506, wherein:
an obtaining module 501, configured to obtain a user request for a business microservice;
determining a first preset field and a second preset field from the user request;
acquiring a third preset field corresponding to the first preset field from a request interface dictionary; the request interface dictionary is obtained by the obtaining module through each service microservice;
a recording module 506, configured to generate a log record of the user request according to at least the second preset field and the third preset field.
In one possible design, further comprising:
a registration module 502, configured to register a gateway microservice to a service discovery center, and obtain registration information of each registered service microservice from the service discovery center;
a pulling module 503, configured to pull, for any service microservice, request interface description information of the service microservice from the service microservice according to registration information of the service microservice;
the dictionary module 504 is configured to form the request interface dictionary according to the description information of each service microservice request interface.
In one possible design, further comprising:
and the monitoring module 505 is configured to acquire, through a monitoring mechanism, the registration information of each registered service microservice from the acquisition service interface.
In one possible design, the registration information of the business microservice includes a microservice name, an IP address where the microservice is located, and a PORT where the microservice is located;
the pulling module 503 is specifically configured to generate a pulling request according to the IP address of the micro service of the service micro service and the PORT of the micro service of the service micro service;
and pulling request interface description information of the business microservice from the business microservice through the pulling request.
In a possible design, the obtaining module 501 is further configured to send the user request to a micro service system;
the recording module 506 is further configured to receive a user response fed back by the micro service business system; generating a log record of the user response.
In a possible design, the dictionary module 504 is further configured to determine, through a listening mechanism, a changed business microservice; and pulling the request interface description information of the changed business microservice, and updating the request interface dictionary.
Based on the same inventive concept, the embodiment of the present invention further provides another computer device, which may specifically be a desktop computer, a portable computer, a smart phone, a tablet computer, a Personal Digital Assistant (PDA), and the like. The computer device may include a Central Processing Unit (CPU), a memory, an input/output device, etc., the input device may include a keyboard, a mouse, a touch screen, etc., and the output device may include a Display device, such as a Liquid Crystal Display (LCD), a Cathode Ray Tube (CRT), etc.
The memory may include Read Only Memory (ROM) and Random Access Memory (RAM), and provides the processor with program instructions and data stored in the memory. In an embodiment of the present invention, the memory may be used to store a program of the above-described logging method.
The processor is used for executing the log recording method according to the obtained program instruction by calling the program instruction stored in the memory.
Based on the same inventive concept, embodiments of the present invention provide a computer storage medium for storing computer program instructions for the computer apparatus, which includes a program for executing the logging method.
The computer storage media may be any available media or data storage device that can be accessed by a computer, including, but not limited to, magnetic memory (e.g., floppy disks, hard disks, magnetic tape, magneto-optical disks (MOs), etc.), optical memory (e.g., CDs, DVDs, BDs, HVDs, etc.), and semiconductor memory (e.g., ROMs, EPROMs, EEPROMs, non-volatile memory (NAND FLASH), solid State Disks (SSDs)), etc.
It will be apparent to those skilled in the art that various modifications and variations can be made in the embodiments of the present invention without departing from the spirit and scope of the application. Thus, if such modifications and variations of the embodiments of the present invention fall within the scope of the claims of the present application and their equivalents, the present application is also intended to encompass such modifications and variations.
Claims (8)
1. A method of logging, the method comprising:
the gateway micro-service acquires a user request aiming at the business micro-service;
the gateway micro-service determines a first preset field and a second preset field from the user request; the first preset field is used for determining the business microservice corresponding to the user request; the second preset field is a field related to the log record in the user request;
the gateway micro-service acquires a third preset field corresponding to the first preset field from a request interface dictionary; the request interface dictionary is obtained by the gateway micro service through each service micro service; the third preset field is a field which needs to be acquired from the business microservice in the log record;
the gateway micro-service generates a log record of the user request at least according to the second preset field and the third preset field;
the first preset field includes: request path address, request mode;
the second preset field comprises at least one of: request parameters, user identification, request IP address and request time;
the third preset field comprises at least one of: request parameter format, request module name and request function description;
the request interface dictionary is obtained by the gateway micro service through each service micro service, and comprises the following steps:
the gateway micro-service is registered to a service discovery center, and registration information of each registered service micro-service is acquired from the service discovery center;
aiming at any business microservice, the gateway microservice pulls request interface description information of the business microservice from the business microservice according to the registration information of the business microservice;
and the gateway micro-service forms the request interface dictionary according to the description information of each service micro-service request interface.
2. The method of claim 1, wherein obtaining registration information of each registered business microservice from the service discovery center comprises:
and the gateway micro-service acquires the registered information of each service micro-service from the acquisition service interface through a monitoring mechanism.
3. The method according to claim 1, wherein the registration information of the business microservice comprises a microservice name, an IP address where the microservice is located, and a PORT PORT where the microservice is located;
the gateway micro-service pulling request interface description information of the business micro-service from the business micro-service according to the registration information of the business micro-service, and the method comprises the following steps:
the gateway micro-service generates a pulling request according to the IP address of the micro-service of the business micro-service and the PORT PORT of the micro-service of the business micro-service;
and the gateway micro-service pulls the request interface description information of the business micro-service from the business micro-service through the pulling request.
4. The method according to any one of claims 1 to 3, further comprising:
the gateway micro service sends the user request to a micro service system;
the gateway micro-service receives a user response fed back by the micro-service system;
and the gateway micro-service generates a log record of the user response.
5. The method of claim 4, wherein each business micro-service conforms to a swagger interface document generation tool architecture specification and turns on swagger annotations.
6. A logging apparatus, comprising: the device comprises an acquisition module and a recording module;
the acquisition module is used for acquiring a user request aiming at the business microservice;
determining a first preset field and a second preset field from the user request; the first preset field is used for determining the business microservice corresponding to the user request; the second preset field is a field related to the log record in the user request;
acquiring a third preset field corresponding to the first preset field from a request interface dictionary; the request interface dictionary is obtained by the obtaining module through each service microservice; the third preset field is a field which needs to be obtained from the business microservice in the log record;
the recording module is used for generating a log record of the user request at least according to the second preset field and the third preset field;
the first preset field includes: request path address, request mode;
the second preset field comprises at least one of: request parameters, user identification, request IP address and request time;
the third preset field comprises at least one of: request parameter format, request module name and request function description;
further comprising:
the registration module is used for registering the gateway micro-service to a service discovery center and acquiring the registration information of each registered service micro-service from the service discovery center;
the pulling module is used for pulling request interface description information of the business microservice from the business microservice according to the registration information of the business microservice aiming at any business microservice;
and the dictionary module is used for forming the request interface dictionary according to the description information of each service microservice request interface.
7. A computing device, comprising:
a memory for storing program instructions;
a processor for calling program instructions stored in said memory to execute the method of any one of claims 1 to 5 in accordance with the obtained program.
8. A computer-readable storage medium having stored thereon computer-executable instructions for causing a computer to perform the method of any one of claims 1-5.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010949189.4A CN112202598B (en) | 2020-09-10 | 2020-09-10 | Log recording method and device |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010949189.4A CN112202598B (en) | 2020-09-10 | 2020-09-10 | Log recording method and device |
Publications (2)
Publication Number | Publication Date |
---|---|
CN112202598A CN112202598A (en) | 2021-01-08 |
CN112202598B true CN112202598B (en) | 2022-12-27 |
Family
ID=74015668
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202010949189.4A Active CN112202598B (en) | 2020-09-10 | 2020-09-10 | Log recording method and device |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN112202598B (en) |
Families Citing this family (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN113449339A (en) * | 2021-06-29 | 2021-09-28 | 平安资产管理有限责任公司 | Log collection method, system, computer device and computer readable storage medium |
CN113641355A (en) * | 2021-08-11 | 2021-11-12 | 杭州安恒信息技术股份有限公司 | Interface document generation method, system and storage medium |
CN113901097A (en) * | 2021-10-12 | 2022-01-07 | 山东可信云信息技术研究院 | Method and system for quickly searching service link and service under micro-service architecture |
CN113971252A (en) * | 2021-10-28 | 2022-01-25 | 上海上讯信息技术股份有限公司 | Log recording method and device |
Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN108847989A (en) * | 2018-06-29 | 2018-11-20 | 杭州安恒信息技术股份有限公司 | Log processing method, business service system and electronic equipment based on micro services framework |
CN110995873A (en) * | 2019-12-27 | 2020-04-10 | 美的集团股份有限公司 | Gateway service interface discovery method, system, electronic device and storage medium |
CN111459756A (en) * | 2020-03-30 | 2020-07-28 | 深圳市金蝶天燕云计算股份有限公司 | Log processing method and related equipment |
Family Cites Families (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102891873B (en) * | 2011-07-21 | 2017-02-15 | 腾讯科技(深圳)有限公司 | Method for storing log data and log data storage system |
IN201911007700A (en) * | 2019-02-27 | 2019-03-22 | ||
CN110069941A (en) * | 2019-03-15 | 2019-07-30 | 深圳市买买提信息科技有限公司 | A kind of interface access authentication method, apparatus and computer-readable medium |
CN110175161B (en) * | 2019-04-25 | 2023-11-14 | 平安科技(深圳)有限公司 | Method, device, computer equipment and storage medium for recording log |
CN110944000B (en) * | 2019-12-05 | 2021-09-28 | 美味不用等(上海)信息科技股份有限公司 | OpenResty gateway feature anti-brushing method based on multi-Agent cluster |
-
2020
- 2020-09-10 CN CN202010949189.4A patent/CN112202598B/en active Active
Patent Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN108847989A (en) * | 2018-06-29 | 2018-11-20 | 杭州安恒信息技术股份有限公司 | Log processing method, business service system and electronic equipment based on micro services framework |
CN110995873A (en) * | 2019-12-27 | 2020-04-10 | 美的集团股份有限公司 | Gateway service interface discovery method, system, electronic device and storage medium |
CN111459756A (en) * | 2020-03-30 | 2020-07-28 | 深圳市金蝶天燕云计算股份有限公司 | Log processing method and related equipment |
Also Published As
Publication number | Publication date |
---|---|
CN112202598A (en) | 2021-01-08 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN112202598B (en) | Log recording method and device | |
US10705942B1 (en) | Simulated testing of API | |
US20210318866A1 (en) | Auto-generation of api documentation via implementation-neutral analysis of api traffic | |
WO2020119434A1 (en) | Method and apparatus for interface data processing, method and apparatus for automated testing, device, and medium | |
US11537606B2 (en) | Solution for implementing computing service based on structured query language statement | |
US9231819B2 (en) | Abstracting restful web service HTTP between a client and a server | |
US8543972B2 (en) | Gateway data distribution engine | |
AU2016302371A1 (en) | Building and managing data-processing attributes for modeled data sources | |
US20060047496A1 (en) | Method, system and program product for recording and replaying target service interaction data | |
US20140157228A1 (en) | Method and system for automatically generating a restful web service software development kit client | |
US20100094884A1 (en) | Representational state transfer (rest) service import editor | |
US12088685B2 (en) | Platform for multi-stream sampling and visualization | |
JP2021111403A (en) | Landing page processing method, apparatus, device and medium | |
WO2021155683A1 (en) | Log printing method and apparatus, electronic device, and storage medium | |
CN113836014A (en) | Interface testing method and device, electronic equipment and storage medium | |
CN114816499A (en) | Electronic resource sharing method and device and storage medium | |
CN113138757A (en) | Method, device, server, system and medium for automatically generating front-end code | |
CN115277657A (en) | Method and device for operation and maintenance of database protocol | |
CN111767229A (en) | Performance test method, device and equipment | |
US11237889B1 (en) | Application infrastructure configuration based on annotated API schemas | |
CN112597036B (en) | Universal baffle plate testing method and device | |
CN115934537A (en) | Interface test tool generation method, device, equipment, medium and product | |
CN112988872B (en) | Interface document management method and device, storage medium and electronic equipment | |
WO2019122011A1 (en) | Computer system and method for extracting dynamic content from websites | |
US20140101280A1 (en) | Generic serializer framework |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |