Skip to main content

proxy-mirror

Mirrors requests to another upstream.

Category TrafficAdd it to Route, Service, Consumer, Consumer group, Global rule, Plugin configEngine plugin proxy-mirrorPriority 1010

What it does​

proxy-mirror sends a copy of the requests on the route to a second address, set under Host, beside the normal trip to the route's upstream. The client gets the backend's answer, and the mirror's answer is thrown away.

Sample ratio decides how many requests are copied, every one unless you change it. In the example, 100 requests with 0.1 are answered 200 by the route's backend, and the shadow copy receives a GET of the same path.

When to use it​

  • A new version of the orders backend, run beside the old one, that must see real traffic before it answers any client.
  • A shadow copy of the service at http://shadow.internal:8080 that takes a tenth of the traffic for a load test.
  • A test environment that records live requests to reproduce a bug, while the answers clients get stay the same.
  • A shadow service that tells mirrored calls apart by a path of their own, /shadow for example, set under Path.

Not for moving a share of clients to another upstream that answers them — see traffic-split (Splits traffic between upstreams by weight and match rules) or recording what passed through the gateway without sending the request again — see http-logger (Sends request logs to an HTTP endpoint in batches).

Set it up​

Send a tenth of the traffic to a shadow copy of the service​

Set Host to http://shadow.internal:8080 and set Sample ratio to 0.1.

proxy-mirror · as the console saves it
{
"host": "http://shadow.internal:8080",
"sample_ratio": 0.1
}

Things to know​

  • Sample ratio — With 0.1, the client is answered 200 by the route's backend on each of 100 requests, and the shadow copy receives a GET of the same path.
  • Sample ratio — Each request is drawn on its own, so the share only comes close to this over many requests.
  • Host — A host that points back at this gateway can re-enter the route it was mirrored from, and one request then mirrors itself without end.
  • Host — A host that carries a path, http://mirror.internal/base, is refused when you save.
  • Path — A path with a query string, /shadow?a=1, is refused when you save.
  • Path mode — Replace, the default, sends the path above with the query string and drops the request's own path. Prefix puts the path above in front of it.
  • AdvicePoint the mirror at a service that can take the load and writes nothing to real data, for example a copy that works on a test database.

Settings​

The fields as the console shows them, section by section.

HosthoststringRequired

A scheme and a host with no path: the mirrored request is sent there on its own and its answer is thrown away.

pattern^(http(s)?|grpc(s)?):\/\/([\da-zA-Z.-]+|\[[\da-fA-F:]+\])(:\d+)?$
· example http://mirror.internal:8080
Pathpathstring

Left empty, the mirror is sent the path and query string the request arrived with.

pattern^/[^?&]+$
Path modepath_concat_modestringdefault replace

Read only when a path is set above.

one of prefix, replace
Sample ratiosample_rationumberdefault 1

The share of requests that are mirrored, where 1 mirrors every request. Each request is drawn on its own, so the share only comes close to this over many requests.

0.00001 to 1

Every plugin also has Enabled, Priority, Filter, Error response and Pre-function: see Plugin execution settings.

G8 dev · Apache APISIX® 3.19.0
Apache, Apache APISIX and APISIX are trademarks of The Apache Software Foundation.
Facts
Category
Traffic
Add it to
Route, Service, Consumer, Consumer group, Global rule, Plugin config
Engine plugin
proxy-mirror
Priority
1010