This is an automated email from the ASF dual-hosted git repository.

spacewander pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git


The following commit(s) were added to refs/heads/master by this push:
     new 1609ce699 fix: correct inspect plugin default hooks file path and add 
hook remove logs (#8612)
1609ce699 is described below

commit 1609ce6990b6d93262ea80efb29836eab2109c0e
Author: jinhua luo <[email protected]>
AuthorDate: Fri Jan 6 15:22:04 2023 +0800

    fix: correct inspect plugin default hooks file path and add hook remove 
logs (#8612)
---
 apisix/inspect/dbg.lua  |  9 +++++++++
 apisix/inspect/init.lua |  2 +-
 t/plugin/inspect.t      | 30 ++++++++++++++++++++++++++++++
 3 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/apisix/inspect/dbg.lua b/apisix/inspect/dbg.lua
index a8a619a26..7f4e7b114 100644
--- a/apisix/inspect/dbg.lua
+++ b/apisix/inspect/dbg.lua
@@ -44,6 +44,7 @@ local function hook(_, arg)
     local key = finfo.source .. "#" .. arg
 
     local hooks2 = {}
+    local removed_hooks = {}
     for _, hook in ipairs(hooks) do
         if key:sub(-#hook.key) == hook.key then
             local filter_func = hook.filter_func
@@ -74,9 +75,12 @@ local function hook(_, arg)
             local r1, r2_or_err = pcall(filter_func, info)
             if not r1 then
                 core.log.error("inspect: pcall filter_func:", r2_or_err)
+                table_insert(removed_hooks, hook)
             elseif r2_or_err == false then
                 -- if filter_func returns false, keep the hook
                 table_insert(hooks2, hook)
+            else
+                table_insert(removed_hooks, hook)
             end
         else
             -- key not match, keep the hook
@@ -84,10 +88,15 @@ local function hook(_, arg)
         end
     end
 
+    for _, hook in ipairs(removed_hooks) do
+        core.log.warn("inspect: remove hook: ", hook.key)
+    end
+
     -- disable debug mode if all hooks done
     if #hooks2 ~= #hooks then
         hooks = hooks2
         if #hooks == 0 then
+            core.log.warn("inspect: all hooks removed")
             debug.sethook()
         end
     end
diff --git a/apisix/inspect/init.lua b/apisix/inspect/init.lua
index 649532d1a..7014b613a 100644
--- a/apisix/inspect/init.lua
+++ b/apisix/inspect/init.lua
@@ -107,7 +107,7 @@ end
 
 function _M.init(delay, file)
     if not running then
-        file = file or "/var/run/apisix_inspect_hooks.lua"
+        file = file or "/usr/local/apisix/plugin_inspect_hooks.lua"
         delay = delay or 3
 
         setup_hooks(file)
diff --git a/t/plugin/inspect.t b/t/plugin/inspect.t
index e938431b4..0bbbfd7ff 100644
--- a/t/plugin/inspect.t
+++ b/t/plugin/inspect.t
@@ -497,3 +497,33 @@ upvar2=yes
             assert(t4-t8 < t4*0.8, "hot2 jit recover")
         }
     }
+
+
+
+=== TEST 13: remove hook log
+--- config
+    location /t {
+        content_by_lua_block {
+            local code = set_test_route("run1")
+            if code >= 300 then
+                ngx.status = code
+                return
+            end
+
+            write_hooks([[
+            local dbg = require "apisix.inspect.dbg"
+            dbg.set_hook("t/lib/test_inspect.lua", 27, nil, function(info)
+                return true
+            end)
+            ]])
+
+            ngx.sleep(1.5)
+
+            do_request()
+
+            os.remove("/tmp/apisix_inspect_hooks.lua")
+        }
+    }
+--- error_log
+inspect: remove hook: t/lib/test_inspect.lua#27
+inspect: all hooks removed

Reply via email to