-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
feat: add inspect plugin #8400
feat: add inspect plugin #8400
Conversation
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.
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
apisix/inspect/init.lua
Outdated
if not f then | ||
return false, err | ||
end | ||
local code = f:read("*all") |
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.
Let's do some err check?
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.
What about your opinion on this?
apisix/plugins/inspect.lua
Outdated
delay = attr.delay | ||
hooks_file = attr.hooks_file | ||
end | ||
ngx.log(ngx.INFO, "delay=", delay, ", hooks_file=", hooks_file) |
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.
core.log.info
Makefile
Outdated
@@ -315,6 +315,9 @@ install: runtime | |||
$(ENV_INSTALL) -d $(ENV_INST_LUADIR)/apisix/plugins/ip-restriction | |||
$(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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be moved under $(ENV_INSTALL) apisix/include/
apisix/inspect/init.lua
Outdated
if not f then | ||
return false, err | ||
end | ||
local code = f:read("*all") |
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.
What about your opinion on this?
@spacewander Add nil case handling already. GitHub failed to add an outdated flag here. |
apisix/inspect/dbg.lua
Outdated
end | ||
end | ||
|
||
local function hook(evt, arg) |
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.
evt
unused in hook
function?
apisix/inspect/init.lua
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need use pcall(func())
here?
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.
Already did so in the outer function.
apisix/inspect/init.lua
Outdated
local code = f:read("*all") | ||
f:close() | ||
if code == nil then | ||
return false, "cannot read hooks file" |
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 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. |
docs/en/latest/plugins/inspect.md
Outdated
- APISIX | ||
- Plugin | ||
- inspect | ||
- inspect |
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 should more this line
docs/en/latest/plugins/inspect.md
Outdated
|
||
## Description | ||
|
||
It's useful to set arbitrary breakpoint in any lua file to inspect the context information, |
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.
lua
-> Lua
docs/en/latest/plugins/inspect.md
Outdated
|
||
## Features | ||
|
||
* set breakpoint at any position |
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.
Capitalized?
docs/en/latest/plugins/inspect.md
Outdated
## Features | ||
|
||
* set breakpoint at any position | ||
* dynamic breakpoint |
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.
ditto
-- limitations under the License. | ||
-- | ||
local core = require("apisix.core") | ||
local dbg = require("apisix.inspect.dbg") |
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.
What‘s dbg
means?
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.
Abbreviation for "debug". Also to avoid conflict with the built-in Lua debug module.
conf/config-default.yaml
Outdated
@@ -555,6 +556,9 @@ plugin_attr: | |||
send: 60s | |||
# redirect: | |||
# https_port: 8443 # the default port for use by HTTP redirects to HTTPS | |||
inspect: | |||
delay: 3 |
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.
3s or 3 mins?
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.
3 seconds, I would add a comment for this line.
conf/config-default.yaml
Outdated
@@ -555,6 +556,9 @@ plugin_attr: | |||
send: 60s | |||
# redirect: | |||
# 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this file for? Has Lua code in it?
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.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
docs/en/latest/plugins/inspect.md
Outdated
# 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not use the /tmp directory, especially for documentation
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.
ok, I would change it.
conf/config-default.yaml
Outdated
@@ -555,6 +556,9 @@ plugin_attr: | |||
send: 60s | |||
# redirect: | |||
# 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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