fix(stream/traffic-split): set route_id in stream preread phase#13284
fix(stream/traffic-split): set route_id in stream preread phase#13284nic-6443 merged 2 commits intoapache:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes stream (TCP/UDP) request context so route_id/route_name are populated after stream route matching, enabling plugins (e.g., traffic-split) to evaluate match conditions against route_id in the stream preread phase—consistent with the HTTP request path.
Changes:
- Assign
api_ctx.route_idandapi_ctx.route_nameinstream_preread_phase()after route match and before running preread plugins. - Add a stream plugin test that configures
traffic-splitwith aroute_id-based match condition and validates upstream selection.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
apisix/init.lua |
Sets api_ctx.route_id/route_name in stream preread before plugins run so ctx.var.route_id works in stream context. |
t/stream-plugin/traffic-split.t |
Adds regression coverage for traffic-split matching on route_id in stream routes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Fixed CI: TEST 5 was causing nginx to restart from stream mode to HTTP mode after TEST 4's 10 concurrent stream connections, which triggered |
|
Fixed the nginx.conf parse error. The issue was that TEST 5 had both |
|
Found the real root cause of the nginx.conf parse error. The The actual issue: Fixed by using a level-1 long bracket string |
In stream_preread_phase, api_ctx.route_id was never assigned after route matching, so ctx.var.route_id always returned nil in stream context. The HTTP access_phase sets it, but stream was missing it. This caused match conditions using route_id in plugins like traffic-split to always evaluate as nil and never match. The fix adds api_ctx.route_id (and route_name) assignment right before plugins run — matching the pattern already established in the HTTP path. Also adds a test case that creates a stream route with a traffic-split rule matching on route_id, and verifies traffic is correctly directed to the plugin-configured upstream.
8da1857 to
a22fe3d
Compare
In
stream_preread_phase,api_ctx.route_idwas never assigned after route matching, soctx.var.route_idalways returned nil in stream context. The HTTPaccess_phasesets it, but stream was missing it.This caused match conditions using
route_idin plugins liketraffic-splitto always evaluate as nil and never match.The fix adds
api_ctx.route_id(androute_name) assignment right before plugins run — matching the pattern already established in the HTTP path.Also adds a test case that creates a stream route with a traffic-split rule matching on
route_id, and verifies traffic is correctly directed to the plugin-configured upstream.