Function Description

The traffic-tag plugin allows for tagging request traffic by adding specific request headers based on weight or specific request content. It supports complex logic to determine how to tag traffic according to user-defined standards.

Running Attributes

Plugin execution phase: Default Phase
Plugin execution priority: 400

Configuration Fields

This section provides a detailed description of the configuration fields.

Field NameTypeDefault ValueRequiredDescription
conditionGroupsarray of object-NoDefines content-based tagging condition groups, detailed structure in Condition Group Configuration.
weightGroupsarray of object-NoDefines weight-based tagging condition groups, detailed structure in Weight Group Configuration.
defaultTagKeystring-NoDefault tagging key name used when no conditions are matched. Only effective when defaultTagVal is also configured.
defaultTagValstring-NoDefault tagging value used when no conditions are matched. Only effective when defaultTagKey is also configured.

Condition Group Configuration

The configuration fields for each item in conditionGroups are described as follows:

Field NameTypeDefault ValueRequiredDescription
headerNamestring-YesThe HTTP header name to be added or modified.
headerValuestring-YesThe value of the HTTP header.
logicstring-YesLogical relationship in the condition group, supports and, or, must be in lowercase.
conditionsarray of object-YesDescribes specific tagging conditions, detailed structure below.

The configuration fields for each item in conditions are described as follows:

Field NameTypeDefault ValueRequiredDescription
conditionTypestring-YesCondition type, supports header, parameter, cookie.
keystring-YesThe key of the condition.
operatorstring-YesOperator, supports equal, not_equal, prefix, in, not_in, regex, percentage.
valuearray of string-YesThe value of the condition. Only when the operator is in and not_in multiple values are supported.

Note: When the operator is regex, the regular expression engine used is RE2. For details, please refer to the RE2 Official Documentation.

Weight Group Configuration

The configuration fields for each item in weightGroups are described as follows:

Field NameTypeDefault ValueRequiredDescription
headerNamestring-YesThe HTTP header name to be added or modified.
headerValuestring-YesThe value of the HTTP header.
weightinteger-YesTraffic weight percentage.

Operator Description

OperatorDescription
equalExact match, values must be identical.
not_equalNot equal match, condition met when values are different.
prefixPrefix match, condition met when the specified value is a prefix of the actual value.
inInclusion match, actual value must be in the specified list.
not_inExclusion match, condition met when actual value is not in the specified list.
regexRegular expression match, matched according to regex rules.
percentagePercentage match, principle: hash(get(key)) % 100 < value, condition met when true.

Tip: About the difference between percentage and weight

  • percentage operator: Used in conditional expressions, it determines whether to perform a certain operation based on specified percentages and key-value pairs. For the same key-value pair, the result of multiple matches is idempotent, meaning if a condition is hit this time, it will hit it next time as well.
  • weight field: Used to define traffic weights for different processing paths. In weight-based traffic tagging, weight determines the proportion of traffic a particular path should receive. Unlike percentage, since there is no fixed comparison basis and it is based on random weight distribution, multiple matches for the same request may yield multiple results.

When using percentage for conditional matching, it assesses whether each request meets specific percentage conditions; while weight is a static random allocation of overall traffic distribution.

Configuration Example

Example 1: Content-based Matching
According to the configuration below, requests where the request header role has a value of user, viewer, or editor and contain query parameter foo=bar will have the request header x-mse-tag: gray added. Since defaultTagKey and defaultTagVal are configured, when no conditions are matched, the request will have the request header x-mse-tag: base added.

  1. defaultTagKey: x-mse-tag
  2. defaultTagVal: base
  3. conditionGroups:
  4. - headerName: x-mse-tag
  5. headerValue: gray
  6. logic: and
  7. conditions:
  8. - conditionType: header
  9. key: role
  10. operator: in
  11. value:
  12. - user
  13. - viewer
  14. - editor
  15. - conditionType: parameter
  16. key: foo
  17. operator: equal
  18. value:
  19. - bar

Example 2: Weight-based Matching
According to the configuration below, there is a 30% chance that the request will have the request header x-mse-tag: gray added, a 30% chance it will have x-mse-tag: blue added, and a 40% chance that no header will be added.

  1. # The total weight is 100; the 40 weight not configured in the example will not add a header.
  2. weightGroups:
  3. - headerName: x-mse-tag
  4. headerValue: gray
  5. weight: 30
  6. - headerName: x-mse-tag
  7. headerValue: blue
  8. weight: 30