You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by ni...@apache.org on 2026/04/25 02:46:06 UTC

(apisix) branch master updated: fix(stream/traffic-split): set route_id in stream preread phase (#13284)

This is an automated email from the ASF dual-hosted git repository.

nic-6443 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git


The following commit(s) were added to refs/heads/master by this push:
     new 08bf6248a fix(stream/traffic-split): set route_id in stream preread phase (#13284)
08bf6248a is described below

commit 08bf6248ad2196109b4cf73f22f98a502362161c
Author: Nic <qi...@api7.ai>
AuthorDate: Sat Apr 25 10:46:00 2026 +0800

    fix(stream/traffic-split): set route_id in stream preread phase (#13284)
---
 apisix/init.lua                 |  2 ++
 t/stream-plugin/traffic-split.t | 66 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 68 insertions(+)

diff --git a/apisix/init.lua b/apisix/init.lua
index 385ebc192..3b3b92b7b 100644
--- a/apisix/init.lua
+++ b/apisix/init.lua
@@ -1344,6 +1344,8 @@ function _M.stream_preread_phase()
     api_ctx.conf_type = "stream/route"
     api_ctx.conf_version = matched_route.modifiedIndex
     api_ctx.conf_id = matched_route.value.id
+    api_ctx.route_id = matched_route.value.id
+    api_ctx.route_name = matched_route.value.name
 
     plugin.run_plugin("preread", plugins, api_ctx)
 
diff --git a/t/stream-plugin/traffic-split.t b/t/stream-plugin/traffic-split.t
index 9de540140..4bdea41a5 100644
--- a/t/stream-plugin/traffic-split.t
+++ b/t/stream-plugin/traffic-split.t
@@ -343,3 +343,69 @@ GET /hit
 --- response_body
 hello world from port 1995
 --- stream_enable
+
+
+
+=== TEST 7: set stream route with traffic-split using route_id in match condition
+--- config
+    location /t {
+        content_by_lua_block {
+            local t = require("lib.test_admin").test
+            local code, body = t('/apisix/admin/stream_routes/3',
+                ngx.HTTP_PUT,
+                [=[{
+                    "plugins": {
+                        "traffic-split": {
+                            "rules": [{
+                                "match": [
+                                    {
+                                        "vars": [["route_id", "==", "3"]]
+                                    }
+                                ],
+                                "weighted_upstreams": [
+                                    {
+                                        "upstream": {
+                                            "name": "upstream_A",
+                                            "type": "roundrobin",
+                                            "nodes": {
+                                                "127.0.0.1:1995": 1
+                                            }
+                                        },
+                                        "weight": 1
+                                    }
+                                ]
+                            }]
+                        }
+                    },
+                    "upstream": {
+                        "nodes": {
+                            "127.0.0.1:1997": 1
+                        },
+                        "type": "roundrobin"
+                    }
+                }]=]
+            )
+            if not code then
+                ngx.status = 500
+                ngx.say("failed to connect to admin API for stream_routes/3: ", body)
+                return
+            end
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+
+
+
+=== TEST 8: route_id match condition directs traffic to plugin upstream
+--- request
+GET /hit
+--- response_body
+hello world from port 1995
+--- stream_enable