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

chore(lib) re-scope the FFI binding to 'resty.wasmx' #359

Merged
merged 1 commit into from
Jul 24, 2023
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
6 changes: 3 additions & 3 deletions docs/adr/003-proxy-wasm-gateway-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ workflow when I wish to configure proxy-wasm filters on a Service:"

### Implementation Steps

1. ngx_wasm_module: Implement the lua-resty-wasm FFI wrapper library.
1. ngx_wasm_module: Implement the lua-resty-wasmx FFI wrapper library.
2. Gateway: compile with ngx_wasm_module.
3. Gateway: add proxy-wasm configuration properties and auto-generate `wasm{}`
section in the Nginx configuration template.
4. Gateway: implement a Lua plugin leveraging lua-resty-wasm to enter the filter
chain during a request.
4. Gateway: implement a Lua plugin leveraging lua-resty-wasmx to enter the
filter chain during a request.
- declaratively-configured proxy-wasm chains must be created from within
`init_worker` when available (e.g. background ticks).
5. Test cases, behavior checks, edge-cases and bug squashing.
Expand Down
File renamed without changes.
16 changes: 8 additions & 8 deletions lib/resty/http/proxy_wasm.lua → lib/resty/wasmx/proxy_wasm.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-- vim:set ts=4 sw=4 sts=4 et:

local ffi = require "ffi"
local wasm = require "resty.wasm"
local wasmx = require "resty.wasmx"


local C = ffi.C
Expand All @@ -11,12 +11,12 @@ local type = type
local ffi_gc = ffi.gc
local ffi_new = ffi.new
local ffi_str = ffi.string
local get_request = wasm.get_request
local get_err_ptr = wasm.get_err_ptr
local FFI_OK = wasm.FFI_OK
local FFI_ERROR = wasm.FFI_ERROR
local FFI_ABORT = wasm.FFI_ABORT
local FFI_DECLINED = wasm.FFI_DECLINED
local get_request = wasmx.get_request
local get_err_ptr = wasmx.get_err_ptr
local FFI_OK = wasmx.FFI_OK
local FFI_ERROR = wasmx.FFI_ERROR
local FFI_ABORT = wasmx.FFI_ABORT
local FFI_DECLINED = wasmx.FFI_DECLINED
local NOT_FOUND = "missing"
local ERROR = "error"

Expand Down Expand Up @@ -65,7 +65,7 @@ function _M.new(filters)
error("filters must be a table", 2)
end

local vm = wasm.get_main_vm()
local vm = wasmx.get_main_vm()
if vm == nil then
error("no wasm vm", 2)
end
Expand Down
8 changes: 4 additions & 4 deletions t/04-openresty/ffi/001-get_main_vm.t
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ __DATA__
--- config
location /t {
content_by_lua_block {
local wasm = require "resty.wasm"
local vm = wasm.get_main_vm()
local wasmx = require "resty.wasmx"
local vm = wasmx.get_main_vm()

ngx.say("vm: ", tostring(vm))
}
Expand All @@ -36,8 +36,8 @@ vm: cdata<struct ngx_wavm_t *>: NULL
--- config
location /t {
content_by_lua_block {
local wasm = require "resty.wasm"
local vm = wasm.get_main_vm()
local wasmx = require "resty.wasmx"
local vm = wasmx.get_main_vm()

ngx.say("vm: ", tostring(vm))
}
Expand Down
10 changes: 5 additions & 5 deletions t/04-openresty/ffi/100-proxy_wasm_new.t
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ __DATA__
=== TEST 1: new() - no VM
--- http_config
init_by_lua_block {
local proxy_wasm = require "resty.http.proxy_wasm"
local proxy_wasm = require "resty.wasmx.proxy_wasm"
proxy_wasm.new({})
}
--- error_log
Expand All @@ -32,7 +32,7 @@ no wasm vm
=== TEST 2: new() - bad argument
--- http_config
init_by_lua_block {
local proxy_wasm = require "resty.http.proxy_wasm"
local proxy_wasm = require "resty.wasmx.proxy_wasm"
proxy_wasm.new()
}
--- error_log
Expand All @@ -48,7 +48,7 @@ filters must be a table
--- wasm_modules: on_phases
--- http_config
init_worker_by_lua_block {
local proxy_wasm = require "resty.http.proxy_wasm"
local proxy_wasm = require "resty.wasmx.proxy_wasm"
local filters = {
{ name = "on_tick" },
}
Expand All @@ -72,7 +72,7 @@ qr/\[error\] .*? no "on_tick" module defined/
--- config
location /t {
access_by_lua_block {
local proxy_wasm = require "resty.http.proxy_wasm"
local proxy_wasm = require "resty.wasmx.proxy_wasm"
local filters = {
{ name = "on_phases", config = "a" },
{ name = "hostcalls", config = "b" },
Expand Down Expand Up @@ -101,7 +101,7 @@ plan: cdata<struct ngx_wasm_ops_plan_t \*>: 0x[0-9a-f]+
--- config
location /t {
access_by_lua_block {
local proxy_wasm = require "resty.http.proxy_wasm"
local proxy_wasm = require "resty.wasmx.proxy_wasm"
local filters = {
{ name = "on_phases", config = "a" },
{ name = "hostcalls", config = "b" },
Expand Down
10 changes: 5 additions & 5 deletions t/04-openresty/ffi/101-proxy_wasm_load.t
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ __DATA__
=== TEST 1: load() - bad argument
--- http_config
init_by_lua_block {
local proxy_wasm = require "resty.http.proxy_wasm"
local proxy_wasm = require "resty.wasmx.proxy_wasm"
proxy_wasm.load({})
}
--- error_log eval
Expand All @@ -31,7 +31,7 @@ qr/\[error\] .*? plan should be a cdata object/
--- wasm_modules: ngx_rust_tests
--- http_config
init_worker_by_lua_block {
local proxy_wasm = require "resty.http.proxy_wasm"
local proxy_wasm = require "resty.wasmx.proxy_wasm"
local filters = {
{ name = "ngx_rust_tests" },
}
Expand Down Expand Up @@ -68,7 +68,7 @@ the wasm{} block postconfig handler. It feels unnecessary at the moment.
--- wasm_modules: on_tick
--- http_config
init_by_lua_block {
local proxy_wasm = require "resty.http.proxy_wasm"
local proxy_wasm = require "resty.wasmx.proxy_wasm"
local filters = {
{ name = "on_tick" },
}
Expand All @@ -89,7 +89,7 @@ qr/\[error\] .*? load cannot be called from 'init' phase/
--- wasm_modules: on_phases
--- http_config
init_worker_by_lua_block {
local proxy_wasm = require "resty.http.proxy_wasm"
local proxy_wasm = require "resty.wasmx.proxy_wasm"
local filters = {
{ name = "on_phases" },
}
Expand Down Expand Up @@ -119,7 +119,7 @@ qr/#0 on_configure, config_size: 0.*/
--- wasm_modules: on_tick
--- http_config
init_worker_by_lua_block {
local proxy_wasm = require "resty.http.proxy_wasm"
local proxy_wasm = require "resty.wasmx.proxy_wasm"
local filters = {
{ name = "on_tick" },
}
Expand Down
12 changes: 6 additions & 6 deletions t/04-openresty/ffi/102-proxy_wasm_start.t
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ __DATA__
--- config
location /t {
rewrite_by_lua_block {
local proxy_wasm = require "resty.http.proxy_wasm"
local proxy_wasm = require "resty.wasmx.proxy_wasm"

local ok, err = proxy_wasm.start()
if not ok then
Expand All @@ -41,7 +41,7 @@ plan not loaded and attached
--- config
location /t {
rewrite_by_lua_block {
local proxy_wasm = require "resty.http.proxy_wasm"
local proxy_wasm = require "resty.wasmx.proxy_wasm"
local filters = {
{ name = "on_phases" },
}
Expand Down Expand Up @@ -73,7 +73,7 @@ plan not loaded and attached
--- config
location /t {
rewrite_by_lua_block {
local proxy_wasm = require "resty.http.proxy_wasm"
local proxy_wasm = require "resty.wasmx.proxy_wasm"
local filters = {
{ name = "on_phases" },
}
Expand Down Expand Up @@ -110,7 +110,7 @@ plan not loaded and attached
--- config
location /t {
rewrite_by_lua_block {
local proxy_wasm = require "resty.http.proxy_wasm"
local proxy_wasm = require "resty.wasmx.proxy_wasm"
local filters = {
{ name = "on_phases" },
}
Expand Down Expand Up @@ -164,7 +164,7 @@ qr/^#0 on_vm_start[^#]*
--- config
location /t {
access_by_lua_block {
local proxy_wasm = require "resty.http.proxy_wasm"
local proxy_wasm = require "resty.wasmx.proxy_wasm"
local filters = {
{ name = "on_phases" },
}
Expand Down Expand Up @@ -217,7 +217,7 @@ qr/^#0 on_vm_start[^#]*
--- wasm_modules: on_phases
--- http_config
init_worker_by_lua_block {
local proxy_wasm = require "resty.http.proxy_wasm"
local proxy_wasm = require "resty.wasmx.proxy_wasm"

assert(proxy_wasm.start())
}
Expand Down
40 changes: 20 additions & 20 deletions t/04-openresty/ffi/103-proxy_wasm_attach.t
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ __DATA__
--- config
location /t {
rewrite_by_lua_block {
local proxy_wasm = require "resty.http.proxy_wasm"
local proxy_wasm = require "resty.wasmx.proxy_wasm"

local pok, perr = pcall(proxy_wasm.attach, {})
if not pok then
Expand All @@ -40,7 +40,7 @@ plan must be a cdata object
--- config
location /t {
rewrite_by_lua_block {
local proxy_wasm = require "resty.http.proxy_wasm"
local proxy_wasm = require "resty.wasmx.proxy_wasm"
local filters = {
{ name = "on_phases" },
}
Expand Down Expand Up @@ -72,7 +72,7 @@ plan not loaded
--- config
location /t {
rewrite_by_lua_block {
local proxy_wasm = require "resty.http.proxy_wasm"
local proxy_wasm = require "resty.wasmx.proxy_wasm"
local filters = {
{ name = "on_phases" },
}
Expand Down Expand Up @@ -117,7 +117,7 @@ qr/\[error\] .*? previous plan already attached/
--- config
location /t {
rewrite_by_lua_block {
local proxy_wasm = require "resty.http.proxy_wasm"
local proxy_wasm = require "resty.wasmx.proxy_wasm"
local filters = {
{ name = "on_phases" },
}
Expand Down Expand Up @@ -167,7 +167,7 @@ qr/^[^#]*#0 on_vm_start[^#]*
--- wasm_modules: on_phases
--- http_config
init_worker_by_lua_block {
local proxy_wasm = require "resty.http.proxy_wasm"
local proxy_wasm = require "resty.wasmx.proxy_wasm"
local filters = {
{ name = "on_phases" },
}
Expand All @@ -180,7 +180,7 @@ qr/^[^#]*#0 on_vm_start[^#]*
--- config
location /t {
rewrite_by_lua_block {
local proxy_wasm = require "resty.http.proxy_wasm"
local proxy_wasm = require "resty.wasmx.proxy_wasm"
local c_plan = _G.c_plan

local ok, err = proxy_wasm.attach(c_plan)
Expand Down Expand Up @@ -218,7 +218,7 @@ qr/^[^#]*#0 on_vm_start[^#]*
--- wasm_modules: on_phases
--- http_config
init_worker_by_lua_block {
local proxy_wasm = require "resty.http.proxy_wasm"
local proxy_wasm = require "resty.wasmx.proxy_wasm"
local filters = {
{ name = "on_phases" },
}
Expand All @@ -231,7 +231,7 @@ qr/^[^#]*#0 on_vm_start[^#]*
--- config
location /t {
access_by_lua_block {
local proxy_wasm = require "resty.http.proxy_wasm"
local proxy_wasm = require "resty.wasmx.proxy_wasm"
local c_plan = _G.c_plan

local ok, err = proxy_wasm.attach(c_plan)
Expand Down Expand Up @@ -269,7 +269,7 @@ qr/^[^#]*#0 on_vm_start[^#]*
--- wasm_modules: hostcalls
--- http_config
init_worker_by_lua_block {
local proxy_wasm = require "resty.http.proxy_wasm"
local proxy_wasm = require "resty.wasmx.proxy_wasm"
local filters = {
{ name = "hostcalls", config = "test=/t/trap" },
}
Expand All @@ -282,7 +282,7 @@ qr/^[^#]*#0 on_vm_start[^#]*
--- config
location /t {
rewrite_by_lua_block {
local proxy_wasm = require "resty.http.proxy_wasm"
local proxy_wasm = require "resty.wasmx.proxy_wasm"
local c_plan = _G.c_plan

local ok, err = proxy_wasm.attach(c_plan)
Expand Down Expand Up @@ -315,7 +315,7 @@ qr/^[^#]*#0 on_vm_start[^#]*
--- config
location /t {
rewrite_by_lua_block {
local proxy_wasm = require "resty.http.proxy_wasm"
local proxy_wasm = require "resty.wasmx.proxy_wasm"
local filters = {
{ name = "on_phases" },
}
Expand All @@ -342,7 +342,7 @@ qr/\[debug\] .*? wasm freeing plan/
--- wasm_modules: on_phases
--- http_config
init_worker_by_lua_block {
local proxy_wasm = require "resty.http.proxy_wasm"
local proxy_wasm = require "resty.wasmx.proxy_wasm"
local filters = {
{ name = "on_phases" },
}
Expand Down Expand Up @@ -372,7 +372,7 @@ qr/attach must be called from 'rewrite' or 'access' phase/
--- config
location /t {
rewrite_by_lua_block {
local proxy_wasm = require "resty.http.proxy_wasm"
local proxy_wasm = require "resty.wasmx.proxy_wasm"
local filters = {
{ name = "on_phases" },
}
Expand All @@ -399,7 +399,7 @@ opts must be a table
--- config
location /t {
rewrite_by_lua_block {
local proxy_wasm = require "resty.http.proxy_wasm"
local proxy_wasm = require "resty.wasmx.proxy_wasm"
local filters = {
{ name = "on_phases" },
}
Expand Down Expand Up @@ -427,7 +427,7 @@ bad opts.isolation value: -1
--- wasm_modules: hostcalls
--- http_config
init_worker_by_lua_block {
local proxy_wasm = require "resty.http.proxy_wasm"
local proxy_wasm = require "resty.wasmx.proxy_wasm"
local filters = {
{ name = "hostcalls" },
}
Expand All @@ -440,7 +440,7 @@ bad opts.isolation value: -1
--- config
location /t {
rewrite_by_lua_block {
local proxy_wasm = require "resty.http.proxy_wasm"
local proxy_wasm = require "resty.wasmx.proxy_wasm"
assert(proxy_wasm.attach(_G.c_plan))
assert(proxy_wasm.start())
ngx.say("ok")
Expand Down Expand Up @@ -482,7 +482,7 @@ qr/\A\*\d+ proxy_wasm initializing filter chain \(nfilters: 1, isolation: 1\)[^#
--- wasm_modules: hostcalls
--- http_config
init_worker_by_lua_block {
local proxy_wasm = require "resty.http.proxy_wasm"
local proxy_wasm = require "resty.wasmx.proxy_wasm"
local filters = {
{ name = "hostcalls" },
}
Expand All @@ -497,7 +497,7 @@ qr/\A\*\d+ proxy_wasm initializing filter chain \(nfilters: 1, isolation: 1\)[^#

location /t {
rewrite_by_lua_block {
local proxy_wasm = require "resty.http.proxy_wasm"
local proxy_wasm = require "resty.wasmx.proxy_wasm"
assert(proxy_wasm.attach(_G.c_plan))
assert(proxy_wasm.start())
ngx.say("ok")
Expand Down Expand Up @@ -545,7 +545,7 @@ qr/\A\*\d+ proxy_wasm initializing filter chain \(nfilters: 1, isolation: 2\)[^#
--- wasm_modules: hostcalls
--- http_config
init_worker_by_lua_block {
local proxy_wasm = require "resty.http.proxy_wasm"
local proxy_wasm = require "resty.wasmx.proxy_wasm"
local filters = {
{ name = "hostcalls" },
}
Expand All @@ -560,7 +560,7 @@ qr/\A\*\d+ proxy_wasm initializing filter chain \(nfilters: 1, isolation: 2\)[^#

location /t {
rewrite_by_lua_block {
local proxy_wasm = require "resty.http.proxy_wasm"
local proxy_wasm = require "resty.wasmx.proxy_wasm"
assert(proxy_wasm.attach(_G.c_plan, {
isolation = proxy_wasm.isolations.NONE
}))
Expand Down
Loading