feat: add traffic-label plugin#13342
Merged
Merged
Conversation
The traffic-label plugin assigns configurable labels to requests based on weighted random distribution rules. It supports matching conditions using resty.expr expressions and writes the selected label to a specified request header or APISIX variable. Each rule defines a list of weighted labels and an optional match condition. When multiple rules are configured, the first matching rule is applied. If no rule matches, the plugin is a no-op. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Change priority from 995 to 967 to avoid conflict with gzip (995) - Move plugin registration to between gzip and traffic-split in config.lua - Add traffic-label entry to t/admin/plugins.t in correct priority position Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Rename APISIX CRD tab to APISIX Ingress Controller - Simplify admin_key note block Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
membphis
approved these changes
May 11, 2026
nic-6443
approved these changes
May 11, 2026
shreemaan-abhishek
approved these changes
May 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces the
traffic-labelplugin, which assigns configurable labels to requests based on weighted random distribution rules.Description
The
traffic-labelplugin selects a label from a configured set of weighted labels and writes it to a request header or APISIX variable. Multiple rules can be configured, each with an optional match condition usingresty.exprexpressions. The first matching rule is applied; if no rule matches, the plugin is a no-op.Use cases:
Key features
resty.expr-based match conditionsExample
The following example assigns the label
grayto 10% of requests andstableto 90%, writing the result to theX-Traffic-Labelheader:Downstream services can then read
X-Traffic-Labelto apply canary logic.Files changed
apisix/plugins/traffic-label.lua— plugin implementationt/plugin/traffic-label.t— basic test casest/plugin/traffic-label2.t— extended test casesdocs/en/latest/plugins/traffic-label.md— English documentationdocs/zh/latest/plugins/traffic-label.md— Chinese documentationapisix/cli/config.lua— register plugin in default listdocs/en/latest/config.json/docs/zh/latest/config.json— add to sidebar