This topic describes the configuration items of the traffic-tag plug-in. The configurations are used to manage traffic tags that are defined for canary release and test purposes based on specific rules.
Plug-in type
Traffic management.
Description
You can use the traffic-tag plug-in to tag request traffic based on weight or specific request content by adding specific request headers. You can use the traffic-tag plug-in to configure complex-logic rules for tagging traffic.
Configuration items
Field name | Data type | Default value | Required | Description |
| array of object | - | No | Defines a content-based marking condition group. For details about the structure, see Condition Group Configuration. |
| array of object | - | No | The weight-based condition groups. For more information, see the weightGroups configurations section in this topic. |
| string | - | No | The default tag key. If no condition is matched, the default tag key is used. This field takes effect only if the defaultTagVal field is configured. |
| string | - | No | The default tag value. If no condition is matched, the default tag value is used. This field takes effect only if the defaultTagKey field is configured. |
conditionGroups configurations
The following table describes the fields in the conditionGroups configuration item.
Field name | Type | Default value | Required | Description |
| string | - | Yes | The name of the HTTP header that you want to add or modify. |
| string | - | Yes | The value of the HTTP header. |
| string | - | Yes | The logical relationship among conditions, which can be |
| array of object | - | Yes | Describe the criteria for marking. |
The following table describes the fields in the conditions configuration item.
Field name | Data type | Default value | Required | Description |
| string | - | Yes | The condition type, which can be |
| string | - | Yes | The condition keyword. |
| string | - | Yes | The operator, which can be |
| array of string | - | Yes | The condition value. You can configure multiple values only if the operator is |
If the operator is regex, the regular expression engine RE2 is used. For more information, see RE2 official documentation.
weightGroups configurations
The following table describes the fields in the weightGroups configuration item.
Field name | Data type | Default value | Required | Description |
| string | - | Yes | The name of the HTTP header that you want to add or modify. |
| string | - | Yes | The value of the HTTP header. |
| integer | - | Yes | The traffic weight in percentage. |
Operators
Operator | Description |
| Exact match: The value must be an exact match. |
| If a value differs from the specified value, a condition is met. |
| If a value is prefixed with the specified value, a condition is met. |
| Inclusion match: The value must be present in the specified list. |
| An exclusion match occurs if the actual value is not in the specified list. |
| Matches the input against a regular expression. |
| If the inequality |
The following describes the differences between percentage and weight:
percentageoperator: used in a conditional expression to determine whether to perform an operation based on a specified percentage and key-value pair. For a key-value pair, the results of multiple matches are idempotent. If a condition is hit, the condition will be hit in subsequent matches.weightfield: used to define the weight for routing traffic to different paths. If traffic is tagged based on weight, theweightfield determines the percentage of traffic that is routed to a path. Unlike thepercentageoperator, the weight field does not define a fixed comparison basis, and traffic is randomly distributed based on weight. A request may be routed to different paths in different matches.If you use the
percentageoperator, the system determines whether a request meets specified percentage conditions. If you use theweightfield, the system distributes traffic in a static and random manner.
Configuration examples
Enable for a specific route
In this example, route-a and route-b specified in _match_route_ are the route names configured for the created gateway routes. If one of the two routes is matched, the configurations take effect.
If multiple rules are configured, the rules take effect in the order specified in _rules_. If a rule is matched, configurations of the rule take effect, and subsequent rules are ignored.
Example 1: Content-based matching
With the following configuration, the x-mse-tag: gray header is added to a request if it matches the route-a or route-b route and meets both of the following conditions: the role request header is user, viewer, or editor, and the query parameter is foo=bar. Because defaultTagKey and defaultTagVal are configured, requests that do not match any conditions have the x-mse-tag: base header added.
# Use the _rules_ field to configure fine-grained rules.
_rules_:
- _match_route_:
- route-a
- route-b
defaultTagKey: x-mse-tag
defaultTagVal: base
conditionGroups:
- headerName: x-mse-tag
headerValue: gray
logic: and
conditions:
- conditionType: header
key: role
operator: in
value:
- user
- viewer
- editor
- conditionType: parameter
key: foo
operator: equal
value:
- barExample 2: Weight-based matching
In the following sample code, a request has a 30% chance of being added with the request header x-mse-tag: gray, another 30% chance of being added with the request header x-mse-tag: blue, and a 40% chance of being added with no request header.
_rules_:
- _match_route_:
- route-a
- route-b
# The total weight is 100. The weight value 40, which is not configured, indicates that no header is added.
weightGroups:
- headerName: x-mse-tag
headerValue: gray
weight: 30
- headerName: x-mse-tag
headerValue: blue
weight: 30Enabling for specific domain names
In this example, *.example.com and test.com specified in _match_domain_ are the domain names used to match requests. If one of the two domain names is matched, the configurations take effect.
In the following sample code, requests that access *.example.com or test.com are matched. If a request contains the request header role and the value of the header is prefixed with user, such as role: user_common, the request header x-mse-tag: blue is added to the request.
_rules_:
- _match_domain_:
- "*.example.com"
- test.com
conditionGroups:
- headerName: x-mse-tag
headerValue: blue
logic: and
conditions:
- conditionType: header
key: role
operator: prefix
value:
- userGateway instance-level enabling
In this example, the _rules_ field is not specified and configurations take effect at the gateway level.
You can configure conditionGroups for content-based matching or weightGroups for weight-based matching. If you configure both configuration items, the traffic-tag plug-in preferentially matches requests based on conditions in conditionGroups. If conditions are met, request headers are added, and the matching ends. If no condition in conditionGroups is met, the traffic-tag plug-in adds request headers based on the weight specified in weightGroups.
conditionGroups:
- headerName: x-mse-tag-1
headerValue: gray
# logic is set to or, which indicates that a request is matched if one of the conditions is met.
logic: or
conditions:
- conditionType: header
key: foo
operator: equal
value:
- bar
- conditionType: cookie
key: x-user-type
operator: prefix
value:
- test
- headerName: x-mse-tag-2
headerValue: blue
# logic is set to and, which indicates that a request is matched only if all conditions are met.
logic: and
conditions:
- conditionType: header
key: x-type
operator: in
value:
- type1
- type2
- type3
- conditionType: header
key: x-mod
operator: regex
value:
- "^[a-zA-Z0-9]{8}$"
- headerName: x-mse-tag-3
headerValue: green
logic: and
conditions:
- conditionType: header
key: user_id
operator: percentage
value:
- 60
# The total weight is 100. The weight value 40, which is not configured, indicates that no header is added.
weightGroups:
- headerName: x-mse-tag
headerValue: gray
weight: 30
- headerName: x-mse-tag
headerValue: base
weight: 30