Updated on 2024-11-27 GMT+08:00

Proxy Mirror

APIG mirrors source backend requests to images for traffic analysis and statistics without affecting online services.

Usage Guidelines

  • The response to the image request will be ignored.
  • The body size of an image request is defaulted to 12 MB and can be configured via the parameter request_body_size. A larger request body size indicates greater performance loss. Exercise caution when performing this operation.
  • Not supported for APIs with a Mock backend.

Prerequisites

  • An API can be bound with only one policy of the same type.
  • Policies are independent of APIs. A policy takes effect for an API only after they are bound to each other. When binding a policy to an API, you must specify an environment where the API has been published. The policy takes effect for the API only in the specified environment.
  • After you bind a policy to an API, unbind the policy from the API, or update the policy, you do not need to publish the API again.
  • Taking an API offline does not affect the policies bound to it. The policies are still bound to the API if the API is published again.
  • Policies that have been bound to APIs cannot be deleted.

Creating a Proxy Mirror Policy

  1. Go to the APIG console.
  2. Select a dedicated gateway at the top of the navigation pane.
  1. In the navigation pane, choose API Management > API Policies.
  2. On the Policies tab, click Create Policy.
  3. On the Select Policy Type page, select Proxy Mirror in the Plug-ins area.
  4. Set the policy information.

    Table 1 Proxy mirror parameters

    Parameter

    Description

    Name

    Enter a policy name. Using naming rules facilitates future search.

    Type

    Fixed as Proxy Mirror.

    Description

    Description about the plug-in.

    Policy Content

    Content of the plug-in, which can be configured in a form or using a script.

    Protocol

    The image request protocol. It must be the same as the user's image service protocol.

    Image Address

    The image service address, which consists of the IP address/domain name and port number. Max: 255 characters. Format: Host name:Port number. Example: xxx.xxx.xxx:7443. If the port number is not specified, the default HTTPS port 443 or the default HTTP port 80 is used.

    Image URI

    URI for HTTP/HTTPS image requests. Max. 512 characters, including special characters (*%-_.). Defaults to the original path of the bound API if not specified.

    Concatenation

    Specifies how to concatenate the image request path.

    Replace: Uses the specified image request path.

    Prefix: Combines the specified image request path and the source request URI.

    Sampling Ratio

    Sampling ratio of image requests. Range: 0.00001–1. Default: 1 (full sampling)

    For example, if there are 1,000 API requests and the sampling ratio is 0.1, 100 requests will be sampled.

    Timeout (ms)

    Image request timeout. Unit: ms. Default: 5,000 ms.

    Mirror Request Body

    Mirrors the body of client requests. Enabled by default.

  5. Click OK.

    • To clone this policy, click Clone in the Operation column.

      The name of a cloned policy cannot be the same as that of any existing policy.

    • After the policy is created, perform the operations described in Binding the Policy to APIs for the policy to take effect for the API.

Example Script

{
  "protocol": "HTTPS",
  "host": "X.X.X.X",
  "sample_ratio": 1,
  "timeout": 5000,
  "mirror_request_body_enabled": true,
  "path": "/ab",
  "path_concat_mode": "replace"
}

Binding the Policy to APIs

  1. Click a policy name to go to the policy details page.
  2. Select an environment and click Select APIs.
  3. Select the API group, environment, and required APIs.

    APIs can be filtered by API name or tag. The tag is defined during API creation.

  4. Click OK.

    • If an API no longer needs this policy, click Unbind in the row that contains the API.
    • If there are multiple APIs that no longer need this policy, select these APIs, and click Unbind above the API list. You can unbind a policy from a maximum of 1000 APIs at a time.