Skip to main content
Version: 3.9.x

Configure Proxy Mirror

The proxy-mirror plugin allows you to mirror real requests from your production environment to a separate service for testing or analysis. The response from the mirrored service is ignored, ensuring no impact on the original request's performance or outcome.

Prerequisites

  • An API7 Enterprise instance is running.
  • A Gateway Group is created and a Gateway instance is running.
  • A token from the Dashboard.

Configure Traffic Mirroring

The following configuration mirrors all incoming requests to a secondary service running at http://test-server:8080.

curl -k "https://localhost:7443/apisix/admin/services/proxy-mirror-service?gateway_group_id={gateway_group_id}" -X PUT \
-H "X-API-KEY: ${API_KEY}" \
-H "Content-Type: application/json" \
-d '{
"name": "proxy-mirror-service",
"upstream": {
"type": "roundrobin",
"scheme": "http",
"nodes": [
{
"host": "httpbin.org",
"port": 80,
"weight": 100
}
]
}
}'

curl -k "https://localhost:7443/apisix/admin/routes/proxy-mirror-route?gateway_group_id={gateway_group_id}" -X PUT \
-H "X-API-KEY: ${API_KEY}" \
-H "Content-Type: application/json" \
-d '{
"name": "proxy-mirror-route",
"methods": ["GET"],
"paths": ["/anything/mirror"],
"service_id": "proxy-mirror-service",
"plugins": {
"proxy-mirror": {
"host": "http://test-server:8080",
"path": "/mirror-receiver",
"sample_ratio": 1
}
}
}'

Configure Sampled Traffic Mirroring

To mirror only a small percentage of your traffic, you can adjust the sample_ratio field.

curl -k "https://localhost:7443/apisix/admin/services/sampled-proxy-mirror-service?gateway_group_id={gateway_group_id}" -X PUT \
-H "X-API-KEY: ${API_KEY}" \
-H "Content-Type: application/json" \
-d '{
"name": "sampled-proxy-mirror-service",
"upstream": {
"type": "roundrobin",
"scheme": "http",
"nodes": [
{
"host": "httpbin.org",
"port": 80,
"weight": 100
}
]
}
}'

curl -k "https://localhost:7443/apisix/admin/routes/sampled-proxy-mirror-route?gateway_group_id={gateway_group_id}" -X PUT \
-H "X-API-KEY: ${API_KEY}" \
-H "Content-Type: application/json" \
-d '{
"name": "sampled-proxy-mirror-route",
"methods": ["GET"],
"paths": ["/anything/mirror-sampled"],
"service_id": "sampled-proxy-mirror-service",
"plugins": {
"proxy-mirror": {
"host": "http://test-server:8080",
"sample_ratio": 0.1
}
}
}'

Validate the Configuration

Send a request to the main service:

curl "http://127.0.0.1:9080/anything/mirror"

Check the logs of your mirrored service (http://test-server:8080) to verify that it received the mirrored request. Since mirroring happens asynchronously, the original client will not experience any delay.

The mirrored target must be reachable from the gateway instances themselves, not just from your local shell or the control plane. In a local Docker setup, exposing the mirror receiver on a host port is often the simplest way to make it reachable.

Next Steps