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

refactor(pluginservers): code refactor & testing #12858

Merged
merged 1 commit into from
Nov 13, 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
2 changes: 2 additions & 0 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,8 @@ jobs:
- name: Build & install dependencies
run: |
make dev
# python pluginserver tests dependency
pip install kong-pdk
flrgh marked this conversation as resolved.
Show resolved Hide resolved

- name: Download test rerun information
uses: actions/download-artifact@v4
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@ spec/fixtures/proxy_wasm_filters/target
bazel-*
# remove it after migrating from WORKSPACE to Bzlmod
MODULE.bazel.lock
spec/fixtures/external_plugins/go/go-hello
7 changes: 5 additions & 2 deletions kong-3.9.0-0.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,11 @@ build = {
["kong.runloop.balancer.upstreams"] = "kong/runloop/balancer/upstreams.lua",
["kong.runloop.plugin_servers"] = "kong/runloop/plugin_servers/init.lua",
["kong.runloop.plugin_servers.process"] = "kong/runloop/plugin_servers/process.lua",
["kong.runloop.plugin_servers.mp_rpc"] = "kong/runloop/plugin_servers/mp_rpc.lua",
["kong.runloop.plugin_servers.pb_rpc"] = "kong/runloop/plugin_servers/pb_rpc.lua",
["kong.runloop.plugin_servers.plugin"] = "kong/runloop/plugin_servers/plugin.lua",
["kong.runloop.plugin_servers.rpc"] = "kong/runloop/plugin_servers/rpc/init.lua",
["kong.runloop.plugin_servers.rpc.util"] = "kong/runloop/plugin_servers/rpc/util.lua",
["kong.runloop.plugin_servers.rpc.mp_rpc"] = "kong/runloop/plugin_servers/rpc/mp_rpc.lua",
["kong.runloop.plugin_servers.rpc.pb_rpc"] = "kong/runloop/plugin_servers/rpc/pb_rpc.lua",
["kong.runloop.wasm"] = "kong/runloop/wasm.lua",
["kong.runloop.wasm.properties"] = "kong/runloop/wasm/properties.lua",

Expand Down
9 changes: 6 additions & 3 deletions kong.conf.default
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,17 @@

#pluginserver_XXX_socket = <prefix>/<XXX>.socket # Path to the unix socket
# used by the <XXX> pluginserver.

#pluginserver_XXX_start_cmd = /usr/local/bin/<XXX> # Full command (including
# any needed arguments) to
# start the <XXX> pluginserver
# start the <XXX>
# pluginserver.

#pluginserver_XXX_query_cmd = /usr/local/bin/query_<XXX> # Full command to "query" the
# <XXX> pluginserver. Should
# produce a JSON with the
# dump info of all plugins it
gszr marked this conversation as resolved.
Show resolved Hide resolved
# manages
# dump info of the plugin it
# manages.

#port_maps = # With this configuration parameter, you can
# let Kong Gateway know the port from
Expand Down
4 changes: 4 additions & 0 deletions kong/conf_loader/constants.lua
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ local DEFAULT_PATHS = {
}


local DEFAULT_PLUGINSERVER_PATH = "/usr/local/bin"


local HEADER_KEY_TO_NAME = {
["server_tokens"] = "server_tokens",
["latency_tokens"] = "latency_tokens",
Expand Down Expand Up @@ -642,6 +645,7 @@ return {

CIPHER_SUITES = CIPHER_SUITES,
DEFAULT_PATHS = DEFAULT_PATHS,
DEFAULT_PLUGINSERVER_PATH = DEFAULT_PLUGINSERVER_PATH,
HEADER_KEY_TO_NAME = HEADER_KEY_TO_NAME,
UPSTREAM_HEADER_KEY_TO_NAME = UPSTREAM_HEADER_KEY_TO_NAME,
DYNAMIC_KEY_NAMESPACES = DYNAMIC_KEY_NAMESPACES,
Expand Down
43 changes: 43 additions & 0 deletions kong/conf_loader/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,49 @@ local function load(path, custom_conf, opts)
conf.cluster_rpc = "off"
end

-- parse and validate pluginserver directives
if conf.pluginserver_names then
local pluginservers = {}
for i, name in ipairs(conf.pluginserver_names) do
name = name:lower()
local env_prefix = "pluginserver_" .. name:gsub("-", "_")
local socket = conf[env_prefix .. "_socket"] or (conf.prefix .. "/" .. name .. ".socket")

local start_command = conf[env_prefix .. "_start_cmd"]
local query_command = conf[env_prefix .. "_query_cmd"]

local default_path = exists(conf_constants.DEFAULT_PLUGINSERVER_PATH .. "/" .. name)

if not start_command and default_path then
start_command = default_path
end

if not query_command and default_path then
query_command = default_path .. " -dump"
end

-- query_command is required
if not query_command then
return nil, "query_command undefined for pluginserver " .. name
end

-- if start_command is unset, we assume the pluginserver process is
-- managed externally
if not start_command then
log.warn("start_command undefined for pluginserver " .. name .. "; assuming external process management")
end

pluginservers[i] = {
name = name,
socket = socket,
start_command = start_command,
query_command = query_command,
}
end

conf.pluginservers = setmetatable(pluginservers, conf_constants._NOP_TOSTRING_MT)
end

-- initialize the dns client, so the globally patched tcp.connect method
-- will work from here onwards.
assert(require("kong.tools.dns")(conf))
Expand Down
Loading
Loading