proxy-mirror

Description

The proxy-mirror Plugin can be used to mirror client requests.

proxy-mirror - 图1note

The response returned by the mirror request is ignored.

Attributes

NameTypeRequiredDefaultValid valuesDescription
hoststringTrueAddress of the mirror service. It needs to contain the scheme but without the path. For example, http://127.0.0.1:9797.
pathstringFalsePath of the mirror request. If unspecified, current path will be used.
sample_rationumberFalse1[0.00001, 1]Ratio of the requests that will be mirrored.

You can customize the proxy timeouts for the mirrored sub-requests by configuring the plugin_attr key in your configuration file (conf/config.yaml). This can be used for mirroring traffic to a slow backend.

conf/config.yaml

  1. plugin_attr:
  2. proxy-mirror:
  3. timeout:
  4. connect: 2000ms
  5. read: 2000ms
  6. send: 2000ms
NameTypeDefaultDescription
connectstring60sConnect timeout to the mirrored Upstream.
readstring60sRead timeout to the mirrored Upstream.
sendstring60sSend timeout to the mirrored Upstream.

Enabling the Plugin

You can enable the Plugin on a specific Route as shown below:

  1. curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
  2. {
  3. "plugins": {
  4. "proxy-mirror": {
  5. "host": "http://127.0.0.1:9797"
  6. }
  7. },
  8. "upstream": {
  9. "nodes": {
  10. "127.0.0.1:1999": 1
  11. },
  12. "type": "roundrobin"
  13. },
  14. "uri": "/hello"
  15. }'

Example usage

Once you have configured the Plugin as shown above, the requests made will be mirrored to the configured host.

  1. curl http://127.0.0.1:9080/hello -i
  1. HTTP/1.1 200 OK
  2. Content-Type: application/octet-stream
  3. Content-Length: 12
  4. Connection: keep-alive
  5. Server: APISIX web server
  6. Date: Wed, 18 Mar 2020 13:01:11 GMT
  7. Last-Modified: Thu, 20 Feb 2020 14:21:41 GMT
  8. hello world
proxy-mirror - 图2tip

For testing you can create a test server by running:

  1. python -m http.server 9797

Disable Plugin

To disable the proxy-mirror Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect.

  1. curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
  2. {
  3. "uri": "/hello",
  4. "plugins": {},
  5. "upstream": {
  6. "type": "roundrobin",
  7. "nodes": {
  8. "127.0.0.1:1999": 1
  9. }
  10. }
  11. }'