CN112202598A - Log recording method and device - Google Patents

Log recording method and device Download PDF

Info

Publication number
CN112202598A
CN112202598A CN202010949189.4A CN202010949189A CN112202598A CN 112202598 A CN112202598 A CN 112202598A CN 202010949189 A CN202010949189 A CN 202010949189A CN 112202598 A CN112202598 A CN 112202598A
Authority
CN
China
Prior art keywords
service
micro
request
gateway
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.)
Granted
Application number
CN202010949189.4A
Other languages
Chinese (zh)
Other versions
CN112202598B (en
Inventor
陈屹
孙希展
段雅鑫
陈维强
孙永良
于涛
王玮
孙镜涛
王中伟
李建伟
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Hisense TransTech Co Ltd
Original Assignee
Hisense TransTech Co Ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by Hisense TransTech Co Ltd filed Critical Hisense TransTech Co Ltd
Priority to CN202010949189.4A priority Critical patent/CN112202598B/en
Publication of CN112202598A publication Critical patent/CN112202598A/en
Application granted granted Critical
Publication of CN112202598B publication Critical patent/CN112202598B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L41/00Arrangements for maintenance, administration or management of data switching networks, e.g. of packet switching networks
    • H04L41/06Management of faults, events, alarms or notifications
    • H04L41/069Management of faults, events, alarms or notifications using logs of notifications; Post-processing of notifications
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/50Network services
    • H04L67/51Discovery or management thereof, e.g. service location protocol [SLP] or web services
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/50Network services
    • H04L67/60Scheduling or organising the servicing of application requests, e.g. requests for application data transmissions using the analysis and optimisation of the required network resources

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

Log recording method and device
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, log formats recorded by each micro service may be completely different, 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 dispersion of log records and the high 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 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.
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 using the IP address and PORT PORT where the micro service of the business micro service in the registration information is located, 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 service microservice, pulling the request interface description information of each service microservice, 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 service 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 microservice includes a microservice name, an IP address where the microservice is located, and a PORT where the microservice is located;
the pulling module is specifically configured to generate a pulling request according to an IP address of the micro service of the service micro service and a 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 the 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, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within 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; the business microservices 103-105 are used for solving different business requests; and the service discovery center 102 is used for registering and managing each micro service (comprising the gateway micro service 101 and the service micro services 103-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 scheme can be provided for the architecture problem of micro-service system development, compared with other frames, the Spring Cloud has the largest support force on the micro-service surrounding environment, the service landing is more convenient, and the framework is very suitable for being used as 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-105 can be developed by different teams, and then are configured with the unified address of the service discovery center 102, so that the business microservices can be registered in the service discovery center 102. The business microservices 103 to 105 in the embodiment of the invention can be business microservices of the same type in different fields or business microservices of different types in different fields, and the invention is not limited.
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 microservices 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:
step 201, a gateway micro-service acquires a user request aiming at a business micro-service;
step 202, the gateway microservice determines a first preset field and a second preset field from the user request;
step 203, 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 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 business microservices A, B and C have registration information a1, B1 and C1, respectively. Since the gateway microservice is registered to the service discovery center, the gateway microservice can acquire the registration information a1, B1 and C1 corresponding to the business microservice A, B and C through the service discovery center. Then, the gateway microserver pulls the request interface description information of the service microserver a from the corresponding service microserver a for the registration information a1 of the service microserver a, and similarly pulls the request interface description information of the service microservers B and C, and further combines the acquired request description information of the service microservers A, B and C to obtain a request interface dictionary with the request description information of the service microservers 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 microservices acquired from the service discovery center, in order to ensure the accuracy of the acquired registration information of each business microservices, one possible implementation mode 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 service microservices A, B and C registered to the service discovery center at the previous moment, and a newly added service microservice D is registered to 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 service microservice D, so that the registration information D1 of the service microservice D acquired by the gateway microservice ensures the accuracy of the acquired registration information of each service 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 that includes 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 supporting the gateway micro-service by extracting the required request interface description information. 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/showpaperid ═ 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 methods 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, so it can be known that the request method 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 function of forwarding the user request uniformly to the outside 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 micro-service 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 that logging is successful, the request status is 500, and logging is 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:
step 301, creating a service discovery center;
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.
Step 302, developing a business microservice and registering the business microservice to a service discovery center;
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 service micro service does not need to develop related functions of logs, only needs to follow swagger architecture specifications, and starts 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.
Step 303, developing gateway microservices and registering the gateway microservices to a service discovery center;
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 service micro-service are registered in the same service discovery center, so that the gateway micro-service can access the service discovery center, all the service micro-services registered in the service discovery center are acquired by using a getInstance () method, registration information is acquired, further, according to an IP address of the micro-service of the service micro-service and a PORT PORT of the micro-service of the service micro-service, a pulling request is generated, all the service micro-services are traversed, HTTP:// IP is accessed, PORT/swagger-ui/index.json is accessed, request interface description information of the service micro-service is pulled from the service micro-service, and further, a request interface dictionary is generated. 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
Figure BDA0002676345560000131
Figure BDA0002676345560000141
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 possibility that the interface information of each service micro-service may change in real time, the gateway micro-service starts a monitoring mechanism for the service discovery center, monitors the on-line of each service micro-service in the service discovery center by using a Lister () method, pulls the latest request interface description information when the service micro-service is found to be on-line, and replaces and covers the original request interface dictionary, 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:
step 401, a user sends a request;
and step 402-405 (same as step 201-204) realizes the log record of the user request through the gateway microservice.
Step 406, distributing to the corresponding micro service system;
step 407, the micro service system processes the user request;
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.
Step 408, the gateway microservice obtains a user response;
step 409, recording a user response log;
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 log recording 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 obtain, through a monitoring mechanism, registration information of each registered service microservice from the service obtaining 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 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 (10)

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 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.
2. The method of claim 1, wherein the request interface dictionary is obtained by the gateway microservice via a respective service microservice, comprising:
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.
3. The method of claim 2, 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.
4. The method of claim 2, wherein the registration information of the business microservice comprises 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.
5. The method according to any one of claims 1 to 4, 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.
6. The method of claim 5,
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.
7. The method of claim 5, wherein each business microservice conforms to a swagger interface document generation tool architecture specification and turns swagger annotations on.
8. 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;
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;
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.
9. 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 7 in accordance with the obtained program.
10. 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-7.
CN202010949189.4A 2020-09-10 2020-09-10 Log recording method and device Active CN112202598B (en)

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 true CN112202598A (en) 2021-01-08
CN112202598B 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)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113641355A (en) * 2021-08-11 2021-11-12 杭州安恒信息技术股份有限公司 Interface document generation method, system and storage medium

Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102891873A (en) * 2011-07-21 2013-01-23 腾讯科技(深圳)有限公司 Method for storing log data and log data storage system
CN108847989A (en) * 2018-06-29 2018-11-20 杭州安恒信息技术股份有限公司 Log processing method, business service system and electronic equipment based on micro services framework
CN110069941A (en) * 2019-03-15 2019-07-30 深圳市买买提信息科技有限公司 A kind of interface access authentication method, apparatus and computer-readable medium
CN110175161A (en) * 2019-04-25 2019-08-27 平安科技(深圳)有限公司 Method, apparatus, computer equipment and the storage medium of record log
CN110944000A (en) * 2019-12-05 2020-03-31 美味不用等(上海)信息科技股份有限公司 OpenResty gateway feature anti-brushing method based on multi-Agent cluster
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
US20200272912A1 (en) * 2019-02-27 2020-08-27 Hcl Technologies Limited System for allowing a secure access to a microservice

Patent Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102891873A (en) * 2011-07-21 2013-01-23 腾讯科技(深圳)有限公司 Method for storing log data and log data storage system
CN108847989A (en) * 2018-06-29 2018-11-20 杭州安恒信息技术股份有限公司 Log processing method, business service system and electronic equipment based on micro services framework
US20200272912A1 (en) * 2019-02-27 2020-08-27 Hcl Technologies Limited System for allowing a secure access to a microservice
CN110069941A (en) * 2019-03-15 2019-07-30 深圳市买买提信息科技有限公司 A kind of interface access authentication method, apparatus and computer-readable medium
CN110175161A (en) * 2019-04-25 2019-08-27 平安科技(深圳)有限公司 Method, apparatus, computer equipment and the storage medium of record log
CN110944000A (en) * 2019-12-05 2020-03-31 美味不用等(上海)信息科技股份有限公司 OpenResty gateway feature anti-brushing method based on multi-Agent cluster
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

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113641355A (en) * 2021-08-11 2021-11-12 杭州安恒信息技术股份有限公司 Interface document generation method, system and storage medium

Also Published As

Publication number Publication date
CN112202598B (en) 2022-12-27

Similar Documents

Publication Publication Date Title
US20210318866A1 (en) Auto-generation of api documentation via implementation-neutral analysis of api traffic
US10705942B1 (en) Simulated testing of API
US10839038B2 (en) Generating configuration information for obtaining web resources
US9038015B1 (en) System and method for creating a development and operational platform for mobile applications
US9231819B2 (en) Abstracting restful web service HTTP between a client and a server
AU2016302371A1 (en) Building and managing data-processing attributes for modeled data sources
US8073887B2 (en) Representational state transfer (REST) service import editor
JP2021111403A (en) Landing page processing method, apparatus, device and medium
CN103885878A (en) Method and device for generating browser testing script
CN111767229A (en) Performance test method, device and equipment
CN112202598B (en) Log recording method and device
US11237889B1 (en) Application infrastructure configuration based on annotated API schemas
CN112417016B (en) Data exchange method, system, equipment and storage medium
CN113836014A (en) Interface testing method and device, electronic equipment and storage medium
WO2021155683A1 (en) Log printing method and apparatus, electronic device, and storage medium
US9258311B2 (en) Virtual federation of remote portals
US20220353351A1 (en) Platform for multi-stream sampling and visualization
CN115277657A (en) Method and device for operation and maintenance of database protocol
CN115145652A (en) Method, device, equipment and medium for creating data processing task
CN113485927A (en) Test data generation method, device, equipment and storage medium
CN112988872A (en) Interface document management method and device, storage medium and electronic equipment
CN114817794A (en) Webpage content control method, device, equipment and medium
US20070240048A1 (en) A standard communication interface for server-side filter objects
CN112347382A (en) Product page sharing method and device and electronic equipment
AU2018390863A1 (en) Computer system and method for extracting dynamic content from websites

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