Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(plugins): load wasm filter plugins before external plugins #13931

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions kong/db/dao/plugins.lua
Original file line number Diff line number Diff line change
Expand Up @@ -162,16 +162,16 @@ local load_plugin_handler do
local plugin_handler = "kong.plugins." .. plugin .. ".handler"
local ok, handler = load_module_if_exists(plugin_handler)
if not ok then
ok, handler = plugin_servers.load_plugin(plugin)
ok, handler = wasm_plugins.load_plugin(plugin)
if type(handler) == "table" then
handler._go = true
handler._wasm = true
end
end

if not ok then
ok, handler = wasm_plugins.load_plugin(plugin)
ok, handler = plugin_servers.load_plugin(plugin)
if type(handler) == "table" then
handler._wasm = true
handler._go = true
end
end

Expand Down
4 changes: 2 additions & 2 deletions kong/db/schema/plugin_loader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ function plugin_loader.load_subschema(parent_schema, plugin, errors)
local plugin_schema = "kong.plugins." .. plugin .. ".schema"
local ok, schema = load_module_if_exists(plugin_schema)
if not ok then
ok, schema = plugin_servers.load_schema(plugin)
ok, schema = wasm_plugins.load_schema(plugin)
end
if not ok then
ok, schema = wasm_plugins.load_schema(plugin)
ok, schema = plugin_servers.load_schema(plugin)
end

if not ok then
Expand Down
96 changes: 96 additions & 0 deletions spec/02-integration/10-external-plugins/03-wasm_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
local helpers = require "spec.helpers"

for _, strategy in helpers.each_strategy() do

describe("external plugins and wasm #" .. strategy, function()
describe("wasm enabled in conjunction with unused pluginservers", function()
it("does not prevent kong from starting", function()
require("kong.runloop.wasm").enable({
{ name = "tests",
path = helpers.test_conf.wasm_filters_path .. "/tests.wasm",
},
})

local bp = assert(helpers.get_db_utils(strategy, {
"services",
"routes",
"plugins",
"filter_chains",
}, { "response-transformer", "tests" }))

local route = assert(bp.routes:insert({
protocols = { "http" },
paths = { "/" },
service = assert(bp.services:insert({})),
}))

-- configure a wasm filter plugin
assert(bp.plugins:insert({
name = "tests",
route = route,
config = "",
}))

-- configure a lua plugin
assert(bp.plugins:insert({
name = "response-transformer",
route = route,
config = {
add = {
headers = {
"X-Lua-Plugin:hello from response-transformer",
},
},
},
}))

assert(helpers.start_kong({
nginx_conf = "spec/fixtures/custom_nginx.template",
database = strategy,

wasm = true,
wasm_filters = "tests",

plugins = "response-transformer",

-- this pluginserver does not exist, but we will validate that kong can
-- start so long as there are no configured/enabled plugins that will
-- require us to invoke it in any way
--
-- XXX: this configuration could be considered invalid, and future changes
-- to plugin resolution/pluginserver code MAY opt to change this behavior
pluginserver_names = "not-exists",
pluginserver_not_exists_start_cmd = "/i/do/not/exist",
pluginserver_not_exists_query_cmd = "/i/do/not/exist",
}))

local client

finally(function()
if client then
client:close()
end

helpers.stop_kong()
end)

client = helpers.proxy_client()
local res = client:get("/", {
headers = {
["X-PW-Test"] = "local_response",
["X-PW-Input"] = "hello from wasm",
},
})

-- verify that our wasm filter ran
local body = assert.res_status(200, res)
assert.equals("hello from wasm", body)

-- verify that our lua plugin (response-transformer) ran
local header = assert.response(res).has.header("X-Lua-Plugin")
assert.equals("hello from response-transformer", header)
end)
end)
end)

end -- each strategy
Loading