All Products
Search
Document Center

API Gateway:canary-header

Last Updated:May 22, 2025

The canary-header plug-in adds specific headers to requests based on a specified percentage. After a header is added to requests, routes are re-matched. You can use cloud-native gateways with this plug-in to implement routing for percentage-based canary releases without the need for the client requests to carry a canary header.

Fields

Configuration item

Data type

Required

Default value

Description

weighted_headers

array of object

Yes

-

The header to be added to requests and the weight in the header.

The following table describes the configuration items in the weighted_headers field.

Configuration item

Data type

Required

Default value

Description

added_key

string

Yes

-

The key of the header that you want to add to requests.

added_value

string

Yes

-

The value of the header that you want to add to requests.

weight

number

Yes

-

The weight of the header that you want to add to requests. Unit: %. The sum of the weights of all headers cannot be greater than 100.

Note

If the sum of the weights of all headers is less than 100, the portion that falls short of 100 indicates the percentage of requests to which no header is added.

Configuration examples

Global configuration

The following sample code indicates that the x-higress-canary:gray header is added to 30% of requests, and the x-higress-canary:base header is added to 70% of requests.

weighted_headers: 
- added_key: x-higress-canary
  added_value: gray
  weight: 30
- added_key: x-higress-canary
  added_value: base
  weight: 70

The following sample code indicates that the x-higress-canary:gray header is added to 30% of requests, and no header is added to 70% of requests.

weighted_headers: 
- added_key: x-higress-canary
  added_value: gray
  weight: 30

Enable the plug-in for specific routes or domain names

If the route-a route is matched, the x-higress-canary:gray header is added to 30% of requests, and the x-higress-canary:base header is added to 70% of requests. After the headers are added, the requests re-matches the route. For example, if the requests of a route named route-a-gray can be routed by header and the x-higress-canary:gray header is used for matching, 30% of the requests of the route-a route match the route-a-gray route. This way, percentage-based canary releases can be implemented.

# Use the _rules_ field to configure fine-grained rules.
_rules_:
# Rule 1: Match a route name.
- _match_route_:
  - route-a
  weighted_headers: 
  - added_key: x-higress-canary
    added_value: gray
    weight: 30
  - added_key: x-higress-canary
    added_value: base
    weight: 70
# Rule 2: Match a domain name.
- _match_domain_:
  - "*.example.com"
  weighted_headers:
  - added_key: x-custom-header
    added_value: gray
    weight: 30
  - added_key: x-custom-header
    added_value: blue
    weight: 30
  - added_key: x-custom-header
    added_value: base
    weight: 40