feat: add inspect plugin#8400
Conversation
moonming
left a comment
There was a problem hiding this comment.
why we need this plugin? And I think it's diagnostic not inspect
In my opinion, And, the naming comes from the design document, and the document was publicized for more than 3 weeks. |
…n blacklist for jit forever
| if not f then | ||
| return false, err | ||
| end | ||
| local code = f:read("*all") |
There was a problem hiding this comment.
What about your opinion on this?
| delay = attr.delay | ||
| hooks_file = attr.hooks_file | ||
| end | ||
| ngx.log(ngx.INFO, "delay=", delay, ", hooks_file=", hooks_file) |
| $(ENV_INSTALL) apisix/plugins/ip-restriction/*.lua $(ENV_INST_LUADIR)/apisix/plugins/ip-restriction/ | ||
|
|
||
| $(ENV_INSTALL) -d $(ENV_INST_LUADIR)/apisix/inspect | ||
| $(ENV_INSTALL) apisix/inspect/*.lua $(ENV_INST_LUADIR)/apisix/inspect/ |
There was a problem hiding this comment.
Should be moved under $(ENV_INSTALL) apisix/include/
| if not f then | ||
| return false, err | ||
| end | ||
| local code = f:read("*all") |
There was a problem hiding this comment.
What about your opinion on this?
|
@spacewander Add nil case handling already. GitHub failed to add an outdated flag here. |
| end | ||
| end | ||
|
|
||
| local function hook(evt, arg) |
There was a problem hiding this comment.
evt unused in hook function?
| for _, hook in ipairs(dbg.hooks()) do | ||
| table_insert(hooks, hook.key) | ||
| end | ||
| core.log.info("set hooks: err=", err, ", hooks=", core.json.encode(hooks)) |
There was a problem hiding this comment.
| core.log.info("set hooks: err=", err, ", hooks=", core.json.encode(hooks)) | |
| core.log.info("set hooks: err: ", err, ", hooks: ", core.json.delay_encode(hooks)) |
is better?
| if not func then | ||
| return false, err | ||
| end | ||
| func() |
There was a problem hiding this comment.
do we need use pcall(func()) here?
There was a problem hiding this comment.
Already did so in the outer function.
| local code = f:read("*all") | ||
| f:close() | ||
| if code == nil then | ||
| return false, "cannot read hooks file" |
There was a problem hiding this comment.
We can improve the error message here by adding the err returned from the f:read above.
https://github.com/LuaJIT/LuaJIT/blob/8625eee71f16a3a780ec92bc303c17456efc7fb3/src/lib_aux.c#L39
The second returned value is a string describing the err.
I see. Thanks for your clarification. |
| - APISIX | ||
| - Plugin | ||
| - inspect | ||
| - inspect |
|
|
||
| ## Description | ||
|
|
||
| It's useful to set arbitrary breakpoint in any lua file to inspect the context information, |
|
|
||
| ## Features | ||
|
|
||
| * set breakpoint at any position |
| ## Features | ||
|
|
||
| * set breakpoint at any position | ||
| * dynamic breakpoint |
| -- limitations under the License. | ||
| -- | ||
| local core = require("apisix.core") | ||
| local dbg = require("apisix.inspect.dbg") |
There was a problem hiding this comment.
Abbreviation for "debug". Also to avoid conflict with the built-in Lua debug module.
| # redirect: | ||
| # https_port: 8443 # the default port for use by HTTP redirects to HTTPS | ||
| inspect: | ||
| delay: 3 |
There was a problem hiding this comment.
3 seconds, I would add a comment for this line.
| # https_port: 8443 # the default port for use by HTTP redirects to HTTPS | ||
| inspect: | ||
| delay: 3 # in seconds | ||
| hooks_file: "/var/run/apisix_inspect_hooks.lua" |
There was a problem hiding this comment.
What is this file for? Has Lua code in it?
There was a problem hiding this comment.
@moonming yes, this hooks file is used to define breakpoints, which itself is lua file. When the administrator needs to set breakpoints to inspect something, he would edit this file, or link another file to this path.
There was a problem hiding this comment.
Normally this file is non-exist. It's only available when you need to set breakpoints. Please refer to the plugin doc.
There was a problem hiding this comment.
There are security risks.
This Lua code file must be in the APISIX directory, and users who do not have write permissions to the APISIX directory cannot write or modify this file.
| # create a hooks file to set a test breakpoint | ||
| # Note that the breakpoint is associated with the line number, | ||
| # so if the Lua code changes, you need to adjust the line number in the hooks file | ||
| cat <<EOF >/tmp/hooks.lua |
There was a problem hiding this comment.
Do not use the /tmp directory, especially for documentation
There was a problem hiding this comment.
ok, I would change it.
| # https_port: 8443 # the default port for use by HTTP redirects to HTTPS | ||
| inspect: | ||
| delay: 3 # in seconds | ||
| hooks_file: "/var/run/apisix_inspect_hooks.lua" |
There was a problem hiding this comment.
There are security risks.
This Lua code file must be in the APISIX directory, and users who do not have write permissions to the APISIX directory cannot write or modify this file.
|
@moonming |
Description
It's useful to set arbitrary breakpoint in any lua file to inspect the context information, e.g. print local variables if some condition satisfied.
In this way, you don't need to modify the source code of your project, and just get diagnose information on demand, i.e. dynamic logging.
Checklist