Disclosure of Invention
In view of the above, the present invention provides an API request replay method, system and computer-readable storage medium, which solve the problem that when an API request is replayed, only an API request causing an exception can be replayed, and an associated series of API requests cannot be replayed.
Based on the above object, an aspect of the embodiments of the present invention provides an API request replay method, where the method performs the following steps at a client:
allocating an identifier for the API request, and calculating the value of each part of the identifier;
adding the identification to a Header of the API request;
the identified API request is sent to the server.
In some embodiments, the identifying comprises: a function module number, a service operation number, a behavior operation number, and an API request timestamp.
In some embodiments, the service operation number is a universal unique identification code.
On the other hand, the embodiment of the invention also provides an API request replay method, which executes the following steps on the server:
obtaining API requests from a server log, and grouping the API requests based on the identifier of the API requests;
ordering the API requests of each group based on the identity of the API requests;
and replaying the API request of each group after the sorting.
In some embodiments, grouping API requests based on their identification includes:
and acquiring the functional module number and the service operation number of the API request from the identifier of the API request, and grouping the API request based on the functional module number and the service operation number.
In some embodiments, ordering the API requests of each group based on the identification of the API requests comprises:
and acquiring a behavior operation number and an API request timestamp of the API request from the identifier of the API request, and sequencing the API requests of each group based on the behavior operation number and the API request timestamp.
In some embodiments, grouping API requests based on the functional module number and the business operation number comprises:
and distributing the API requests with the consistent functional module numbers and the consistent service operation numbers to the same group.
In another aspect of the embodiments of the present invention, there is also provided an API request replay system, where the replay system includes a client, and the client includes:
the distribution module is configured to distribute identifiers for the API requests and calculate values of all parts of the identifiers;
an add module configured to add the identification to a Header of the API request;
a sending module configured to send the API request with the identification added to a server.
In another aspect of the embodiments of the present invention, there is also provided an API request replay system, where the replay system includes a server, and the server includes:
the grouping module is configured to acquire the API requests from the server log and group the API requests based on the identifier of the API requests;
an ordering module configured to order the API requests of each group based on the identity of the API requests;
a replay module configured to replay the ordered API requests of each group.
In another aspect of the embodiments of the present invention, a computer-readable storage medium is further provided, in which a computer program for implementing the following method steps when executed by a processor is stored:
the method comprises the following steps of:
allocating an identifier for the API request, and calculating the value of each part of the identifier;
adding the identification to a Header of the API request;
the identified API request is sent to the server.
In some embodiments, the identifying comprises: a function module number, a service operation number, a behavior operation number, and an API request timestamp.
In some embodiments, the service operation number is a universal unique identification code.
The method executes the following steps at the server:
obtaining API requests from a server log, and grouping the API requests based on the identifier of the API requests;
ordering the API requests of each group based on the identity of the API requests;
and replaying the API request of each group after the sorting.
In some embodiments, grouping API requests based on their identification includes:
and acquiring the functional module number and the service operation number of the API request from the identifier of the API request, and grouping the API request based on the functional module number and the service operation number.
In some embodiments, ordering the API requests of each group based on the identification of the API requests comprises:
and acquiring a behavior operation number and an API request timestamp of the API request from the identifier of the API request, and sequencing the API requests of each group based on the behavior operation number and the API request timestamp.
In some embodiments, grouping API requests based on the functional module number and the business operation number comprises:
and distributing the API requests with the consistent functional module numbers and the consistent service operation numbers to the same group.
The invention has at least the following beneficial technical effects: the client establishes the personalized identifier of the API request and calculates the value of the personalized identifier, so that different API requests can be distinguished, and a basis is provided for a subsequent server to replay the associated API request; the server obtains a series of API requests with context association by attributing the API requests with the same function module number and the same service operation number to the same group and sequencing each API request according to the behavior operation number and the API request timestamp in the same group, thereby providing convenience for positioning faults through API replay and shortening troubleshooting time.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the following embodiments of the present invention are described in further detail with reference to the accompanying drawings.
For better understanding of the embodiments of the present invention, related technical terms related to the embodiments of the present invention are described below.
API: application Programming Interface is some predefined interfaces (such as functions, HTTP interfaces), or refers to the convention for linking different components of a software system. The API is a set of definitions, procedures and protocols, and implements the communication between the computer software through the API. One of the primary functions of an API is to provide a common set of functions. The API is also a middleware and provides data sharing for various platforms. The API described herein refers specifically to the HTTP interface.
And (3) replaying: the actions that have occurred are re-executed. In this context, API replay refers to re-simulating transmission of a series of API requests that have already occurred.
API logging: the access log recorded by the server for a series of API requests typically contains request methods, request addresses, request times, request parameters, client information, and the like.
C/S architecture: in the Client-Server architecture, an application program is divided into two parts, namely a Server part and a Client part, in a C/S structure. The server part is information and functions shared by a plurality of users, and executes background services, such as controlling the operation of a shared database and the like; the client part is exclusive to the user and is responsible for executing foreground functions, has powerful functions in the aspects of error prompt, online help and the like, and can be freely switched among subprograms.
B/S architecture: the browser and server architecture mode is a changed or improved architecture of the C/S architecture along with the rise of Internet technology. Under the structure, the user work interface is realized through a WEB browser. The B/S architecture is a network architecture mode after WEB is started, and a WEB browser is the most main application software of a client. The mode unifies the client, centralizes the core part of the system function realization to the server, and simplifies the development, maintenance and use of the system.
A WEB server: a WEB server refers to a program that resides on some type of computer on the internet. When a WEB browser, i.e. a client, connects to a server and requests a file, the server will process the request and feed the file back to the browser, with accompanying information telling the browser how to view the file (i.e. the file type). The server uses HTTP (Hyper Text Transport Protocol) to communicate with the client, which is why people often refer to them as HTTP servers.
UUID: the abbreviation of universal Unique Identifier (universal Unique Identifier) can enable all elements in the distributed system to have Unique identification information without specifying the identification information through a central control end.
It should be noted that all expressions using "first" and "second" in the embodiments of the present invention are used for distinguishing two entities with the same name but different names or different parameters, and it should be noted that "first" and "second" are merely for convenience of description and should not be construed as limitations of the embodiments of the present invention, and they are not described in any more detail in the following embodiments.
In view of the above objects, a first aspect of embodiments of the present invention proposes an embodiment of an API request replay method. As shown in fig. 1, the method performs the following steps at the client:
step S101, allocating identifiers for API requests, and calculating values of all parts of the identifiers;
step S103, adding the identifier to a Header of the API request;
and step S105, sending the API request added with the identifier to a server.
And adding a characteristic identifier for the API request according to the function of the WEB client and the user operation, sending the API request added with the identifier to a WEB server, recording the API request in a log after the WEB server receives the API request, and extracting a series of APIs with context association from the log record according to the identifier to perform replay simulation.
The Header is a part of the API request and is used for storing the identifier of the API request and adopts a key-value pair format.
In the actual development process, there are many cases of the trigger mechanism of one API request. The identifier of the API request includes a tag for distinguishing each identifier, and is used to record a condition that the WEB client triggers the API request, for example, what kind of function is triggered when the WEB client implements, and the operation of the same function is triggered multiple times, and the trigger time is the trigger time.
According to the embodiment of the invention, the client establishes the personalized identifier of the API request and calculates the value of the personalized identifier, so that different API requests can be distinguished, and a basis is provided for the subsequent server to replay the associated API request.
In some embodiments, the identifying comprises: a function module number, a service operation number, a behavior operation number, and an API request timestamp.
In some embodiments, the service operation number is a universal unique identification code.
The same API request may be used by different functional modules, each of which is a complete business process, such as creating a user, publishing an article, creating a container, and the like. The business operation refers to a plurality of operations performed by a user on the same functional module, such as creating a plurality of users. Behavioral operations refer to actions triggered automatically by software or actively by a user, such as initialization, mouse clicks, page scrolling, and the like.
In order to fully resolve the context relationship of a series of APIs, the identifier of the API has the following characteristics: can reflect which functional module the API request belongs to; the API request can be reflected by which business operation is triggered; can reflect what behavior operation the API request is triggered by; it can be reflected when the API request is triggered.
Based on the characteristics, the identifier of the API request is defined to comprise the following four parts of information: function module number (name), service operation number, behavior operation number, API request timestamp.
The identification format is: numbering functional modules; a service operation number; a behavior operation number; the API requests a timestamp, with an english semicolon (;) as a separator, for splicing each portion of content.
The specific process of calculating the value identifying each part is as follows:
the number of the functional module does not specify a specific format, and is defined by the user according to the system requirements, for example, the user-creation represents the functional module of the created user; the service operation number is in the form of a UUID, and each service operation generates a new UUID, such as 62b52e66-a372-4b32-81d6-ae13b57720c 6. The behavior operation number adopts a definition with self-descriptive property, such as using "initial" to represent function module initialization, using "button ═ button name" to represent button name click; the API request timestamp is defined as a digital timestamp representing the timestamp of the API request sent, which has a value of 13 bits, such as 1636620401038.
The final API identification is thus calculated as:
user-creation;62b52e66-a372-4b32-81d6-ae13b57720c6;button=buttonName;1636620401038。
and adding the calculated API identification to a Header, wherein the Header adopts a KEY-value pair form and is a KEY: VALUE; the KEY is a KEY name, which can be freely defined, for example, the KEY name is X-Request-Identification, and the VALUE stores an identifier of the API Request.
Based on the same inventive concept, according to another aspect of the present invention, as shown in fig. 2, an embodiment of the present invention further provides an API request replay method, which performs the following steps at a server:
step S201, obtaining an API request from a server log, and grouping the API request based on the identifier of the API request;
step S203, sequencing the API requests of each group based on the identification of the API requests;
and step S205, replaying the API request of each group after sorting.
According to the embodiment of the invention, the server obtains the API requests from the server log, groups the API requests based on the identifier of the API request and sequences the API requests of each group, so that the replay of a series of context-related API requests is realized.
In some embodiments, grouping API requests based on their identification includes:
and acquiring the functional module number and the service operation number of the API request from the identifier of the API request, and grouping the API request based on the functional module number and the service operation number.
In some embodiments, ordering the API requests of each group based on the identification of the API requests comprises:
and acquiring a behavior operation number and an API request timestamp of the API request from the identifier of the API request, and sequencing the API requests of each group based on the behavior operation number and the API request timestamp.
Furthermore, in each group of API requests, the API requests with the same operation behavior number are arranged according to the sequence of the API request time stamps.
In some embodiments, grouping API requests based on the functional module number and the business operation number comprises:
and distributing the API requests with the consistent functional module numbers and the consistent service operation numbers to the same group.
In the embodiment of the invention, the API requests with the same functional module number and the same service operation number belong to the same group, and each API request is sequenced in the same group according to the behavior operation number and the API request timestamp, so that a series of API requests with context correlation are obtained, and convenience is provided for searching for faults through API replay.
Furthermore, the replay method of the embodiment facilitates the developer to locate the bug of the software on the one hand. Through API replay, the whole business operation can be completely reproduced, so that a developer can be helped to completely analyze the whole business unit code, and deep mining of faults caused by mutually influencing or API with context relation is facilitated. In a complex use scene of a client site, the reason of the defect of the positioning software is often required to be fully communicated with the client so as to know what operation causes the fault, and great convenience is brought to fault positioning.
The playback method of the present embodiment on the other hand facilitates user behavior analysis. In the past user behavior analysis, a software designer needs to go to a customer line to do sufficient research and analysis to know what the software has the defects so as to optimize the software. Now, by replaying the API, each operation performed by the user in the software, such as when the client is used to use the software, which function modules are frequently used, which service operations are frequently interrupted, and which service operations are most time consuming, can be completely analyzed from the API replay process.
Based on the same inventive concept, according to another aspect of the present invention, as shown in fig. 3, an embodiment of the present invention further provides an API request replay system, the replay system including a client, the client including:
an allocation module 110, wherein the allocation module 110 is configured to allocate identifiers for API requests and calculate values of respective portions of the identifiers;
an add module 120, the add module 120 configured to add the identification to a Header of the API request;
a sending module 130, wherein the sending module 130 is configured to send the API request added with the identifier to the server.
According to the embodiment of the invention, the client establishes the personalized identifier of the API request and calculates the value of the personalized identifier, so that different API requests can be distinguished, and a basis is provided for the subsequent server to replay the associated API request.
Based on the same inventive concept, according to another aspect of the present invention, as shown in fig. 4, an embodiment of the present invention further provides an API request replay system, the replay system including a server, the server including:
a grouping module 210, wherein the grouping module 210 is configured to obtain API requests from a server log and group the API requests based on their identities;
an ordering module 220, the ordering module 220 configured to order the API requests of each group based on the identity of the API requests;
a replay module 230, said replay module 230 configured to replay the ordered API requests of each group.
According to the embodiment of the invention, the server obtains the API requests from the server log, groups the API requests based on the identifier of the API request and sequences the API requests of each group, so that the replay of a series of context-related API requests is realized.
Based on the same inventive concept, according to another aspect of the present invention, as shown in fig. 4, an embodiment of the present invention further provides a computer-readable storage medium 40, the computer-readable storage medium 40 storing a computer program 410 which, when executed by a processor, performs the following method:
the method comprises the following steps of:
allocating an identifier for the API request, and calculating the value of each part of the identifier;
adding the identification to a Header of the API request;
the identified API request is sent to the server.
In some embodiments, the identifying comprises: a function module number, a service operation number, a behavior operation number, and an API request timestamp.
In some embodiments, the service operation number is a universal unique identification code.
The method executes the following steps at the server:
obtaining API requests from a server log, and grouping the API requests based on the identifier of the API requests;
ordering the API requests of each group based on the identity of the API requests;
and replaying the API request of each group after the sorting.
In some embodiments, grouping API requests based on their identification includes:
and acquiring the functional module number and the service operation number of the API request from the identifier of the API request, and grouping the API request based on the functional module number and the service operation number.
In some embodiments, ordering the API requests of each group based on the identification of the API requests comprises:
and acquiring a behavior operation number and an API request timestamp of the API request from the identifier of the API request, and sequencing the API requests of each group based on the behavior operation number and the API request timestamp.
In some embodiments, grouping API requests based on the functional module number and the business operation number comprises:
and distributing the API requests with the consistent functional module numbers and the consistent service operation numbers to the same group.
The embodiment of the invention also can comprise corresponding computer equipment. The computer device comprises a memory, at least one processor and a computer program stored on the memory and executable on the processor, the processor executing the program to perform any one of the following methods:
the method comprises the following steps of:
allocating an identifier for the API request, and calculating the value of each part of the identifier;
adding the identification to a Header of the API request;
the identified API request is sent to the server.
In some embodiments, the identifying comprises: a function module number, a service operation number, a behavior operation number, and an API request timestamp.
In some embodiments, the service operation number is a universal unique identification code.
The method executes the following steps at the server:
obtaining API requests from a server log, and grouping the API requests based on the identifier of the API requests;
ordering the API requests of each group based on the identity of the API requests;
and replaying the API request of each group after the sorting.
In some embodiments, grouping API requests based on their identification includes:
and acquiring the functional module number and the service operation number of the API request from the identifier of the API request, and grouping the API request based on the functional module number and the service operation number.
In some embodiments, ordering the API requests of each group based on the identification of the API requests comprises:
and acquiring a behavior operation number and an API request timestamp of the API request from the identifier of the API request, and sequencing the API requests of each group based on the behavior operation number and the API request timestamp.
In some embodiments, grouping API requests based on the functional module number and the business operation number comprises:
and distributing the API requests with the consistent functional module numbers and the consistent service operation numbers to the same group.
The memory, which is a non-volatile computer-readable storage medium, may be used to store non-volatile software programs, non-volatile computer-executable programs, and modules, such as program instructions/modules corresponding to the API request replay method in the embodiments of the present application. The processor executes various functional applications of the apparatus and data processing, i.e., the API request replay method of the above-described method embodiments, by running the nonvolatile software program, instructions, and modules stored in the memory.
The memory may include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application program required for at least one function; the storage data area may store data created according to the use of the device, and the like. Further, the memory may include high speed random access memory, and may also include non-volatile memory, such as at least one magnetic disk storage device, flash memory device, or other non-volatile solid state storage device. In some embodiments, the memory optionally includes memory located remotely from the processor, and such remote memory may be coupled to the local module via a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
Finally, it should be noted that, as will be understood by those skilled in the art, all or part of the processes of the methods of the above embodiments may be implemented by a computer program, which may be stored in a computer-readable storage medium, and when executed, may include the processes of the embodiments of the methods described above. The storage medium of the program may be a magnetic disk, an optical disk, a Read Only Memory (ROM), a Random Access Memory (RAM), or the like. The embodiments of the computer program may achieve the same or similar effects as any of the above-described method embodiments.
Those of skill would further appreciate that the various illustrative logical blocks, modules, circuits, and algorithm steps described in connection with the disclosure herein may be implemented as electronic hardware, computer software, or combinations of both. To clearly illustrate this interchangeability of hardware and software, various illustrative components, blocks, modules, circuits, and steps have been described above generally in terms of their functionality. Whether such functionality is implemented as software or hardware depends upon the particular application and design constraints imposed on the overall system. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the disclosed embodiments of the present invention.
The foregoing is an exemplary embodiment of the present disclosure, but it should be noted that various changes and modifications could be made herein without departing from the scope of the present disclosure as defined by the appended claims. The functions, steps and/or actions of the method claims in accordance with the disclosed embodiments described herein need not be performed in any particular order. Furthermore, although elements of the disclosed embodiments of the invention may be described or claimed in the singular, the plural is contemplated unless limitation to the singular is explicitly stated.
It should be understood that, as used herein, the singular forms "a", "an" and "the" are intended to include the plural forms as well, unless the context clearly supports the exception. It should also be understood that "and/or" as used herein is meant to include any and all possible combinations of one or more of the associated listed items.
The numbers of the embodiments disclosed in the embodiments of the present invention are merely for description, and do not represent the merits of the embodiments.
It will be understood by those skilled in the art that all or part of the steps for implementing the above embodiments may be implemented by hardware, or may be implemented by a program instructing relevant hardware, and the program may be stored in a computer-readable storage medium, and the above-mentioned storage medium may be a read-only memory, a magnetic disk or an optical disk, etc.
Those of ordinary skill in the art will understand that: the discussion of any embodiment above is meant to be exemplary only, and is not intended to intimate that the scope of the disclosure, including the claims, of embodiments of the invention is limited to these examples; within the idea of an embodiment of the invention, also technical features in the above embodiment or in different embodiments may be combined and there are many other variations of the different aspects of the embodiments of the invention as described above, which are not provided in detail for the sake of brevity. Therefore, any omissions, modifications, substitutions, improvements, and the like that may be made without departing from the spirit and principles of the embodiments of the present invention are intended to be included within the scope of the embodiments of the present invention.