From df6b1218cab480deccf33bb37c2bf490ec27685e Mon Sep 17 00:00:00 2001 From: chronolaw Date: Sun, 1 Dec 2024 13:11:07 +0800 Subject: [PATCH 1/8] add rpc service in custom plugin --- .../18-hybrid_rpc/01-rpc_spec.lua | 20 +++++++++++-------- .../plugins/rpc-framework-test/handler.lua | 14 +++++++++++++ .../plugins/rpc-framework-test/schema.lua | 12 +++++++++++ 3 files changed, 38 insertions(+), 8 deletions(-) create mode 100644 spec/fixtures/custom_plugins/kong/plugins/rpc-framework-test/handler.lua create mode 100644 spec/fixtures/custom_plugins/kong/plugins/rpc-framework-test/schema.lua diff --git a/spec/02-integration/18-hybrid_rpc/01-rpc_spec.lua b/spec/02-integration/18-hybrid_rpc/01-rpc_spec.lua index 6b717e293cbf..f18c317836c7 100644 --- a/spec/02-integration/18-hybrid_rpc/01-rpc_spec.lua +++ b/spec/02-integration/18-hybrid_rpc/01-rpc_spec.lua @@ -2,10 +2,9 @@ local helpers = require "spec.helpers" local cjson = require("cjson.safe") local CLUSTERING_SYNC_STATUS = require("kong.constants").CLUSTERING_SYNC_STATUS --- we need incremental sync to verify rpc -for _, inc_sync in ipairs { "on" } do +-- register a test rpc service in custom plugin rpc-framework-test for _, strategy in helpers.each_strategy() do - describe("Hybrid Mode RPC #" .. strategy .. " inc_sync=" .. inc_sync, function() + describe("Hybrid Mode RPC #" .. strategy, function() lazy_setup(function() helpers.get_db_utils(strategy, { @@ -20,7 +19,8 @@ for _, strategy in helpers.each_strategy() do cluster_listen = "127.0.0.1:9005", nginx_conf = "spec/fixtures/custom_nginx.template", cluster_rpc = "on", - cluster_incremental_sync = inc_sync, -- incremental sync + plugins = "bundled,rpc-framework-test", + cluster_incremental_sync = "off", })) assert(helpers.start_kong({ @@ -33,6 +33,7 @@ for _, strategy in helpers.each_strategy() do proxy_listen = "0.0.0.0:9002", nginx_conf = "spec/fixtures/custom_nginx.template", cluster_rpc = "on", + plugins = "bundled,rpc-framework-test", cluster_incremental_sync = inc_sync, -- incremental sync })) end) @@ -69,9 +70,13 @@ for _, strategy in helpers.each_strategy() do assert(tonumber(m[2]) >= 9) -- check the available rpc service - table.sort(v.rpc_capabilities) - assert.same("kong.sync.v2", v.rpc_capabilities[1]) - return true + for _, c in ipairs(v.rpc_capabilities) do + if c == "kong.test" then + return true + end + end + + return false end end end, 10) @@ -79,4 +84,3 @@ for _, strategy in helpers.each_strategy() do end) end) end -- for _, strategy -end -- for inc_sync diff --git a/spec/fixtures/custom_plugins/kong/plugins/rpc-framework-test/handler.lua b/spec/fixtures/custom_plugins/kong/plugins/rpc-framework-test/handler.lua new file mode 100644 index 000000000000..a54eb406d547 --- /dev/null +++ b/spec/fixtures/custom_plugins/kong/plugins/rpc-framework-test/handler.lua @@ -0,0 +1,14 @@ +local RpcFrameworkTestHandler = { + VERSION = "1.0", + PRIORITY = 1000, +} + + +function RpcFrameworkTestHandler:init_worker() + kong.rpc.callbacks:register("kong.test.hello", function(node_id, greeting) + return "hello ".. greeting + end) +end + + +return RpcFrameworkTestHandler diff --git a/spec/fixtures/custom_plugins/kong/plugins/rpc-framework-test/schema.lua b/spec/fixtures/custom_plugins/kong/plugins/rpc-framework-test/schema.lua new file mode 100644 index 000000000000..ab028ed7eda8 --- /dev/null +++ b/spec/fixtures/custom_plugins/kong/plugins/rpc-framework-test/schema.lua @@ -0,0 +1,12 @@ +return { + name = "rpc-framework-test", + fields = { + { + config = { + type = "record", + fields = { + }, + }, + }, + }, +} From f89ff3d5b31a4bc25617c61628fef5c115c9361e Mon Sep 17 00:00:00 2001 From: chronolaw Date: Sun, 1 Dec 2024 13:13:04 +0800 Subject: [PATCH 2/8] 04-concentrator_spec --- .../18-hybrid_rpc/04-concentrator_spec.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/spec/02-integration/18-hybrid_rpc/04-concentrator_spec.lua b/spec/02-integration/18-hybrid_rpc/04-concentrator_spec.lua index f88e0bba8aa1..0631c688ea92 100644 --- a/spec/02-integration/18-hybrid_rpc/04-concentrator_spec.lua +++ b/spec/02-integration/18-hybrid_rpc/04-concentrator_spec.lua @@ -28,10 +28,9 @@ local function obtain_dp_node_id() -- luacheck: ignore end --- we need incremental sync to verify rpc -for _, inc_sync in ipairs { "on" } do +-- register a test rpc service in custom plugin rpc-framework-test for _, strategy in helpers.each_strategy() do - describe("Hybrid Mode RPC over DB concentrator #" .. strategy .. " inc_sync=" .. inc_sync, function() + describe("Hybrid Mode RPC over DB concentrator #" .. strategy, function() lazy_setup(function() helpers.get_db_utils(strategy, { @@ -47,7 +46,7 @@ for _, strategy in helpers.each_strategy() do admin_listen = "127.0.0.1:" .. helpers.get_available_port(), nginx_conf = "spec/fixtures/custom_nginx.template", cluster_rpc = "on", - cluster_incremental_sync = inc_sync, -- incremental sync + cluster_incremental_sync = "off", })) assert(helpers.start_kong({ @@ -59,6 +58,7 @@ for _, strategy in helpers.each_strategy() do cluster_listen = "127.0.0.1:" .. helpers.get_available_port(), nginx_conf = "spec/fixtures/custom_nginx.template", cluster_rpc = "on", + plugins = "bundled,rpc-framework-test", cluster_incremental_sync = inc_sync, -- incremental sync })) @@ -72,7 +72,8 @@ for _, strategy in helpers.each_strategy() do proxy_listen = "0.0.0.0:9002", nginx_conf = "spec/fixtures/custom_nginx.template", cluster_rpc = "on", - cluster_incremental_sync = inc_sync, -- incremental sync + plugins = "bundled,rpc-framework-test", + cluster_incremental_sync = "off", })) end) @@ -87,4 +88,3 @@ for _, strategy in helpers.each_strategy() do --end) end) end -- for _, strategy -end -- for inc_sync From d556540d7a5d3ad6e0e5346d9a9a476c4c19bbbc Mon Sep 17 00:00:00 2001 From: chronolaw Date: Sun, 1 Dec 2024 13:14:46 +0800 Subject: [PATCH 3/8] fix --- spec/02-integration/18-hybrid_rpc/01-rpc_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/02-integration/18-hybrid_rpc/01-rpc_spec.lua b/spec/02-integration/18-hybrid_rpc/01-rpc_spec.lua index f18c317836c7..8f2536458e73 100644 --- a/spec/02-integration/18-hybrid_rpc/01-rpc_spec.lua +++ b/spec/02-integration/18-hybrid_rpc/01-rpc_spec.lua @@ -34,7 +34,7 @@ for _, strategy in helpers.each_strategy() do nginx_conf = "spec/fixtures/custom_nginx.template", cluster_rpc = "on", plugins = "bundled,rpc-framework-test", - cluster_incremental_sync = inc_sync, -- incremental sync + cluster_incremental_sync = "off", })) end) From 18f7664b936fae61193189c8fb22b67034e7ea1d Mon Sep 17 00:00:00 2001 From: chronolaw Date: Sun, 1 Dec 2024 13:17:27 +0800 Subject: [PATCH 4/8] fix --- spec/02-integration/18-hybrid_rpc/04-concentrator_spec.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/02-integration/18-hybrid_rpc/04-concentrator_spec.lua b/spec/02-integration/18-hybrid_rpc/04-concentrator_spec.lua index 0631c688ea92..b998641bf99d 100644 --- a/spec/02-integration/18-hybrid_rpc/04-concentrator_spec.lua +++ b/spec/02-integration/18-hybrid_rpc/04-concentrator_spec.lua @@ -46,6 +46,7 @@ for _, strategy in helpers.each_strategy() do admin_listen = "127.0.0.1:" .. helpers.get_available_port(), nginx_conf = "spec/fixtures/custom_nginx.template", cluster_rpc = "on", + plugins = "bundled,rpc-framework-test", cluster_incremental_sync = "off", })) @@ -59,7 +60,7 @@ for _, strategy in helpers.each_strategy() do nginx_conf = "spec/fixtures/custom_nginx.template", cluster_rpc = "on", plugins = "bundled,rpc-framework-test", - cluster_incremental_sync = inc_sync, -- incremental sync + cluster_incremental_sync = "off", })) assert(helpers.start_kong({ From b16b2f9a5a32a0d6cc1db49cad7776c402e2f4ac Mon Sep 17 00:00:00 2001 From: chronolaw Date: Sun, 1 Dec 2024 13:33:35 +0800 Subject: [PATCH 5/8] try to fix concentrator --- spec/02-integration/18-hybrid_rpc/01-rpc_spec.lua | 2 ++ .../18-hybrid_rpc/04-concentrator_spec.lua | 6 ++++-- .../kong/plugins/rpc-framework-test/handler.lua | 11 +++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/spec/02-integration/18-hybrid_rpc/01-rpc_spec.lua b/spec/02-integration/18-hybrid_rpc/01-rpc_spec.lua index 8f2536458e73..c8535b6dedda 100644 --- a/spec/02-integration/18-hybrid_rpc/01-rpc_spec.lua +++ b/spec/02-integration/18-hybrid_rpc/01-rpc_spec.lua @@ -80,6 +80,8 @@ for _, strategy in helpers.each_strategy() do end end end, 10) + + --ngx.sleep(0.5) end) end) end) diff --git a/spec/02-integration/18-hybrid_rpc/04-concentrator_spec.lua b/spec/02-integration/18-hybrid_rpc/04-concentrator_spec.lua index b998641bf99d..289e265869c0 100644 --- a/spec/02-integration/18-hybrid_rpc/04-concentrator_spec.lua +++ b/spec/02-integration/18-hybrid_rpc/04-concentrator_spec.lua @@ -85,7 +85,9 @@ for _, strategy in helpers.each_strategy() do end) -- TODO: test with other rpc - --describe("XXX over RPC", function() - --end) + describe("hell greeting over RPC", function() + it("can get the message", function() + end) + end) end) end -- for _, strategy diff --git a/spec/fixtures/custom_plugins/kong/plugins/rpc-framework-test/handler.lua b/spec/fixtures/custom_plugins/kong/plugins/rpc-framework-test/handler.lua index a54eb406d547..994fd2bb2654 100644 --- a/spec/fixtures/custom_plugins/kong/plugins/rpc-framework-test/handler.lua +++ b/spec/fixtures/custom_plugins/kong/plugins/rpc-framework-test/handler.lua @@ -8,6 +8,17 @@ function RpcFrameworkTestHandler:init_worker() kong.rpc.callbacks:register("kong.test.hello", function(node_id, greeting) return "hello ".. greeting end) + + -- wait 0.2s for rpc established + --[[ + ngx.timer.at(0.2, function() + local res, err = kong.rpc:call("kong.test.hello", "world") + ngx.log(ngx.ERR, "xxx res = ", res) + ngx.log(ngx.ERR, "xxx err = ", err) + --assert(res and not err) + --assert(res == "hello world") + end) + --]] end From 087303864b1a53e15acb46c6fcc3be79de8cd697 Mon Sep 17 00:00:00 2001 From: chronolaw Date: Sun, 1 Dec 2024 18:55:51 +0800 Subject: [PATCH 6/8] Revert "try to fix concentrator" This reverts commit b16b2f9a5a32a0d6cc1db49cad7776c402e2f4ac. --- spec/02-integration/18-hybrid_rpc/01-rpc_spec.lua | 2 -- .../18-hybrid_rpc/04-concentrator_spec.lua | 6 ++---- .../kong/plugins/rpc-framework-test/handler.lua | 11 ----------- 3 files changed, 2 insertions(+), 17 deletions(-) diff --git a/spec/02-integration/18-hybrid_rpc/01-rpc_spec.lua b/spec/02-integration/18-hybrid_rpc/01-rpc_spec.lua index c8535b6dedda..8f2536458e73 100644 --- a/spec/02-integration/18-hybrid_rpc/01-rpc_spec.lua +++ b/spec/02-integration/18-hybrid_rpc/01-rpc_spec.lua @@ -80,8 +80,6 @@ for _, strategy in helpers.each_strategy() do end end end, 10) - - --ngx.sleep(0.5) end) end) end) diff --git a/spec/02-integration/18-hybrid_rpc/04-concentrator_spec.lua b/spec/02-integration/18-hybrid_rpc/04-concentrator_spec.lua index 289e265869c0..b998641bf99d 100644 --- a/spec/02-integration/18-hybrid_rpc/04-concentrator_spec.lua +++ b/spec/02-integration/18-hybrid_rpc/04-concentrator_spec.lua @@ -85,9 +85,7 @@ for _, strategy in helpers.each_strategy() do end) -- TODO: test with other rpc - describe("hell greeting over RPC", function() - it("can get the message", function() - end) - end) + --describe("XXX over RPC", function() + --end) end) end -- for _, strategy diff --git a/spec/fixtures/custom_plugins/kong/plugins/rpc-framework-test/handler.lua b/spec/fixtures/custom_plugins/kong/plugins/rpc-framework-test/handler.lua index 994fd2bb2654..a54eb406d547 100644 --- a/spec/fixtures/custom_plugins/kong/plugins/rpc-framework-test/handler.lua +++ b/spec/fixtures/custom_plugins/kong/plugins/rpc-framework-test/handler.lua @@ -8,17 +8,6 @@ function RpcFrameworkTestHandler:init_worker() kong.rpc.callbacks:register("kong.test.hello", function(node_id, greeting) return "hello ".. greeting end) - - -- wait 0.2s for rpc established - --[[ - ngx.timer.at(0.2, function() - local res, err = kong.rpc:call("kong.test.hello", "world") - ngx.log(ngx.ERR, "xxx res = ", res) - ngx.log(ngx.ERR, "xxx err = ", err) - --assert(res and not err) - --assert(res == "hello world") - end) - --]] end From 85bfcf8d6fe3ef656913c1660a2aa1fe7c25ff78 Mon Sep 17 00:00:00 2001 From: chronolaw Date: Sun, 1 Dec 2024 18:58:03 +0800 Subject: [PATCH 7/8] rename --- spec/02-integration/18-hybrid_rpc/01-rpc_spec.lua | 6 +++--- .../{rpc-framework-test => rpc-hello-test}/handler.lua | 6 +++--- .../{rpc-framework-test => rpc-hello-test}/schema.lua | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) rename spec/fixtures/custom_plugins/kong/plugins/{rpc-framework-test => rpc-hello-test}/handler.lua (59%) rename spec/fixtures/custom_plugins/kong/plugins/{rpc-framework-test => rpc-hello-test}/schema.lua (79%) diff --git a/spec/02-integration/18-hybrid_rpc/01-rpc_spec.lua b/spec/02-integration/18-hybrid_rpc/01-rpc_spec.lua index 8f2536458e73..8f670a0388e1 100644 --- a/spec/02-integration/18-hybrid_rpc/01-rpc_spec.lua +++ b/spec/02-integration/18-hybrid_rpc/01-rpc_spec.lua @@ -2,7 +2,7 @@ local helpers = require "spec.helpers" local cjson = require("cjson.safe") local CLUSTERING_SYNC_STATUS = require("kong.constants").CLUSTERING_SYNC_STATUS --- register a test rpc service in custom plugin rpc-framework-test +-- register a test rpc service in custom plugin rpc-hello-test for _, strategy in helpers.each_strategy() do describe("Hybrid Mode RPC #" .. strategy, function() @@ -19,7 +19,7 @@ for _, strategy in helpers.each_strategy() do cluster_listen = "127.0.0.1:9005", nginx_conf = "spec/fixtures/custom_nginx.template", cluster_rpc = "on", - plugins = "bundled,rpc-framework-test", + plugins = "bundled,rpc-hello-test", cluster_incremental_sync = "off", })) @@ -33,7 +33,7 @@ for _, strategy in helpers.each_strategy() do proxy_listen = "0.0.0.0:9002", nginx_conf = "spec/fixtures/custom_nginx.template", cluster_rpc = "on", - plugins = "bundled,rpc-framework-test", + plugins = "bundled,rpc-hello-test", cluster_incremental_sync = "off", })) end) diff --git a/spec/fixtures/custom_plugins/kong/plugins/rpc-framework-test/handler.lua b/spec/fixtures/custom_plugins/kong/plugins/rpc-hello-test/handler.lua similarity index 59% rename from spec/fixtures/custom_plugins/kong/plugins/rpc-framework-test/handler.lua rename to spec/fixtures/custom_plugins/kong/plugins/rpc-hello-test/handler.lua index a54eb406d547..7ef7af7a4da4 100644 --- a/spec/fixtures/custom_plugins/kong/plugins/rpc-framework-test/handler.lua +++ b/spec/fixtures/custom_plugins/kong/plugins/rpc-hello-test/handler.lua @@ -1,14 +1,14 @@ -local RpcFrameworkTestHandler = { +local RpcHelloTestHandler = { VERSION = "1.0", PRIORITY = 1000, } -function RpcFrameworkTestHandler:init_worker() +function RpcHelloTestHandler:init_worker() kong.rpc.callbacks:register("kong.test.hello", function(node_id, greeting) return "hello ".. greeting end) end -return RpcFrameworkTestHandler +return RpcHelloTestHandler diff --git a/spec/fixtures/custom_plugins/kong/plugins/rpc-framework-test/schema.lua b/spec/fixtures/custom_plugins/kong/plugins/rpc-hello-test/schema.lua similarity index 79% rename from spec/fixtures/custom_plugins/kong/plugins/rpc-framework-test/schema.lua rename to spec/fixtures/custom_plugins/kong/plugins/rpc-hello-test/schema.lua index ab028ed7eda8..a11e24948267 100644 --- a/spec/fixtures/custom_plugins/kong/plugins/rpc-framework-test/schema.lua +++ b/spec/fixtures/custom_plugins/kong/plugins/rpc-hello-test/schema.lua @@ -1,5 +1,5 @@ return { - name = "rpc-framework-test", + name = "rpc-hello-test", fields = { { config = { From c5502e8738712e9a46b76d546fae97f903574d90 Mon Sep 17 00:00:00 2001 From: chronolaw Date: Sun, 1 Dec 2024 18:59:16 +0800 Subject: [PATCH 8/8] fix --- .../02-integration/18-hybrid_rpc/04-concentrator_spec.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/02-integration/18-hybrid_rpc/04-concentrator_spec.lua b/spec/02-integration/18-hybrid_rpc/04-concentrator_spec.lua index b998641bf99d..445bcee6ec12 100644 --- a/spec/02-integration/18-hybrid_rpc/04-concentrator_spec.lua +++ b/spec/02-integration/18-hybrid_rpc/04-concentrator_spec.lua @@ -28,7 +28,7 @@ local function obtain_dp_node_id() -- luacheck: ignore end --- register a test rpc service in custom plugin rpc-framework-test +-- register a test rpc service in custom plugin rpc-hello-test for _, strategy in helpers.each_strategy() do describe("Hybrid Mode RPC over DB concentrator #" .. strategy, function() @@ -46,7 +46,7 @@ for _, strategy in helpers.each_strategy() do admin_listen = "127.0.0.1:" .. helpers.get_available_port(), nginx_conf = "spec/fixtures/custom_nginx.template", cluster_rpc = "on", - plugins = "bundled,rpc-framework-test", + plugins = "bundled,rpc-hello-test", cluster_incremental_sync = "off", })) @@ -59,7 +59,7 @@ for _, strategy in helpers.each_strategy() do cluster_listen = "127.0.0.1:" .. helpers.get_available_port(), nginx_conf = "spec/fixtures/custom_nginx.template", cluster_rpc = "on", - plugins = "bundled,rpc-framework-test", + plugins = "bundled,rpc-hello-test", cluster_incremental_sync = "off", })) @@ -73,7 +73,7 @@ for _, strategy in helpers.each_strategy() do proxy_listen = "0.0.0.0:9002", nginx_conf = "spec/fixtures/custom_nginx.template", cluster_rpc = "on", - plugins = "bundled,rpc-framework-test", + plugins = "bundled,rpc-hello-test", cluster_incremental_sync = "off", })) end)