Flow playback method and device

By listening and replaying the service request traffic of the target main container, injecting the tracking identifier and forwarding it to the simulated server, the problem of link incompleteness in the existing technology is solved, and the complete tracking of the database request link is achieved.

CN119211056APending Publication Date: 2024-12-27SHANGHAI HODE INFORMATION TECH CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411305749.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-18
Publication Date
2024-12-27

AI Technical Summary

Technical Problem

The existing link tracing framework lacks request header information when crawling database requests, resulting in incomplete links and difficult to track database request links.

Method used

Get the traffic with a trace ID by listening to the port of the target main container, record downstream requests and return data, and inject trace IDs into the database requests, generate traffic files, playback traffic files to intercept downstream requests and forward them to the simulated server. , realize complete tracking of database links.

Benefits of technology

Complete tracking of links carrying request headers and non-portable request headers is realized, improving the accuracy and comprehensiveness of link tracking.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119211056A_ABST
    Figure CN119211056A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a traffic playback method, and the method comprises the steps: monitoring a port of a target main container, so as to obtain the business request traffic of the target main container; under the condition that the first service request flow is obtained, recording a first downstream request and first return data corresponding to the first service request flow according to the tracking identifier of the first service request flow, and under the condition that the first downstream request comprises a database request, recording the first return data; injecting a first tracking identifier of the first service request flow into a structured query statement of a database request; generating a traffic file according to the first service request traffic, the first downstream request, the first return data and the first tracking identifier; and playing back the traffic file, intercepting a first downstream request corresponding to the first service request traffic according to the first tracking identifier, and forwarding the first downstream request to the simulation server, so that the simulation server returns first return data to the target main container according to the first downstream request. According to the technical scheme provided by the embodiment of the invention, the tracked link is relatively complete.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application relate to the field of testing technology, and in particular, to a traffic playback method, apparatus, computer equipment, computer-readable storage medium, and computer program product. Background Art

[0002] The importance of traffic recording is self-evident. Whether it is R&D or testing, we hope to obtain real online traffic for stress testing or functional regression testing. Traffic recording can save a lot of test case construction work, and at the same time, the case coverage is more comprehensive and realistic. When testing through traffic recording and playback, the integrity of the traffic link is more critical. One interface request often sends several downstream dependent requests. How to associate these requests into a complete request link is crucial to the success of the playback.

[0003] At present, the mainstream link tracking frameworks all inject relevant link information into the request header when sending a request and transmit it as part of the request. However, request protocols such as database requests do not have request headers that carry additional information. Therefore, the links captured by these link tracking frameworks are not complete.

[0004] It should be noted that the above content is not necessarily prior art, nor is it intended to limit the scope of patent protection of this application. Summary of the invention

[0005] The embodiments of the present application provide a traffic playback method, apparatus, computer device, computer-readable storage medium, and computer program product to solve or alleviate one or more of the technical problems raised above.

[0006] An aspect of an embodiment of the present application provides a traffic playback method, the method comprising: Listening to a port of a target main container to obtain a service request flow of the target main container, wherein the service request flow includes a tracking identifier; When the first service request traffic is obtained, a first downstream request and first return data corresponding to the first service request traffic are recorded according to the tracking identifier, and when the first downstream request includes a database request, a first tracking identifier of the first service request traffic is injected into a structured query statement of the database request, wherein the first service request traffic is the current service request traffic; Generate a traffic file according to the first service request traffic, the first downstream request, the first return data, and the first tracking identifier; The traffic file is replayed, and a first downstream request corresponding to the first business request traffic is intercepted according to the first tracking identifier and forwarded to the simulation server, so that the simulation server returns the first return data to the target main container according to the first downstream request.

[0007] Optionally, injecting the first tracking identifier of the first service request traffic into the structured query statement of the database request includes: The first tracking identifier of the first service request flow is injected into the beginning of the structured query statement of the database request by using the first SDK in the target main container, wherein the first SDK is adapted to the language type of the service corresponding to the target main container.

[0008] Optionally, monitoring a port of a target main container to obtain service request traffic of the target main container includes: Monitor the traffic of the port of the target main container, and determine to obtain the service request traffic of the target main container when the target IP address and port of the current traffic are the service address of the target main container.

[0009] Optionally, when the first service request flow is acquired, recording the first downstream request and the first return data corresponding to the first service request flow according to the tracking identifier includes: When the source IP address of the current traffic is the IP address of the target main container and the corresponding tracking identifier is the first tracking identifier, it is determined that the current traffic is the first downstream request.

[0010] Optionally, the replaying the traffic file, intercepting the first downstream request corresponding to the first service request traffic according to the first tracking identifier and forwarding it to the simulation server includes: When receiving a target signal for replaying the traffic file, updating the iptables of the target main container, and starting a service proxy process in the same container group as the target main container; Starting the simulation server and replaying the traffic file; Intercepting the first downstream request to the service proxy process through the updated iptables; The first downstream request is forwarded to the simulation server through the service proxy process.

[0011] Optionally, the method further comprises: When the playback is finished, a signal for closing the simulation function is sent to the simulation server; Restore the iptables of the target main container and release the service proxy process.

[0012] Another aspect of an embodiment of the present application provides a traffic playback device, the device comprising: A monitoring module, used for monitoring a port of a target main container to obtain a service request flow of the target main container, wherein the service request flow includes a tracking identifier; an injection module, configured to, when a first service request flow is acquired, record a first downstream request and first return data corresponding to the first service request flow according to a tracking identifier, and, when the first downstream request includes a database request, inject a first tracking identifier of the first service request flow into a structured query statement of the database request, wherein the first service request flow is a current service request flow; A generating module, configured to generate a flow file according to the first service request flow, the first downstream request, the first return data and the first tracking identifier; A playback module is used to play back the traffic file, intercept the first downstream request corresponding to the first business request traffic according to the first tracking identifier, and forward it to the simulation server, so that the simulation server returns the first return data to the target main container according to the first downstream request.

[0013] Another aspect of an embodiment of the present application provides a computer device, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein: the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute the method described above.

[0014] Another aspect of an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer instructions, and when the computer instructions are executed by a processor, the method described above is implemented.

[0015] Another aspect of an embodiment of the present application provides a computer program product, including a computer program, which implements the method described above when executed by a processor.

[0016] The above technical solution adopted in the embodiment of the present application may have the following advantages: By listening to the port of the target main container, the business request traffic with a tracking identifier of the target main container is obtained. When the first business request traffic is obtained, the first downstream request and the first return data corresponding to the first business request traffic are recorded according to the tracking identifier. When the first downstream request includes a database request, the first tracking identifier of the first business request traffic is injected into the structured query statement of the database request, and a traffic file is generated according to the first business request traffic, the first downstream request, the first return data and the first tracking identifier; the traffic file is replayed, and the first downstream request corresponding to the first business request traffic is intercepted according to the first tracking identifier and forwarded to the simulation server, so that the simulation server can track the database links that do not carry the request header by injecting the tracking identifier into the structured query statement of the database request according to the first downstream request, so that not only the links carrying the request header can be tracked, but also the links not carrying the request header can be tracked, so that the tracked links are more complete. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] The accompanying drawings exemplarily illustrate the embodiments and constitute a part of the specification, and together with the text description of the specification, are used to explain the exemplary implementation of the embodiments. The embodiments shown are for illustrative purposes only and do not limit the scope of the claims. In all drawings, the same reference numerals refer to similar but not necessarily identical elements.

[0018] Figure 1 The following schematically shows an operating environment diagram of the traffic playback method according to the first embodiment of the present application; Figure 2 The flowchart of the traffic playback method according to the first embodiment of the present application is schematically shown; Figure 3 Schematically shows Figure 2 Flow chart of sub-steps of step S206; Figure 4 The newly added process of the traffic playback method according to the first embodiment of the present application is schematically shown; Figure 5 The schematic diagram shows a flow playback method according to the first embodiment of the present application; Figure 6 A block diagram of a traffic playback device according to Embodiment 2 of the present application is schematically shown; and Figure 7 The hardware architecture diagram of the computer device according to the third embodiment of the present application is schematically shown. DETAILED DESCRIPTION

[0019] In order to make the purpose, technical solutions and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not intended to limit the present application. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of the present application.

[0020] It should be noted that the descriptions involving "first", "second", etc. in the embodiments of the present application are only for descriptive purposes and cannot be understood as indicating or implying their relative importance or implicitly indicating the number of technical features indicated. Therefore, the features defined as "first" and "second" may explicitly or implicitly include at least one of the features. In addition, the technical solutions between the various embodiments can be combined with each other, but they must be based on the ability of ordinary technicians in the field to implement them. When the combination of technical solutions is contradictory or cannot be implemented, it should be deemed that such combination of technical solutions does not exist and is not within the scope of protection required by this application.

[0021] In the description of the present application, it should be understood that the numerical labels before the steps do not indicate the order in which the steps are executed, but are only used to facilitate the description of the present application and to distinguish each step, and therefore should not be understood as a limitation on the present application.

[0022] First, the following terms are explained: Kubernetes (K8s for short): is an open source platform dedicated to managing clusters of containerized applications and services.

[0023] Pod: The smallest unit level managed in k8s, which is a combination of one or more containers.

[0024] Sidecar: In a Pod, in addition to the main business container, one or more auxiliary containers are deployed. These auxiliary containers are designed to complete some tasks independent of the main process (main container), such as log collection, monitoring, network proxy, security scanning, etc. The companion container shares the same Pod's network namespace, storage volume and other resources with the main container, but they each run independent processes and focus on providing additional functions or support for the Pod.

[0025] Tshark: is the command-line version of Wireshark, which allows users to capture and analyze network traffic.

[0026] Microservices: is a software architecture design pattern that decomposes applications into small, autonomous service units that can be independently deployed, expanded, and maintained. Each service runs in its own process and communicates with each other through a lightweight communication mechanism (usually using http or grpc protocol).

[0027] iptables: is a command line tool widely used in Linux systems. It allows system administrators to control network traffic according to predefined rules, and implement functions such as packet filtering, packet redirection, and network address translation.

[0028] grpc: is a modern open source RPC framework based on the HTTP / 2 protocol and the Protocol Buffers (Protobuf) serialization protocol. It can run in any environment and efficiently connect services within and across data centers.

[0029] Envoy: is a lightweight Layer 7 service proxy that supports multiple protocols such as HTTP / 2 and gRPC. It can run as a sidecar proxy around the application or as an edge proxy for the network.

[0030] Secondly, in order to facilitate those skilled in the art to understand the technical solutions provided in the embodiments of the present application, the relevant technologies are described below: Currently, mainstream link tracking frameworks inject relevant link information into the request header when sending a request and transmit it as part of the request. However, since request protocols such as database requests do not have request headers that carry additional information, the links that can be captured using these link tracking frameworks are not complete.

[0031] To this end, the embodiment of the present application provides a traffic playback technical solution. In this technical solution, not only the link corresponding to the request header can be tracked, but also the link without the request header can be tracked, so the tracked link can be relatively complete. See below for details.

[0032] Finally, for ease of understanding, an exemplary operating environment is provided below.

[0033] like Figure 1 As shown, the environment diagram includes a service platform 2, a network 4, and a client 6, wherein: The service platform 2 may be composed of a single or multiple computing devices. The multiple computing devices may include virtualized computing instances. Virtualized computing instances may include virtual machines, such as simulations of computer systems, operating systems, servers, etc. The computing device may load a virtual machine based on a virtual image and / or other data defining specific software (e.g., operating system, dedicated application, server) for simulation. As the demand for different types of processing services changes, different virtual machines may be loaded and / or terminated on one or more computing devices. A hypervisor may be implemented to manage the use of different virtual machines on the same computing device.

[0034] The service platform 2 may be configured to communicate with the client 6 or the like via a network 4. The network 4 includes various network devices, such as routers, switches, multiplexers, hubs, modems, bridges, repeaters, firewalls, proxy devices, and / or the like. The network 4 may include physical links, such as coaxial cable links, twisted pair cable links, optical fiber links, combinations thereof, and the like, or wireless links, such as cellular links, satellite links, Wi-Fi links, and the like.

[0035] The service platform 2 can provide storage, reading, writing, querying, deleting and other services, such as providing the client with a service for reading the database of the service platform 2.

[0036] The client 6 may be an electronic device running an operating system such as Windows, Android™ or iOS, such as a smart phone, a tablet device, a laptop computer, a virtual reality device, a gaming device, a set-top box, a vehicle terminal, or a smart TV. Based on the above operating system, various application programs may be run, such as an application program for reading a database of the service platform 2.

[0037] The client 6 may provide / configure a user access page for manipulating the service platform 2 or uploading an object, etc.

[0038] It should be noted that the above devices are exemplary, and the number and type of devices are adjustable in different scenarios or according to different needs.

[0039] The following uses the service platform as the execution subject to introduce the technical solution of the present application through multiple embodiments. It should be noted that these embodiments can be implemented in a variety of different forms and should not be interpreted as being limited to the embodiments described here.

[0040] Embodiment 1 Figure 2 The flowchart of the traffic playback method according to the first embodiment of the present application is schematically shown.

[0041] like Figure 2 As shown, the traffic playback method may include steps S200 to S206, wherein: Step S200 , monitoring the port of the target main container to obtain the service request traffic of the target main container, wherein the service request traffic includes a tracking identifier.

[0042] Step S202, when the first business request traffic is obtained, the first downstream request and the first return data corresponding to the first business request traffic are recorded according to the tracking identifier, and when the first downstream request includes a database request, the first tracking identifier of the first business request traffic is injected into the structured query statement of the database request, wherein the first business request traffic is the current business request traffic.

[0043] Step S204: Generate a traffic file according to the first service request traffic, the first downstream request, the first return data and the first tracking identifier.

[0044] Step S206, replaying the traffic file, intercepting the first downstream request corresponding to the first business request traffic according to the first tracking identifier and forwarding it to the simulation server, so that the simulation server returns the first return data to the target main container according to the first downstream request.

[0045] The traffic replay method provided in this embodiment monitors the port of the target main container to obtain the business request traffic with a tracking identifier of the target main container. When the first business request traffic is obtained, the first downstream request and the first return data corresponding to the first business request traffic are recorded according to the tracking identifier. When the first downstream request includes a database request, the first tracking identifier of the first business request traffic is injected into the structured query statement of the database request, and a traffic file is generated according to the first business request traffic, the first downstream request, the first return data and the first tracking identifier; the traffic file is replayed, and the first downstream request corresponding to the first business request traffic is intercepted according to the first tracking identifier and forwarded to the simulation server, so that the simulation server can track the database links that do not carry the request header by injecting the tracking identifier into the structured query statement of the database request according to the first downstream request, so that not only the links carrying the request header can be tracked, but also the links not carrying the request header can be tracked, so that the tracked links are more complete.

[0046] The following combination Figure 2 , each step in steps S200~S206 and other optional steps are described in detail.

[0047] Step S200 , listen to the port of the target main container to obtain the business request traffic of the target main container, wherein the business request traffic includes a tracking identifier.

[0048] A tracing identifier (such as a trace ID) can be pre-added to the business request traffic, so that the business request traffic includes the tracing identifier. For example, the tracing identifier can be added to the http request header by the client, or the tracing identifier can be added to the request header by a dedicated tracing framework in the microservice architecture.

[0049] When monitoring the port of the target main container, you can monitor it by recording the companion container. When monitoring, the recording companion container can monitor the network card or network interface of the main container by configuring a traffic monitoring tool (such as Tshark) to capture the business request traffic of the target main container.

[0050] In an optional embodiment, in step S200, monitoring the port of the target main container to obtain the business request traffic of the target main container may include: monitoring the traffic of the port of the target container, and determining that the business request traffic of the target main container is obtained when the target IP address and port of the current traffic are the business address of the target main container.

[0051] Specifically, when the recording companion container monitors the port of the target main container for traffic, it extracts the target IP address and port of the current traffic, and judges the target IP address and port of the current traffic. If the target IP address and port of the current traffic are the business address of the target main container, it is determined that the business request traffic of the target main container is obtained.

[0052] In this optional embodiment, by monitoring the traffic of the port of the target main container, when the target IP address and port of the current traffic are the business address of the target main container, it is determined that the business request traffic of the target main container is obtained. The target IP address and port of the traffic can be used to determine whether the current traffic is the business request traffic of the target main container, thereby improving the efficiency of traffic identification and facilitating traffic monitoring.

[0053] Step S202 When the first business request traffic is obtained, the first downstream request and the first return data corresponding to the first business request traffic are recorded according to the tracking identifier, and when the first downstream request includes a database request, the first tracking identifier of the first business request traffic is injected into the structured query statement of the database request, wherein the first business request traffic is the current business request traffic.

[0054] When the first business request traffic is obtained, the tracking identifier in the first business request traffic can be obtained. When the main container generates a downstream request, the tracking identifier in the corresponding business request traffic can be added to the downstream request, so that the downstream request also includes the tracking identifier. The downstream request will first be sent to the recording companion container. After the recording companion container obtains the downstream request, it can determine the business request traffic corresponding to the current downstream request according to the tracking identifier. Similarly, after the downstream request is sent to the corresponding downstream application, the downstream application can add the tracking identifier corresponding to the downstream request to the return data. The return data corresponding to the downstream request is also first sent to the recording companion container. The recording companion container can identify the downstream request corresponding to the current return data according to the tracking identifier.

[0055] In an optional embodiment, in step S202, when the first business request traffic is obtained, recording the first downstream request and the first return data corresponding to the first business request traffic according to the tracking identifier may include: when the source IP address of the current traffic is the IP address of the target main container and the corresponding tracking identifier is the first tracking identifier, determining that the current traffic is the first downstream request.

[0056] Specifically, when the recording companion container monitors that there is traffic on the port of the target main container, it extracts the source IP address and tracking identifier of the current traffic, and judges the source IP address and tracking identifier of the current traffic. If the source IP address of the current traffic is the IP address of the target main container and the corresponding tracking identifier is the first tracking identifier, it is determined that the current traffic is the first downstream request.

[0057] In this optional embodiment, by determining that the current traffic is the first downstream request when the source IP address of the current traffic is the IP address of the target main container and the corresponding tracking identifier is the first tracking identifier, it is possible to determine whether the current traffic is the downstream request corresponding to the first business request traffic by using the source IP address of the traffic and the tracking identifier, thereby improving the efficiency of traffic identification and facilitating the aggregation of the same business request traffic and downstream requests and downstream return data.

[0058] When the downstream request includes a database request, the main container can inject the tracking identifier corresponding to the business traffic into the structured query statement of the database request, so that the return data corresponding to the database request also contains the corresponding tracking identifier, thereby realizing the tracking of the database link.

[0059] In an optional embodiment, injecting the first tracking identifier of the first business request traffic into the structured query statement of the database request in step S202 may include: using the first SDK in the target main container to inject the first tracking identifier of the first business request traffic into the beginning of the line of the structured query statement of the database request, wherein the first SDK is adapted to the language type of the business corresponding to the target main container.

[0060] The service platform can prepare the first SDK of multiple language types in advance, and provide the first SDK of the corresponding language type according to the language type of the business corresponding to the target main container, so that the first SDK is adapted to the language type of the business corresponding to the target main container. The language types may include but are not limited to java, python, C++, JavaScript, Golang, etc.

[0061] In this optional embodiment, the first tracking identifier of the first business request traffic is injected into the beginning of the structured query statement of the database request by utilizing the first SDK in the target main container. The first SDK is adapted to the language type of the business corresponding to the target main container. The SDK can be used to implement the injection of the tracking identifier corresponding to the database request, thereby reducing the difficulty of code development and improving the convenience of database request link tracking.

[0062] Step S204 , generating a traffic file according to the first business request traffic, the first downstream request, the first return data and the first tracking identifier.

[0063] Specifically, the service platform can aggregate all first service request flows, first downstream requests, and first return data according to the first tracking identifier to form a flow file corresponding to the first tracking identifier as data for subsequent simulation (mock). The service platform can form a mock configuration file according to the flow file so as to perform corresponding simulation according to the corresponding simulation configuration file.

[0064] Step S206 , replay the traffic file, intercept the first downstream request corresponding to the first business request traffic according to the first tracking identifier and forward it to the simulation server, so that the simulation server returns the first return data to the target main container according to the first downstream request.

[0065] In an optional embodiment, in step S206, the traffic file is replayed, and the first downstream request corresponding to the first service request traffic is intercepted according to the first tracking identifier and forwarded to the simulation server, such as Figure 3 As shown, the method may further include steps S300 to S306: Step S300, when receiving the target signal of the playback traffic file, the iptables of the target main container is updated, and the service proxy process in the same container group as the target main container is started.

[0066] Step S302, start the simulation server and play back the traffic file.

[0067] Step S304: intercept the first downstream request to the service proxy process through the updated iptables.

[0068] Step S306: forward the first downstream request to the simulation server through the service proxy process.

[0069] Specifically, a traffic execution engine can be used to send a target signal for replaying the traffic file. When the service platform receives the target signal for replaying the traffic file, it updates the iptables of the target main container and starts the service proxy process in the same container group (pod) as the target main container, so as to redirect the first downstream request to the service proxy process according to the simulation configuration file and the traffic file, and the service proxy process then forwards the first downstream request to the simulation server. The traffic execution engine can also notify the simulation server to start and turn on the simulation function of the simulation server; after the simulation server is started, the service platform can obtain the traffic file from the recording companion container and replay it to the specified microservice according to the simulation configuration file; the updated iptables intercepts the first downstream request to the service proxy process, and after receiving the first downstream request, the service proxy process forwards the first downstream request to the simulation server, and the simulation server simulates the corresponding interface and returns the result to the target main container. Among them, the service proxy process can be Envoy, for example.

[0070] In this optional embodiment, when the target signal of the playback traffic file is received, the iptables of the target main container is updated, and the service proxy process in the same container group as the target main container is started, the simulation server is started, the traffic file is replayed, and the first downstream request is intercepted to the service proxy process through the updated iptables, and the first downstream request is forwarded to the simulation server through the service proxy process. The real request-response process can be simulated through the collaborative work of iptables, the service proxy process and the simulation server, without relying on the actual back-end service, thereby facilitating corresponding testing and verification.

[0071] In an optional embodiment, if Figure 4 As shown, the traffic playback method may further include steps S400 to S402: Step S400: When the playback is finished, a signal for closing the simulation function is sent to the simulation server.

[0072] Step S402, restore the iptables of the target main container and release the service proxy process.

[0073] Specifically, the traffic execution engine can be used to send a signal to the simulation server to shut down the simulation function when the playback is finished, so that the simulation server shuts down the simulation function and can shut down the simulation server; at the same time, the iptables of the target main container is restored to the configuration before the traffic playback, and the service proxy process is released, so that the target main container resumes normal routing.

[0074] In this optional embodiment, by sending a signal to shut down the simulation function to the simulation server when the playback ends, restoring the iptables of the target main container, and releasing the service proxy process, the normal routing of the target main container can be restored when the traffic playback ends.

[0075] Please refer to Figure 5 , which is a schematic diagram of the principle of the traffic playback method, which mainly includes two stages: recording and playback, and can mainly include the following contents: Recording stage: 1. When the downstream request of the interface includes a database request, call the SDK injection method before the request is executed to inject the trace id into the beginning of the structured query statement (SQL); 2. Record the traffic by recording the companion container listening to the network card port of the main container. If the target IP address and port of the current traffic are the business address of the main container, the traffic is recorded as the business request traffic, and the trace id (tracing identifier) ​​of this request is extracted from the request header; if the source IP address of the current traffic is the IP address of the main container, the traffic is recorded as a downstream request, and the trace id is extracted from the request header or structured query statement; aggregate the downstream traffic with the same trace id as the business request mock data file corresponding to the trace id, and wait for the simulated server to call it.

[0076] Playback phase: 1. Update the iptables of the main container, start the Envoy process, and the playback engine (i.e., traffic execution engine) notifies the mockserver to start and enable the mock function. When notifying the mock server to start, the playback engine notifies the mock server of the name of the downstream traffic mock data file required for this playback so that the mock server can pull the configuration file; 2. The updated iptables intercepts the original export request to the downstream service or database to the Envoy process, which then forwards it to the mock server. The mock server mocks the corresponding interface based on the acquired configuration file and the proto file required by the grpc interface and returns the result to the main container. 3. After receiving the signal from the playback engine to shut down the mock function, restore the iptables of the host container, release the Envoy process and mock server, clean up the generated intermediate files, and restore normal routing of the main container.

[0077] In the related art, the link tracking method has the following problems: (1) Request protocols such as database requests are based on the 4-layer TCP protocol and do not expose request headers that can carry additional information. Therefore, the link captured by adding a trace ID to the request header is incomplete.

[0078] (2) For downstream dependent services, the relevant technology is often implemented by deploying a complete service chain in the test environment, or starting a complete service container to simulate the downstream service and manually preparing all mock data. When encountering core services with complex downstream dependencies, the cost of pre-configuration work is very high.

[0079] (3) Since existing tools basically only support mocks for http and grpc network requests, and database requests are a key part of interface requests, existing tools do not provide mock implementations, so it is necessary to use shadow libraries or shadow tables to replace the database in the test environment to avoid problems such as dirty data or data unique index conflicts. However, shadow libraries or shadow tables require too much investment in the early preparation process; and for unique indexes, each playback requires a new shadow table to meet the needs, which not only complicates the playback link, but also increases resource consumption.

[0080] The traffic playback method of the embodiment of the present application has the following advantages: (1) During the traffic recording process, a comment containing the same trace ID as in the interface request header is injected at the beginning of the line where the SQL statement is executed on the interface. This allows the downstream database request to be associated with the interface request when the TCP traffic of the database request is parsed, thereby making up for the shortcoming in related technologies that the database-related links cannot be tracked through the trace ID.

[0081] (2) Based on the characteristics of the companion container and the main container sharing the network card and execution environment, by modifying the iptable of the main container, the qualified export traffic of the main container can be directly forwarded to the mock service. When recording the inlet traffic, the service automatically associates the downstream export traffic and generates a mock configuration file based on these downstream export traffic. The mock service only needs one configuration file to simulate the required downstream service return. There is no need to manually prepare mock data or deploy downstream dependent services.

[0082] (3) As a separate companion service deployment, it does not need to consider the business language and is universal across languages. In addition to HTTP and GRPC, the simulated protocols also support MySQL, without relying on shadow libraries or shadow tables, which improves the convenience of traffic playback testing.

[0083] Embodiment 2 Figure 6 The block diagram of the traffic playback device 500 according to the second embodiment of the present application is schematically shown. The device can be divided into one or more program modules, one or more program modules are stored in a storage medium, and are executed by one or more processors to complete the embodiment of the present application. The program module referred to in the embodiment of the present application refers to a series of computer program instruction segments that can complete specific functions. The following description will specifically introduce the functions of each program module in this embodiment. Figure 6 As shown, the apparatus 500 may include: a monitoring module 510, an injection module 520, a generation module 530 and a playback module 540, wherein: A monitoring module 510 is used to monitor the port of the target main container to obtain the service request traffic of the target main container, wherein the service request traffic includes a tracking identifier; The injection module 520 is used to record the first downstream request and the first return data corresponding to the first business request flow according to the tracking identifier when the first business request flow is obtained, and inject the first tracking identifier of the first business request flow into the structured query statement of the database request when the first downstream request includes a database request, wherein the first business request flow is the current business request flow; A generating module 530, configured to generate a flow file according to the first service request flow, the first downstream request, the first return data and the first tracking identifier; The playback module 540 is used to play back the traffic file, intercept the first downstream request corresponding to the first business request traffic according to the first tracking identifier, and forward it to the simulation server, so that the simulation server returns the first return data to the target main container according to the first downstream request.

[0084] In an optional embodiment, the injection module 520 is further configured to: The first tracking identifier of the first service request flow is injected into the beginning of the structured query statement of the database request by using the first SDK in the target main container, wherein the first SDK is adapted to the language type of the service corresponding to the target main container.

[0085] In an optional embodiment, the monitoring module 510 is further configured to: Monitor the traffic of the port of the target main container, and determine to obtain the service request traffic of the target main container when the target IP address and port of the current traffic are the service address of the target main container.

[0086] In an optional embodiment, the injection module 520 is further configured to: When the source IP address of the current traffic is the IP address of the target main container and the corresponding tracking identifier is the first tracking identifier, it is determined that the current traffic is the first downstream request.

[0087] In an optional embodiment, the playback module 540 is further configured to: When receiving a target signal for replaying the traffic file, updating the iptables of the target main container, and starting a service proxy process in the same container group as the target main container; Starting the simulation server and replaying the traffic file; Intercepting the first downstream request to the service proxy process through the updated iptables; The first downstream request is forwarded to the simulation server through the service proxy process.

[0088] In an optional embodiment, the traffic playback device 500 is further used for: When the playback is finished, a signal for closing the simulation function is sent to the simulation server; Restore the iptables of the target main container and release the service proxy process.

[0089] Embodiment 3 Figure 7The schematic diagram of the hardware architecture of a computer device 10000 suitable for implementing the traffic playback method according to the third embodiment of the present application is shown schematically. In some embodiments, the computer device 10000 may be a terminal device such as a smart phone, a wearable device, a tablet computer, a personal computer, a vehicle terminal, a game console, a virtual device, a workbench, a digital assistant, a set-top box, a robot, etc. In other embodiments, the computer device 10000 may be a rack server, a blade server, a tower server, or a cabinet server (including an independent server, or a server cluster composed of multiple servers), etc. Figure 7 As shown, the computer device 10000 includes but is not limited to: a memory 10010, a processor 10020, and a network interface 10030 that can communicate with each other through a system bus. Among them: The memory 10010 includes at least one type of computer-readable storage medium, and the readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (such as SD or DX memory), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, magnetic disk, optical disk, etc. In some embodiments, the memory 10010 can be an internal storage module of the computer device 10000, such as a hard disk or memory of the computer device 10000. In other embodiments, the memory 10010 can also be an external storage device of the computer device 10000, such as a plug-in hard disk equipped on the computer device 10000, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. Of course, the memory 10010 can also include both the internal storage module of the computer device 10000 and its external storage device. In this embodiment, the memory 10010 is generally used to store the operating system and various application software installed in the computer device 10000, such as the program code of the traffic playback method, etc. In addition, the memory 10010 can also be used to temporarily store various data that have been output or will be output.

[0090] In some embodiments, the processor 10020 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other chips. The processor 10020 is generally used to control the overall operation of the computer device 10000, such as performing control and processing related to data interaction or communication with the computer device 10000. In this embodiment, the processor 10020 is used to run the program code stored in the memory 10010 or process data.

[0091] The network interface 10030 may include a wireless network interface or a wired network interface, and the network interface 10030 is generally used to establish a communication link between the computer device 10000 and other computer devices. For example, the network interface 10030 is used to connect the computer device 10000 to an external terminal through a network, and to establish a data transmission channel and a communication link between the computer device 10000 and the external terminal. The network may be a wireless or wired network such as an intranet, the Internet, the Global System of Mobile communication (GSM), Wideband Code Division Multiple Access (WCDMA), 4G network, 5G network, Bluetooth, Wi-Fi, etc.

[0092] It should be pointed out that Figure 7 Only a computer device having components 10010 - 10030 is shown, but it should be understood that implementation of all of the components shown is not a requirement, and more or fewer components may alternatively be implemented.

[0093] In this embodiment, the traffic replay method stored in the memory 10010 can also be divided into one or more program modules and executed by one or more processors (such as processor 10020) to complete the embodiment of the present application.

[0094] Embodiment 4 An embodiment of the present application also provides a computer-readable storage medium, on which a computer program is stored, wherein when the computer program is executed by a processor, the steps of the traffic playback method in the embodiment are implemented.

[0095] In this embodiment, the computer-readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (for example, SD or DX memory, etc.), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, disk, optical disk, etc. In some embodiments, the computer-readable storage medium may be an internal storage unit of a computer device, such as a hard disk or memory of the computer device. In other embodiments, the computer-readable storage medium may also be an external storage device of a computer device, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. equipped on the computer device. Of course, the computer-readable storage medium may also include both the internal storage unit of the computer device and its external storage device. In this embodiment, the computer-readable storage medium is generally used to store an operating system and various application software installed on the computer device, such as the program code of the traffic playback method in the embodiment. In addition, the computer-readable storage medium may also be used to temporarily store various types of data that have been output or are to be output.

[0096] Embodiment 5 An embodiment of the present application also provides a computer program product, including a computer program, which implements the method in the above embodiment when executed by a processor.

[0097] Obviously, those skilled in the art should understand that the modules or steps of the above-mentioned embodiments of the present application can be implemented by general-purpose computer devices, they can be concentrated on a single computer device, or distributed on a network composed of multiple computer devices, optionally, they can be implemented by executable program codes of computer devices, so that they can be stored in a storage device and executed by the computer device, and in some cases, the steps shown or described can be executed in a different order from that herein, or they can be made into individual integrated circuit modules, or multiple modules or steps therein can be made into a single integrated circuit module for implementation. In this way, the embodiments of the present application are not limited to any specific combination of hardware and software.

[0098] It should be noted that the above are only preferred embodiments of the present application, and the patent protection scope of the present application is not limited thereto. Any equivalent structure or equivalent process transformation made using the contents of the specification and drawings of the present application, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present application.

Claims

1. A traffic playback method, characterized in that: The method comprises: Listening to a port of a target main container to obtain a service request flow of the target main container, wherein the service request flow includes a tracking identifier; When the first service request traffic is obtained, a first downstream request and first return data corresponding to the first service request traffic are recorded according to the tracking identifier, and when the first downstream request includes a database request, a first tracking identifier of the first service request traffic is injected into a structured query statement of the database request, wherein the first service request traffic is the current service request traffic; Generate a traffic file according to the first service request traffic, the first downstream request, the first return data, and the first tracking identifier; The traffic file is replayed, and a first downstream request corresponding to the first business request traffic is intercepted according to the first tracking identifier and forwarded to the simulation server, so that the simulation server returns the first return data to the target main container according to the first downstream request.

2. The method according to claim 1, characterized in that The step of injecting the first tracking identifier of the first service request flow into the structured query statement of the database request includes: The first tracking identifier of the first service request flow is injected into the beginning of the structured query statement of the database request by using the first SDK in the target main container, wherein the first SDK is adapted to the language type of the service corresponding to the target main container.

3. The method according to claim 2, characterized in that The monitoring the port of the target main container to obtain the service request flow of the target main container includes: Monitor the traffic of the port of the target main container, and determine to obtain the service request traffic of the target main container when the target IP address and port of the current traffic are the service address of the target main container.

4. The method according to claim 3, characterized in that When the first service request flow is obtained, recording the first downstream request and the first return data corresponding to the first service request flow according to the tracking identifier includes: When the source IP address of the current traffic is the IP address of the target main container and the corresponding tracking identifier is the first tracking identifier, it is determined that the current traffic is the first downstream request.

5. The method according to any one of claims 1 to 4, characterized in that: The replaying of the traffic file, intercepting the first downstream request corresponding to the first service request traffic according to the first tracking identifier and forwarding it to the simulation server, includes: When receiving a target signal for replaying the traffic file, updating the iptables of the target main container, and starting a service proxy process in the same container group as the target main container; Starting the simulation server and replaying the traffic file; Intercepting the first downstream request to the service proxy process through the updated iptables; The first downstream request is forwarded to the simulation server through the service proxy process.

6. The method according to claim 5, characterized in that The method further comprises: When the playback is finished, a signal for closing the simulation function is sent to the simulation server; Restore the iptables of the target main container and release the service proxy process.

7. A flow playback device, characterized in that: The device comprises: A monitoring module, used for monitoring a port of a target main container to obtain a service request flow of the target main container, wherein the service request flow includes a tracking identifier; an injection module, configured to, when a first service request flow is acquired, record a first downstream request and first return data corresponding to the first service request flow according to a tracking identifier, and, when the first downstream request includes a database request, inject a first tracking identifier of the first service request flow into a structured query statement of the database request, wherein the first service request flow is a current service request flow; A generating module, configured to generate a flow file according to the first service request flow, the first downstream request, the first return data and the first tracking identifier; A playback module is used to play back the traffic file, intercept the first downstream request corresponding to the first business request traffic according to the first tracking identifier, and forward it to the simulation server, so that the simulation server returns the first return data to the target main container according to the first downstream request.

8. A computer device, characterized in that: include: at least one processor; and a memory communicatively connected to the at least one processor; wherein: The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 6.

9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and when the computer instructions are executed by a processor, the method according to any one of claims 1 to 6 is implemented.

10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.

Citation Information

Cited By

  • System testing method and device, electronic equipment and storage medium

    CN121547376A