Skip to content

Commit

Permalink
style(dynamic_hook): rename run_hooks to run_hook as it only run …
Browse files Browse the repository at this point in the history
…a single hook
  • Loading branch information
ADD-SP committed May 27, 2024
1 parent ba73506 commit 9b8c63f
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 43 deletions.
2 changes: 1 addition & 1 deletion kong/dynamic_hook/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ function _M.is_group_enabled(group_name)
end


function _M.run_hooks(group_name, hook_name, a1, a2, a3, a4, a5, a6, a7, a8, ...)
function _M.run_hook(group_name, hook_name, a1, a2, a3, a4, a5, a6, a7, a8, ...)
assert(type(group_name) == "string", "group_name must be a string")
assert(type(hook_name) == "string", "hook_name must be a string")

Expand Down
72 changes: 36 additions & 36 deletions kong/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ local get_start_time_ms = utils.get_start_time_ms
local get_updated_now_ms = utils.get_updated_now_ms


local req_dyn_hook_run_hooks = req_dyn_hook.run_hooks
local req_dyn_hook_run_hook = req_dyn_hook.run_hook
local req_dyn_hook_is_group_enabled = req_dyn_hook.is_group_enabled


Expand Down Expand Up @@ -326,7 +326,7 @@ local function execute_global_plugins_iterator(plugins_iterator, phase, ctx)
local has_timing = ctx.has_timing

if has_timing then
req_dyn_hook_run_hooks("timing", "before:plugin_iterator")
req_dyn_hook_run_hook("timing", "before:plugin_iterator")
end

for _, plugin, configuration in iterator, plugins, 0 do
Expand All @@ -338,13 +338,13 @@ local function execute_global_plugins_iterator(plugins_iterator, phase, ctx)
setup_plugin_context(ctx, plugin, configuration)

if has_timing then
req_dyn_hook_run_hooks("timing", "before:plugin", plugin.name, ctx.plugin_id)
req_dyn_hook_run_hook("timing", "before:plugin", plugin.name, ctx.plugin_id)
end

plugin.handler[phase](plugin.handler, configuration)

if has_timing then
req_dyn_hook_run_hooks("timing", "after:plugin")
req_dyn_hook_run_hook("timing", "after:plugin")
end

reset_plugin_context(ctx, old_ws)
Expand All @@ -355,7 +355,7 @@ local function execute_global_plugins_iterator(plugins_iterator, phase, ctx)
end

if has_timing then
req_dyn_hook_run_hooks("timing", "after:plugin_iterator")
req_dyn_hook_run_hook("timing", "after:plugin_iterator")
end
end

Expand All @@ -376,7 +376,7 @@ local function execute_collecting_plugins_iterator(plugins_iterator, phase, ctx)
local has_timing = ctx.has_timing

if has_timing then
req_dyn_hook_run_hooks("timing", "before:plugin_iterator")
req_dyn_hook_run_hook("timing", "before:plugin_iterator")
end

for _, plugin, configuration in iterator, plugins, 0 do
Expand All @@ -389,14 +389,14 @@ local function execute_collecting_plugins_iterator(plugins_iterator, phase, ctx)
setup_plugin_context(ctx, plugin, configuration)

if has_timing then
req_dyn_hook_run_hooks( "timing", "before:plugin", plugin.name, ctx.plugin_id)
req_dyn_hook_run_hook( "timing", "before:plugin", plugin.name, ctx.plugin_id)
end

local co = coroutine.create(plugin.handler[phase])
local cok, cerr = coroutine.resume(co, plugin.handler, configuration)

if has_timing then
req_dyn_hook_run_hooks("timing", "after:plugin")
req_dyn_hook_run_hook("timing", "after:plugin")
end

if not cok then
Expand Down Expand Up @@ -426,7 +426,7 @@ local function execute_collecting_plugins_iterator(plugins_iterator, phase, ctx)
end

if has_timing then
req_dyn_hook_run_hooks("timing", "after:plugin_iterator")
req_dyn_hook_run_hook("timing", "after:plugin_iterator")
end

ctx.delay_response = nil
Expand All @@ -447,7 +447,7 @@ local function execute_collected_plugins_iterator(plugins_iterator, phase, ctx)
local has_timing = ctx.has_timing

if has_timing then
req_dyn_hook_run_hooks("timing", "before:plugin_iterator")
req_dyn_hook_run_hook("timing", "before:plugin_iterator")
end

for _, plugin, configuration in iterator, plugins, 0 do
Expand All @@ -459,13 +459,13 @@ local function execute_collected_plugins_iterator(plugins_iterator, phase, ctx)
setup_plugin_context(ctx, plugin, configuration)

if has_timing then
req_dyn_hook_run_hooks("timing", "before:plugin", plugin.name, ctx.plugin_id)
req_dyn_hook_run_hook("timing", "before:plugin", plugin.name, ctx.plugin_id)
end

plugin.handler[phase](plugin.handler, configuration)

if has_timing then
req_dyn_hook_run_hooks("timing", "after:plugin")
req_dyn_hook_run_hook("timing", "after:plugin")
end

reset_plugin_context(ctx, old_ws)
Expand All @@ -476,7 +476,7 @@ local function execute_collected_plugins_iterator(plugins_iterator, phase, ctx)
end

if has_timing then
req_dyn_hook_run_hooks("timing", "after:plugin_iterator")
req_dyn_hook_run_hook("timing", "after:plugin_iterator")
end
end

Expand Down Expand Up @@ -1119,15 +1119,15 @@ function Kong.rewrite()
ctx.KONG_PHASE = PHASES.rewrite
local has_timing

req_dyn_hook_run_hooks("timing:auth", "auth")
req_dyn_hook_run_hook("timing:auth", "auth")

if req_dyn_hook_is_group_enabled("timing") then
ctx.has_timing = true
has_timing = true
end

if has_timing then
req_dyn_hook_run_hooks("timing", "before:rewrite")
req_dyn_hook_run_hook("timing", "before:rewrite")
end

kong_resty_ctx.stash_ref(ctx)
Expand Down Expand Up @@ -1156,7 +1156,7 @@ function Kong.rewrite()
ctx.KONG_REWRITE_TIME = ctx.KONG_REWRITE_ENDED_AT - ctx.KONG_REWRITE_START

if has_timing then
req_dyn_hook_run_hooks("timing", "after:rewrite")
req_dyn_hook_run_hook("timing", "after:rewrite")
end
end

Expand All @@ -1166,7 +1166,7 @@ function Kong.access()
local has_timing = ctx.has_timing

if has_timing then
req_dyn_hook_run_hooks("timing", "before:access")
req_dyn_hook_run_hook("timing", "before:access")
end

if not ctx.KONG_ACCESS_START then
Expand All @@ -1192,7 +1192,7 @@ function Kong.access()
ctx.KONG_RESPONSE_LATENCY = ctx.KONG_ACCESS_ENDED_AT - ctx.KONG_PROCESSING_START

if has_timing then
req_dyn_hook_run_hooks("timing", "after:access")
req_dyn_hook_run_hook("timing", "after:access")
end

return flush_delayed_response(ctx)
Expand All @@ -1208,7 +1208,7 @@ function Kong.access()
ctx.buffered_proxying = nil

if has_timing then
req_dyn_hook_run_hooks("timing", "after:access")
req_dyn_hook_run_hook("timing", "after:access")
end

return kong.response.error(503, "no Service found with those values")
Expand All @@ -1229,7 +1229,7 @@ function Kong.access()
local upgrade = var.upstream_upgrade or ""
if version < 2 and upgrade == "" then
if has_timing then
req_dyn_hook_run_hooks("timing", "after:access")
req_dyn_hook_run_hook("timing", "after:access")
end

return Kong.response()
Expand All @@ -1245,7 +1245,7 @@ function Kong.access()
end

if has_timing then
req_dyn_hook_run_hooks("timing", "after:access")
req_dyn_hook_run_hook("timing", "after:access")
end
end

Expand All @@ -1255,7 +1255,7 @@ function Kong.balancer()
local has_timing = ctx.has_timing

if has_timing then
req_dyn_hook_run_hooks("timing", "before:balancer")
req_dyn_hook_run_hook("timing", "before:balancer")
end

-- This may be called multiple times, and no yielding here!
Expand Down Expand Up @@ -1337,7 +1337,7 @@ function Kong.balancer()
ctx.KONG_PROXY_LATENCY = ctx.KONG_BALANCER_ENDED_AT - ctx.KONG_PROCESSING_START

if has_timing then
req_dyn_hook_run_hooks("timing", "after:balancer")
req_dyn_hook_run_hook("timing", "after:balancer")
end

return ngx.exit(errcode)
Expand All @@ -1349,7 +1349,7 @@ function Kong.balancer()
ngx_log(ngx_ERR, "failed to set balancer Host header: ", err)

if has_timing then
req_dyn_hook_run_hooks("timing", "after:balancer")
req_dyn_hook_run_hook("timing", "after:balancer")
end

return ngx.exit(500)
Expand Down Expand Up @@ -1404,7 +1404,7 @@ function Kong.balancer()
ctx.KONG_PROXY_LATENCY = ctx.KONG_BALANCER_ENDED_AT - ctx.KONG_PROCESSING_START

if has_timing then
req_dyn_hook_run_hooks("timing", "after:balancer")
req_dyn_hook_run_hook("timing", "after:balancer")
end

return ngx.exit(500)
Expand Down Expand Up @@ -1444,7 +1444,7 @@ function Kong.balancer()
ctx.KONG_PROXY_LATENCY = ctx.KONG_BALANCER_ENDED_AT - ctx.KONG_PROCESSING_START

if has_timing then
req_dyn_hook_run_hooks("timing", "after:balancer")
req_dyn_hook_run_hook("timing", "after:balancer")
end
end

Expand Down Expand Up @@ -1473,7 +1473,7 @@ do
local has_timing = ctx.has_timing

if has_timing then
req_dyn_hook_run_hooks("timing", "before:response")
req_dyn_hook_run_hook("timing", "before:response")
end

local plugins_iterator = runloop.get_plugins_iterator()
Expand All @@ -1494,7 +1494,7 @@ do
ngx.status = res.status or 502

if has_timing then
req_dyn_hook_run_hooks("timing", "after:response")
req_dyn_hook_run_hook("timing", "after:response")
end

return kong_error_handlers(ctx)
Expand Down Expand Up @@ -1548,7 +1548,7 @@ do
ngx.print(body)

if has_timing then
req_dyn_hook_run_hooks("timing", "after:response")
req_dyn_hook_run_hook("timing", "after:response")
end

-- jump over the balancer to header_filter
Expand All @@ -1562,7 +1562,7 @@ function Kong.header_filter()
local has_timing = ctx.has_timing

if has_timing then
req_dyn_hook_run_hooks("timing", "before:header_filter")
req_dyn_hook_run_hook("timing", "before:header_filter")
end

if not ctx.KONG_PROCESSING_START then
Expand Down Expand Up @@ -1634,7 +1634,7 @@ function Kong.header_filter()
ctx.KONG_HEADER_FILTER_TIME = ctx.KONG_HEADER_FILTER_ENDED_AT - ctx.KONG_HEADER_FILTER_START

if has_timing then
req_dyn_hook_run_hooks("timing", "after:header_filter")
req_dyn_hook_run_hook("timing", "after:header_filter")
end
end

Expand All @@ -1644,7 +1644,7 @@ function Kong.body_filter()
local has_timing = ctx.has_timing

if has_timing then
req_dyn_hook_run_hooks("timing", "before:body_filter")
req_dyn_hook_run_hook("timing", "before:body_filter")
end

if not ctx.KONG_BODY_FILTER_START then
Expand Down Expand Up @@ -1703,7 +1703,7 @@ function Kong.body_filter()

if not arg[2] then
if has_timing then
req_dyn_hook_run_hooks("timing", "after:body_filter")
req_dyn_hook_run_hook("timing", "after:body_filter")
end

return
Expand All @@ -1725,7 +1725,7 @@ function Kong.body_filter()
end

if has_timing then
req_dyn_hook_run_hooks("timing", "after:body_filter")
req_dyn_hook_run_hook("timing", "after:body_filter")
end
end

Expand All @@ -1735,7 +1735,7 @@ function Kong.log()
local has_timing = ctx.has_timing

if has_timing then
req_dyn_hook_run_hooks("timing", "before:log")
req_dyn_hook_run_hook("timing", "before:log")
end

if not ctx.KONG_LOG_START then
Expand Down Expand Up @@ -1830,7 +1830,7 @@ function Kong.log()
runloop.log.after(ctx)

if has_timing then
req_dyn_hook_run_hooks("timing", "after:log")
req_dyn_hook_run_hook("timing", "after:log")
end

release_table(CTX_NS, ctx)
Expand Down
4 changes: 2 additions & 2 deletions kong/resty/dns/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ local table_concat = table.concat
local string_lower = string.lower
local string_byte = string.byte

local req_dyn_hook_run_hooks = req_dyn_hook.run_hooks
local req_dyn_hook_run_hook = req_dyn_hook.run_hook


local DOT = string_byte(".")
Expand Down Expand Up @@ -145,7 +145,7 @@ local cachelookup = function(qname, qtype)

local ctx = ngx.ctx
if ctx and ctx.has_timing then
req_dyn_hook_run_hooks("timing", "dns:cache_lookup", cached ~= nil)
req_dyn_hook_run_hook("timing", "dns:cache_lookup", cached ~= nil)
end

if cached then
Expand Down
8 changes: 4 additions & 4 deletions kong/runloop/handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ local request_id_get = request_id.get
local escape = require("kong.tools.uri").escape
local encode = require("string.buffer").encode

local req_dyn_hook_run_hooks = req_dyn_hook.run_hooks
local req_dyn_hook_run_hook = req_dyn_hook.run_hook

local is_http_module = subsystem == "http"
local is_stream_module = subsystem == "stream"
Expand Down Expand Up @@ -1112,15 +1112,15 @@ return {
local has_timing = ctx.has_timing

if has_timing then
req_dyn_hook_run_hooks("timing", "before:router")
req_dyn_hook_run_hook("timing", "before:router")
end

-- routing request
local router = get_updated_router()
local match_t = router:exec(ctx)

if has_timing then
req_dyn_hook_run_hooks("timing", "after:router")
req_dyn_hook_run_hook("timing", "after:router")
end

if not match_t then
Expand All @@ -1141,7 +1141,7 @@ return {
ctx.workspace = match_t.route and match_t.route.ws_id

if has_timing then
req_dyn_hook_run_hooks("timing", "workspace_id:got", ctx.workspace)
req_dyn_hook_run_hook("timing", "workspace_id:got", ctx.workspace)
end

local host = var.host
Expand Down

0 comments on commit 9b8c63f

Please sign in to comment.