-
Notifications
You must be signed in to change notification settings - Fork 3
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: required changes for 3.1 compatibility #36
Conversation
-- `table.nkeys()` is a LuaJIT function and is not available to the Lua VM that goks uses. | ||
local nkeys | ||
do | ||
local ok | ||
ok, nkeys = pcall(require, "table.nkeys") | ||
if not ok then | ||
nkeys = function (tab) | ||
local count = 0 | ||
for _, v in pairs(tab) do | ||
if v ~= nil then | ||
count = count + 1 | ||
end | ||
end | ||
return count | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is copypasta from resty/healthecheck.lua. I'm following the pattern of local_tab
initialized on L46 of this file. This addresses the error:
lua-tree/share/lua/5.1/kong/db/schema/init.lua:4: module table.nkeys not found:
no field package.preload['table.nkeys']
open /table/nkeys.lua: file does not exist
open lua-tree/share/lua/5.1/table/nkeys.lua: file does not exist
open lua-tree/share/lua/5.1/table/nkeys/init.lua: file does not exist,
I can't tell if this resolves the issue, however. I get a new error:
Received unexpected error:
lua-tree/share/lua/5.1/kong/constants.lua:222: table index is nil
stack traceback:
lua-tree/share/lua/5.1/kong/constants.lua:222: in function <lua-tree/share/lua/5.1/kong/constants.lua:0>
[G]: in function 'require'
lua-tree/share/lua/5.1/kong/db/schema/typedefs.lua:6: in function <lua-tree/share/lua/5.1/kong/db/schema/typedefs.lua:0>
[G]: in function 'require'
setup.lua:6: in main chunk
[G]: ?
I'm able to validate the method is called. The if block beginning on line 62 is entered but nkeys = function (tab)
on line 63 panics. I'm not sure if it's the method call itself or something else. A print statement on line 64 is never executed. Curiously, print statements before the method is called are also not executed?
The stacktrace is also not very illuminating: lua-tree/share/lua/5.1/kong/constants.lua:222: in function <lua-tree/share/lua/5.1/kong/constants.lua:0>
is on a different line in kong-ee and points to LOG_LEVELS
. This looks new to 3.1, I don't see it in this 3.0 branch.
My guess is either:
- This is a new error. The introduction of
LOG_LEVELS
is causing something to break. What and why is unclear. - The update I made to
nkeys
somehow breaks this import, or something that processes this import.
Number 1 is the most reasonable, but I don't really understand what table index is nil
means in this context and I'm struggling to trace where exactly this is breaking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really understand what
table index is nil
means in this context and I'm struggling to trace where exactly this is breaking.
the LOG_LEVELS
table, starting in constants.lua:222
has this form:
LOG_LEVELS = {
debug = ngx.DEBUG,
info = ngx.INFO,
notice = ngx.NOTICE,
warn = ngx.WARN,
error = ngx.ERR,
crit = ngx.CRIT,
alert = ngx.ALERT,
emerg = ngx.EMERG,
[ngx.DEBUG] = "debug",
[ngx.INFO] = "info",
[ngx.NOTICE] = "notice",
[ngx.WARN] = "warn",
[ngx.ERR] = "error",
[ngx.CRIT] = "crit",
[ngx.ALERT] = "alert",
[ngx.EMERG] = "emerg",
},
lines 231-238 use the form [key-expression] = value-expression
, so it evaluates the ngx.DEBUG
, ngx.INFO
, etc to get the actual keys (unlike key-name=value-expression
, which directly sets the key as a string constant). if any of these is nil
, this error will trigger. unfortunately, this aborts the whole (sub) table construction, so we don't know which of these is failing.
Now to find where are those ngx.XXXX
values....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now to find where are those
ngx.XXXX
values....
Can't find them. I think the easiest would be to add to internal/vm/setup.go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
local decode_base64url = require "ngx.base64".decode_base64url | ||
local decode_base64url = ngx.decode_base64url |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addresses:
lua-tree/share/lua/5.1/kong/tools/utils.lua:1270: module ngx.base64 not found:
no field package.preload['ngx.base64']
open /ngx/base64.lua: file does not exist
open lua-tree/share/lua/5.1/ngx/base64.lua: file does not exist
open lua-tree/share/lua/5.1/ngx/base64/init.lua: file does not exist,
This (and other instances) will need to be added to lua-tree.patch
or fixed in kong-ee.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there's already lualibs/go/ngx/base64.go
, which implements the ngx.decode_base64
function. i guess the URL variant should be added there, so line 1270 could go unmodified.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding a decode_base64url
aliased function to lualibs/go/ngx/base64.go
was my first approach. However, I noticed that updating the import without the rest of the work also resolved the issue. My guess is there may be a runtime error for calls to ngx.decode_base64url
? I'll look at extending lualibs/go/ngx/base64.go
and adding some test coverage if I find gaps.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there's already lualibs/go/ngx/base64.go, which implements the ngx.decode_base64 function. i guess the URL variant should be added there, so line 1270 could go unmodified.
We have encode_base64
, no decode functions. Any way I change this will be internally inconsistent. I'd like to leave this change as-is without adding any new methods to the go.ngx package.
return bin | ||
end | ||
end | ||
local sha256_bin = require "sha256".sha256_bin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addresses:
Received unexpected error:
lua-tree/share/lua/5.1/resty/openssl/digest.lua:1: module ffi not found:
no field package.preload['ffi']
open /ffi.lua: file does not exist
open lua-tree/share/lua/5.1/ffi.lua: file does not exist
open lua-tree/share/lua/5.1/ffi/init.lua: file does not exist,
stack traceback:
[G]: in function 'require'
lua-tree/share/lua/5.1/resty/openssl/digest.lua:1: in function <lua-tree/share/lua/5.1/resty/openssl/digest.lua:0>
[G]: in function 'require'
lua-tree/share/lua/5.1/kong/tools/utils.lua:1304: in function <lua-tree/share/lua/5.1/kong/tools/utils.lua:0>
[G]: in function 'require'
This will need to be added to lua-tree.patch.
local to_hex = require "resty.string".to_hex | ||
local to_hex = require "hex".to_hex |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addresses another instance of module ffi not found
internal/vm/vm.go
Outdated
l.PreloadModule("sha256", sha256.Loader) | ||
l.PreloadModule("hex", hex.Loader) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're using the pattern "go.xxx" for those replacement modules:
l.PreloadModule("sha256", sha256.Loader) | |
l.PreloadModule("hex", hex.Loader) | |
l.PreloadModule("go.sha256", sha256.Loader) | |
l.PreloadModule("go.hex", hex.Loader) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -11,6 +9,18 @@ local table_concat = table.concat | |||
local ngx_re_find = ngx.re.find | |||
local ngx_re_gsub = ngx.re.gsub | |||
|
|||
-- `table.new()` is a LuaJIT function and is not available to the Lua VM that goks uses. | |||
local new_tab |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addresses
lua-tree/share/lua/5.1/kong/tools/uri.lua:1: module table.new not found
See
local new_tab |
5f2ce54
to
001809f
Compare
@javierguerragiraldez @GGabriele I'm seeking feedback on current progress and guidance on next steps. I ripped out a bunch of stuff to get this to a point where tests are passing. I'm trying to get a complete picture and determine what can be removed vs what needs to be reworked. I took a shortcut and completely removed the Here's the current status as I understand it:
|
yes. remember that we only use goks to validate plugins, not all of the config; much less during "real work". I did port the atc-router (#31), but then realised koko doesn't use those typedefs at all.
full agree. right now the easiest would be to either add directly to the bunch of Lua code at
again, remember we only use plugin config validation. i guess the "unit" level tests should test the typedefs, and the "functional" level should just test good and bad plugin configs. I think most of the existing tests are for the typedefs, while the plugins are mostly only for the "hard" features.
the biggest quality-of-life improvement here would be a script to recreate the patchfile completely from the changes to the Lua tree. What I've done in the past is to use git-diff (or was it git format-patch?) and then copy/paste discrete chunks into the big patchfile. constantly applying it until it reproduced my changes with zero complains. In short, commit all the Lua changes, and then tweak the patchfile until regenerating the lua-tree results in no diffs as seen on
i wouldn't worry too much. if the plugin validators can reject/accept consistently, we're ok. |
FYI: this will need to pull Kong |
990ddc1
to
c82d5e7
Compare
c82d5e7
to
cddf098
Compare
Confirmed current changes work when imported into
All package |
|
@GGabriele @javierguerragiraldez @mikefero I've trimmed down some of the changes and updated the patchfile. This should be ready to be merged into #35. Patch applies correctly, goks and koko tests passing. |
@omegabytes I am not sure of the state of this PR anymore now that we fixed the YAML processing for validation. Is this PR required anymore and will #35 be the only thing that still needs to be merged to complete the updates for 3.1.0? |
Whoops! Didn't mean to close that! |
At a high level, this looks good. |
@omegabytes other than this ask, can you also sign the license CLA for this repo? |
@omegabytes With 3.2.0 on the horizon I am going to close this PR in favor of grabbing the newest updates after that release occurs. |
Additional updates required before goks works with kong v3.1. While this is in draft, please assume additional unobserved failures exist due to the iterative nature of the failures.