This is an automated email from the ASF dual-hosted git repository.
spacewander 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 67eb787 fix: distinguish different routes which has the same service
(#2840)
67eb787 is described below
commit 67eb787c383c8c2ac4b42896edc9372e63b6c75c
Author: 罗泽轩 <[email protected]>
AuthorDate: Wed Nov 25 14:32:11 2020 +0800
fix: distinguish different routes which has the same service (#2840)
Fix #2828.
The bug is introduced in #2121.
Can't be reproduced in over 1 millions requests after applying this
patch.
---
apisix/plugin.lua | 3 ++-
t/config-center-yaml/route-service.t | 41 +++++++++++++++++++++++++++++++++++
t/config-center-yaml/route-upstream.t | 5 +++++
t/config-center-yaml/route.t | 3 +++
4 files changed, 51 insertions(+), 1 deletion(-)
diff --git a/apisix/plugin.lua b/apisix/plugin.lua
index b5fe014..a319fbc 100644
--- a/apisix/plugin.lua
+++ b/apisix/plugin.lua
@@ -396,7 +396,8 @@ function _M.merge_service_route(service_conf, route_conf)
core.log.info("service conf: ", core.json.delay_encode(service_conf))
core.log.info(" route conf: ", core.json.delay_encode(route_conf))
- local route_service_key = route_conf.modifiedIndex .. "#" ..
service_conf.modifiedIndex
+ local route_service_key = route_conf.value.id .. "#"
+ .. route_conf.modifiedIndex .. "#" .. service_conf.modifiedIndex
return merged_route(route_service_key, service_conf,
merge_service_route,
service_conf, route_conf)
diff --git a/t/config-center-yaml/route-service.t
b/t/config-center-yaml/route-service.t
index 8febcd7..8876022 100644
--- a/t/config-center-yaml/route-service.t
+++ b/t/config-center-yaml/route-service.t
@@ -39,6 +39,7 @@ routes:
-
uri: /hello
service_id: 1
+ id: 1
services:
-
id: 1
@@ -62,6 +63,7 @@ hello world
routes:
-
uri: /hello
+ id: 1
service_id: 1111
services:
-
@@ -84,6 +86,7 @@ failed to fetch service configuration by id: 1111
--- apisix_yaml
routes:
-
+ id: 1
uri: /hello
service_id: 1
services:
@@ -115,6 +118,7 @@ hello world
--- apisix_yaml
routes:
-
+ id: 1
uri: /hello
service_id: 1
upstream:
@@ -149,6 +153,7 @@ hello world
--- apisix_yaml
routes:
-
+ id: 1
uri: /hello
service_id: 1
upstream:
@@ -184,6 +189,7 @@ hello world
--- apisix_yaml
routes:
-
+ id: 1
uri: /hello
service_id: 1
upstream:
@@ -211,3 +217,38 @@ GET /hello
hello world
--- no_error_log
[error]
+
+
+
+=== TEST 7: two routes with the same service
+--- yaml_config eval: $::yaml_config
+--- apisix_yaml
+routes:
+ - uris:
+ - /hello
+ service_id: 1
+ id: 1
+ plugins:
+ response-rewrite:
+ body: "hello\n"
+ - uris:
+ - /world
+ service_id: 1
+ id: 2
+ plugins:
+ response-rewrite:
+ body: "world\n"
+services:
+ -
+ id: 1
+ upstream:
+ nodes:
+ "127.0.0.1:1980": 1
+ type: roundrobin
+#END
+--- request
+GET /hello
+--- response_body
+hello
+--- no_error_log
+[error]
diff --git a/t/config-center-yaml/route-upstream.t
b/t/config-center-yaml/route-upstream.t
index 46063a8..42908da 100644
--- a/t/config-center-yaml/route-upstream.t
+++ b/t/config-center-yaml/route-upstream.t
@@ -37,6 +37,7 @@ __DATA__
--- apisix_yaml
routes:
-
+ id: 1
uri: /hello
upstream_id: 1
upstreams:
@@ -60,6 +61,7 @@ hello world
--- apisix_yaml
routes:
-
+ id: 1
uri: /hello
upstream_id: 1111
upstreams:
@@ -82,6 +84,7 @@ failed to find upstream by id: 1111
--- apisix_yaml
routes:
-
+ id: 1
uri: /hello
upstream_id: 1
upstream:
@@ -109,6 +112,7 @@ hello world
--- apisix_yaml
routes:
-
+ id: 1
uri: /hello
upstream_id: 1
upstreams:
@@ -139,6 +143,7 @@ hello world
--- apisix_yaml
routes:
-
+ id: 1
uri: /get
upstream_id: 1
upstreams:
diff --git a/t/config-center-yaml/route.t b/t/config-center-yaml/route.t
index 972f1f0..81a37d1 100644
--- a/t/config-center-yaml/route.t
+++ b/t/config-center-yaml/route.t
@@ -37,6 +37,7 @@ __DATA__
--- apisix_yaml
routes:
-
+ id: 1
uri: /hello
upstream:
nodes:
@@ -82,6 +83,7 @@ use config_center: yaml
--- apisix_yaml
routes:
-
+ id: 1
uri: /hello
host: foo.com
upstream:
@@ -106,6 +108,7 @@ hello world
stream_routes:
- server_addr: 127.0.0.1
server_port: 1985
+ id: 1
upstream:
nodes:
"127.0.0.1:1995": 1