Skip to main content

Canary releases with traffic-split: 10 % of requests to the new version

Send a weighted share of a Route's traffic to a second Upstream with traffic-split, route chosen callers to it by header, and count the split in the records.

By Akif F. Güven Updated Gateway

What you will have at the end

A Route, orders-canary, whose requests go to the current orders service nine times out of ten and to the new version once, by weight; then a rule above it that sends every request carrying a chosen header to the new version alone, so a tester can use v2 on purpose while everyone else stays on the split. Both backends count their requests, Traffic Explorer names which node answered each request, Analytics lists both Upstreams, and the two changes are in the audit log.

Prerequisites

  • Two versions of a backend. Here orders-backend is the Upstream of the orders service in use, orders-svc:8080, and orders-v2 a second Upstream for the release candidate, orders-v2:8080, which answers the same paths and adds a response header, X-Orders-Version: v2, so the article can count who answered.
  • A Route to the current version. orders-canary serves /shop/orders/* from orders-backend and rewrites the path with proxy-rewrite; it carries no authentication, so the article can send a hundred requests without a budget in the way.
  • Traffic logging turned on under Traffic Explorer › Settings, a Prometheus the Environment reads, and a role that may manage Routes. The screenshots below were taken as nora.becker.

A share by weight

Open the Route, select the Plugins tab, Add plugin, and choose traffic-split. The form is a list of Rules; each rule has a Match section and a Weighted upstreams section, and the note at the bottom of the form says how they combine: the first rule whose conditions pass takes the request, an unconditioned rule hides every rule below it, and when no rule takes the request, the Route’s own Upstream serves it.

Add one rule and leave Match empty, so it applies to every request. Under Weighted upstreams, add two entries:

  • Upstream ID: orders-v2, picked from the list of the Environment’s Upstreams, with Weight 10.
  • A second entry with no Upstream at all and Weight 90. The note under the list says what that means: an entry that names no upstream stands for the Route’s own Upstream, the current version.

Upstream, the third field of each entry, takes an Upstream written inline, with its own nodes, for a share that has no Upstream object; it stays empty here.

The traffic-split form on orders-canary: one rule with Match empty and, under Weighted upstreams, Entry 1 with Upstream ID orders-v2 · 00000000000000010241 and Weight 10, and the Upstream editor showing its placeholder One rule, no condition, two shares. The second entry, with no Upstream named, is the current version.

Select Add plugin. A hundred requests without any header, counted by the version header of the answer:

100 requests without a header: v1=93 v2=7

The split is by chance per request, so a run of a hundred lands near 90/10 and not on it; the backends’ own logs for the same minute read 98 and 8, the extra ones being the article’s first probes.

A chosen caller goes to v2 every time

Edit the Plugin and add a second rule. Under its Match, add an entry and one Condition: Variable http_x_canary, Operator ==, Value 1; the help under the section says the rule takes the request when any one of its condition sets passes. Under Weighted upstreams, one entry: orders-v2 with Weight 100. Then move this rule above the first one with the arrow in its header, because the first rule is unconditioned and would hide it.

The traffic-split form with the conditioned rule as Entry 1: under Match a condition row with Variable http_x_canary, Negate unticked, Operator == and Value 1, and under Weighted upstreams the entry orders-v2 · 00000000000000010241 The conditioned rule sits first. A request with x-canary: 1 is taken here; everything else falls through to the 10/90 rule.

The Variable names a request variable: http_x_canary is the header x-canary, arg_version would be a query parameter, consumer_name the Consumer an authentication Plugin set. The Operator list holds comparisons, regular expressions, in, has and ipmatch, so the same form routes a Consumer, a client network or a version parameter to the new version.

Select Save plugin. Twenty requests with the header and a hundred without:

20 requests with x-canary: 1 → v1=0 v2=20
100 requests without the header → v1=92 v2=8

What Traffic Explorer and Analytics show

Every request is a record, and the Upstream node column names the address that answered: two addresses on one Route, the current version’s and the candidate’s, in about the share set.

Traffic Explorer filtered to the path /shop/orders: GET records for /shop/orders/ord-10421, all 200, with two different Upstream node addresses, 172.23.0.24:8080 and 172.23.0.30:8080, across the rows One Route, two nodes. A row’s Upstream node says which version answered it.

Under Analytics, the list Upstreams · most requests counts the requests handed to each Upstream’s nodes on the Routes that reach it, so both versions appear with their own counts. The save itself is an audit record, and audit records are drawn as markers on the Route’s request chart, as Audit records shows.

The Analytics card Upstreams · most requests: payments-backend 2.4K, orders-backend 313, orders-v2 128 and httpbin-backend 17 in the last 24 hours The candidate has its own row as soon as the first request reached it. Watch its 5xx row next to it before raising the weight.

Raising the share is a change to the two weights; moving everyone to v2 is a change to the Route’s Upstream and the removal of the Plugin. Each is an audit record.

What the audit log keeps

Adding traffic-split is a Route update with the rules as the difference, and the second save is another, with the conditioned rule added above the first. There is no secret in this Plugin, so nothing is masked.

The Change section of the audit record of the orders-canary Route update: the traffic-split block with two rules on the after side, the first with the match on http_x_canary and orders-v2 at weight 100, the second with orders-v2 at weight 10 and an entry with weight 90 and no upstream The rules as the engine received them. The order of the rules is part of the record, because it decides who goes where.

What to do next

Written by
Akif F. Güven
Engineer, G8
Was this helpful?
Next step

See G8 in a demo

We’ll show you the console with APIs and AI traffic like yours, and answer the questions these articles leave open.

  1. 01Demo
  2. 02Proof of conceptOn Docker for a quick start, or on the infrastructure you plan to run G8 on.
  3. 03LicenseWe prepare a quote for your edition and nodes, and you receive a signed license file.