traffic-split
Splits traffic between upstreams by weight and match rules.
traffic-splitPriority 966What it does
traffic-split sends a share of a route's requests to another upstream. Each entry under Rules has a Match that decides which requests it takes, and Weighted upstreams that share them out by Weight.
The rules are read in order, and the first whose conditions pass takes the request. A request no rule takes goes to the route's own upstream, and so does the share of an entry that names no upstream.
When to use it
- A canary release: a new version of the orders service takes a tenth of the requests while the current one serves the rest.
- Moving from an old backend to a new one in steps, raising the new version's weight as it proves itself.
- Testers who send a release header reach the new version, while every other client stays on the current one.
- One tenant's requests, matched by a cookie or a header, sent to backends of its own.
Not for balancing requests between the instances of one backend — see Upstream (Upstreams are the backends that routes and services send traffic to) or choosing a backend by path, host or method — see Route (Routes match incoming requests and send them to an upstream).
Guides
Pages that walk through a job with traffic-split, step by step.
- Send a share of requests to a new versionSend a tenth of a route's requests to a new version of its backend, and raise the share as the new version proves itself.
Set it up
Send a tenth of the traffic to a new version of the service
Needs an upstream with the id checkout-v2; the entry without an upstream id sends to the route's own upstream.
Fill Rules as in the JSON below.
{
"rules": [
{
"weighted_upstreams": [
{
"upstream_id": "checkout-v2",
"weight": 1
},
{
"weight": 9
}
]
}
]
}
What you will see
- Over many requests every answer is
200, and both the route's own backend and the new version answer some of them; one request on its own cannot show the split.
Things to know
- Rules — The first rule whose conditions pass takes the request, so an unconditioned rule hides every rule below it. When no rule takes the request, the object's own upstream serves it.
- Weight — With weights
1and9, 100 requests are answered partly by the upstreamcheckout-v2and partly by the route's own upstream. - Weighted upstreams — An entry with a weight and no upstream sends its share to the route's own upstream. In the example, the requests that do not reach
checkout-v2reach the route's own backend. - Weighted upstreams — A rule holds at most 20 entries; more are refused when you save.
- Rules — An empty list of rules is refused when you save.
- Conditions — A match entry with no conditions is refused when you save.
- Upstream — An upstream written here with
httpsopens TLS without checking the backend's certificate. - Upstream — An upstream written here needs its nodes. One found by service discovery is refused when you save.
- Upstream — A slow start,
warm_up_conf, is refused when you save. - AdviceGive a new version an upstream of its own and name it under Upstream ID, so that its nodes are kept in one place for every route that splits to it.
Settings
The fields as the console shows them, section by section.
rulesarray of objectsrules[].matcharray of objectsThe rule takes the request when any one of these condition sets passes.
rules[].match[].varsarrayRequiredrules[].weighted_upstreamsarray of objectsdefault [{"weight":1}]An entry that names no upstream at all stands for the object's own upstream.
rules[].weighted_upstreams[].upstream_idstring or integerAn existing upstream to send this share to; an id that names none is stored and then fails every request of this rule. An id written beside an upstream of its own is the one that is used.
pattern
^[a-zA-Z0-9-_.]+$rules[].weighted_upstreams[].weightintegerdefault 1The share of this rule's traffic that goes to this upstream, such as 20 beside 80. A weight of 0 takes it out of the split only while another entry of the rule carries more than 0; an entry left alone in its rule takes every request whatever its weight.
rules[].weighted_upstreams[].upstreamobjectAn upstream written here for this share; its nodes, algorithm and key, timeout, scheme and Host passing are read. https and wss open TLS (https checks no certificate, wss always does); ws, grpc and grpcs go plain; everything else is stored, never used. A keyless consistent hash on a header, cookie or variable fails every request past one node. Its keys are those of an upstream, each described on that page; only the ones named here are read.
{"type":"roundrobin","scheme":"https","nodes":{"10.0.0.14:8443":1}}