Skip to main content

Version: 3.2.14.1

Configure Canary Traffic Shifting

Canary traffic shifting enables you to safely test new upstreams with a small percentage of your traffic while keeping most traffic to the baseline upstream.

note

Canary traffic shifting differs from a canary release as the API/service version is unchanged. Canary release refers to the simultaneous operation and availability of two versions of the same API/service.

Prerequisites

  1. Install API7 Enterprise.
  2. Have a running API on the gateway group.

Shift Traffic by Percentage

In this example, you will direct 10% of the traffic to a canary upstream. The remaining 90% will continue to be forwarded to the baseline upstream.

note

The canary rule applies to all routes in a service and cannot be applied to individual routes.

After the new canary upstream is tested, all traffic can be routed to the canary upstream and it becomes the new baseline upstream. The older baseline upstream can then be removed.

  1. Select Published Services of your gateway group from the side navigation bar, then click the service you want to modify, for example, httpbin API with version 1.0.0.
  2. Under the published service, select Upstreams from the side navigation bar.
  3. In the Canary Rules field, click Start Canary.
  4. From the dialog box, do the following:
  • In the Conditions field, close the switch.
  • In the Weight field, enter 10.
  • Click Next.
  1. In the Choose or Create Canary Upstream field, choose to create a new upstream.
  • Modify the name of the new upstream to newupstream.
  • Adjust the host of the node to point to the new backend. For example, use mock.api7.ai as the host and 80 as the port.
  • Keep the other properties the same as the baseline upstream.
  • Click Next.
  1. Confirm the displayed information and click Start. The canary rules will start working immediately.

  2. Validate the canary rules by sending 10 requests:

    for i in {1..10}; do "curl 127.0.0.1:9080/headers";  done

    9 requests will be sent to the baseline upstream address, httpbin.org, and you will receive the following response:

    {
    "headers": {
    "Accept": "*/*",
    "Host": "httpbin.org",
    "User-Agent": "curl/7.74.0",
    "X-Amzn-Trace-Id": "Root=1-6650ab7e-32c90eba787abbeb4e3dbb0c",
    "X-Forwarded-Host": "127.0.0.1"
    }
    }

    A single request will be sent to the canary upstream address, mock.api7.ai:

    {
    "headers": {
    "accept": "*/*",
    "accept-encoding": "gzip, br",
    "cf-connecting-ip": "159.89.160.194",
    "cf-ipcountry": "IN",
    "cf-ray": "888e28733f9604aa",
    "cf-visitor": "{\"scheme\":\"https\"}",
    "connection": "Keep-Alive",
    "content-type": "application/json",
    "host": "mock.api7.ai",
    "user-agent": "curl/7.74.0",
    "x-application-owner": "API7.ai",
    "x-forwarded-for": "127.0.0.1",
    "x-forwarded-host": "127.0.0.1",
    "x-forwarded-port": "9080",
    "x-forwarded-proto": "https",
    "x-real-ip": "159.89.160.194",
    "X-Application-Owner": "API7.ai",
    "Content-Type": "application/json"
    }
    }
  3. In the Canary Rules field, click Edit.

  4. From the dialog box, do the following:

  • Adjust the weight to 50%.
  • Click Edit.
  1. Make more requests to test the canary upstream, until it meets your expectation.
  2. In the Canary Rules field, click Finish.
  3. From the dialog box, do the following:
  • In the Baseline Upstream field, choose canary upstream: newupstream.
  • In the Delete Unselected Upstream field, close the switch.
  • Click Finish.

Shift Traffic by Request Header

In this example, you will direct requests with the header version = test to the canary upstream, while the remaining traffic will continue to the baseline upstream. The canary rule applies to all routes in a service and cannot be applied to individual routes.

  1. Select Published Services of your gateway group from the side navigation bar, then click the service you want to modify, for example, httpbin API with version 1.0.0.
  2. Under the service, select Upstreams from the side navigation bar.
  3. In the Canary Rules field, click Start Canary.
  4. From the dialog box, do the following:
  • In the Conditions field, open the switch.
  • Fill in the header requirement with header evaluation version == test.
  • In the Weight field, enter 100.
  • Click Next.
  1. In the Choose or Create Canary Upstream field, choose to create a new upstream.
  • Modify the name of the new upstream to newupstream.
  • Adjust the host of the node to point to the new backend. For example, use mock.api7.ai as the host and 80 as the port.
  • Keep the other properties the same as the baseline upstream.
  • Click Next.
  1. Confirm the displayed information and click Start. The canary rules will start working immediately.

  2. Validate the canary rules by sending requests:

    Send a request with the version:test header:

    curl 127.0.0.1:9080/headers -H "version:test"

    You shall receive the following response from the canary upstream:

    {
    "headers": {
    "accept": "*/*",
    "accept-encoding": "gzip, br",
    "cf-connecting-ip": "159.89.160.194",
    "cf-ipcountry": "IN",
    "cf-ray": "888e28733f9604aa",
    "cf-visitor": "{\"scheme\":\"https\"}",
    "connection": "Keep-Alive",
    "content-type": "application/json",
    "host": "mock.api7.ai",
    "user-agent": "curl/7.74.0",
    "x-application-owner": "API7.ai",
    "x-forwarded-for": "127.0.0.1",
    "x-forwarded-host": "127.0.0.1",
    "x-forwarded-port": "9080",
    "x-forwarded-proto": "https",
    "x-real-ip": "159.89.160.194",
    "X-Application-Owner": "API7.ai",
    "Content-Type": "application/json"
    }
    }

    Send a request with the wrong header:

    curl 127.0.0.1:9080/headers -H "version:new"

    You shall receive the following response from the baseline upstream:

    {
    "headers": {
    "Accept": "*/*",
    "Host": "httpbin.org",
    "User-Agent": "curl/7.74.0",
    "X-Amzn-Trace-Id": "Root=1-6650ab7e-32c90eba787abbeb4e3dbb0c",
    "X-Forwarded-Host": "127.0.0.1"
    }
    }

    Send a request with no header:

    curl 127.0.0.1:9080/headers

    You shall receive the following response from the baseline upstream:

    {
    "headers": {
    "Accept": "*/*",
    "Host": "httpbin.org",
    "User-Agent": "curl/7.74.0",
    "X-Amzn-Trace-Id": "Root=1-6650ab7e-32c90eba787abbeb4e3dbb0c",
    "X-Forwarded-Host": "127.0.0.1"
    }
    }
  3. Make more requests to test the canary upstream, until it meets your expectation.

  4. In the Canary Rules field, click Finish.

  5. From the dialog box, do the following:

  • In the Baseline Upstream field, choose canary upstream: newupstream.
  • In the Delete Unselected Upstream field, close the switch.
  • Click Finish.

Additional Resources


API7.ai Logo

API Management for Modern Architectures with Edge, API Gateway, Kubernetes, and Service Mesh.

Product

API7 Cloud

SOC2 Type IRed Herring

Copyright © APISEVEN Ltd. 2019 – 2024. Apache, Apache APISIX, APISIX, and associated open source project names are trademarks of the

Apache Software Foundation