From 280f4f1d6a28d6e67593a922af32bc38eb15bcca Mon Sep 17 00:00:00 2001 From: Qi Date: Mon, 23 Oct 2023 16:07:10 +0800 Subject: [PATCH] style(request-debugging): rename `ctx.is_timing_enabled` to `ctx.has_timing` to maintain synchronization with the EE code (Backport from https://github.com/Kong/kong/commit/f59e36b554b6071a9213deea6947eb804dd7a6f6) --- kong/init.lua | 92 +++++++++++++++++++-------------------- kong/resty/dns/client.lua | 2 +- kong/runloop/handler.lua | 8 ++-- 3 files changed, 51 insertions(+), 51 deletions(-) diff --git a/kong/init.lua b/kong/init.lua index 2f02d73f9e2..8fb8f605be1 100644 --- a/kong/init.lua +++ b/kong/init.lua @@ -319,9 +319,9 @@ local function execute_global_plugins_iterator(plugins_iterator, phase, ctx) end local old_ws = ctx.workspace - local is_timing_enabled = ctx.is_timing_enabled + local has_timing = ctx.has_timing - if is_timing_enabled then + if has_timing then req_dyn_hook_run_hooks(ctx, "timing", "before:plugin_iterator") end @@ -333,13 +333,13 @@ local function execute_global_plugins_iterator(plugins_iterator, phase, ctx) setup_plugin_context(ctx, plugin, configuration) - if is_timing_enabled then + if has_timing then req_dyn_hook_run_hooks(ctx, "timing", "before:plugin", plugin.name, ctx.plugin_id) end plugin.handler[phase](plugin.handler, configuration) - if is_timing_enabled then + if has_timing then req_dyn_hook_run_hooks(ctx, "timing", "after:plugin") end @@ -350,7 +350,7 @@ local function execute_global_plugins_iterator(plugins_iterator, phase, ctx) end end - if is_timing_enabled then + if has_timing then req_dyn_hook_run_hooks(ctx, "timing", "after:plugin_iterator") end end @@ -369,9 +369,9 @@ local function execute_collecting_plugins_iterator(plugins_iterator, phase, ctx) ctx.delay_response = true local old_ws = ctx.workspace - local is_timing_enabled = ctx.is_timing_enabled + local has_timing = ctx.has_timing - if is_timing_enabled then + if has_timing then req_dyn_hook_run_hooks(ctx, "timing", "before:plugin_iterator") end @@ -384,14 +384,14 @@ local function execute_collecting_plugins_iterator(plugins_iterator, phase, ctx) setup_plugin_context(ctx, plugin, configuration) - if is_timing_enabled then + if has_timing then req_dyn_hook_run_hooks(ctx, "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 is_timing_enabled then + if has_timing then req_dyn_hook_run_hooks(ctx, "timing", "after:plugin") end @@ -421,7 +421,7 @@ local function execute_collecting_plugins_iterator(plugins_iterator, phase, ctx) end end - if is_timing_enabled then + if has_timing then req_dyn_hook_run_hooks(ctx, "timing", "after:plugin_iterator") end @@ -440,9 +440,9 @@ local function execute_collected_plugins_iterator(plugins_iterator, phase, ctx) end local old_ws = ctx.workspace - local is_timing_enabled = ctx.is_timing_enabled + local has_timing = ctx.has_timing - if is_timing_enabled then + if has_timing then req_dyn_hook_run_hooks(ctx, "timing", "before:plugin_iterator") end @@ -454,13 +454,13 @@ local function execute_collected_plugins_iterator(plugins_iterator, phase, ctx) setup_plugin_context(ctx, plugin, configuration) - if is_timing_enabled then + if has_timing then req_dyn_hook_run_hooks(ctx, "timing", "before:plugin", plugin.name, ctx.plugin_id) end plugin.handler[phase](plugin.handler, configuration) - if is_timing_enabled then + if has_timing then req_dyn_hook_run_hooks(ctx, "timing", "after:plugin") end @@ -471,7 +471,7 @@ local function execute_collected_plugins_iterator(plugins_iterator, phase, ctx) end end - if is_timing_enabled then + if has_timing then req_dyn_hook_run_hooks(ctx, "timing", "after:plugin_iterator") end end @@ -1084,16 +1084,16 @@ function Kong.rewrite() end ctx.KONG_PHASE = PHASES.rewrite - local is_timing_enabled + local has_timing req_dyn_hook_run_hooks(ctx, "timing:auth", "auth") if req_dyn_hook_is_group_enabled("timing") then - ctx.is_timing_enabled = true - is_timing_enabled = true + ctx.has_timing = true + has_timing = true end - if is_timing_enabled then + if has_timing then req_dyn_hook_run_hooks(ctx, "timing", "before:rewrite") end @@ -1122,7 +1122,7 @@ function Kong.rewrite() ctx.KONG_REWRITE_ENDED_AT = get_updated_now_ms() ctx.KONG_REWRITE_TIME = ctx.KONG_REWRITE_ENDED_AT - ctx.KONG_REWRITE_START - if is_timing_enabled then + if has_timing then req_dyn_hook_run_hooks(ctx, "timing", "after:rewrite") end end @@ -1130,9 +1130,9 @@ end function Kong.access() local ctx = ngx.ctx - local is_timing_enabled = ctx.is_timing_enabled + local has_timing = ctx.has_timing - if is_timing_enabled then + if has_timing then req_dyn_hook_run_hooks(ctx, "timing", "before:access") end @@ -1158,7 +1158,7 @@ function Kong.access() ctx.KONG_ACCESS_TIME = ctx.KONG_ACCESS_ENDED_AT - ctx.KONG_ACCESS_START ctx.KONG_RESPONSE_LATENCY = ctx.KONG_ACCESS_ENDED_AT - ctx.KONG_PROCESSING_START - if is_timing_enabled then + if has_timing then req_dyn_hook_run_hooks(ctx, "timing", "after:access") end @@ -1174,7 +1174,7 @@ function Kong.access() ctx.buffered_proxying = nil - if is_timing_enabled then + if has_timing then req_dyn_hook_run_hooks(ctx, "timing", "after:access") end @@ -1195,7 +1195,7 @@ function Kong.access() local version = ngx.req.http_version() local upgrade = var.upstream_upgrade or "" if version < 2 and upgrade == "" then - if is_timing_enabled then + if has_timing then req_dyn_hook_run_hooks(ctx, "timing", "after:access") end @@ -1211,7 +1211,7 @@ function Kong.access() ctx.buffered_proxying = nil end - if is_timing_enabled then + if has_timing then req_dyn_hook_run_hooks(ctx, "timing", "after:access") end end @@ -1219,9 +1219,9 @@ end function Kong.balancer() local ctx = ngx.ctx - local is_timing_enabled = ctx.is_timing_enabled + local has_timing = ctx.has_timing - if is_timing_enabled then + if has_timing then req_dyn_hook_run_hooks(ctx, "timing", "before:balancer") end @@ -1303,7 +1303,7 @@ function Kong.balancer() ctx.KONG_BALANCER_TIME = ctx.KONG_BALANCER_ENDED_AT - ctx.KONG_BALANCER_START ctx.KONG_PROXY_LATENCY = ctx.KONG_BALANCER_ENDED_AT - ctx.KONG_PROCESSING_START - if is_timing_enabled then + if has_timing then req_dyn_hook_run_hooks(ctx, "timing", "after:balancer") end @@ -1315,7 +1315,7 @@ function Kong.balancer() if not ok then ngx_log(ngx_ERR, "failed to set balancer Host header: ", err) - if is_timing_enabled then + if has_timing then req_dyn_hook_run_hooks(ctx, "timing", "after:balancer") end @@ -1370,7 +1370,7 @@ function Kong.balancer() ctx.KONG_BALANCER_TIME = ctx.KONG_BALANCER_ENDED_AT - ctx.KONG_BALANCER_START ctx.KONG_PROXY_LATENCY = ctx.KONG_BALANCER_ENDED_AT - ctx.KONG_PROCESSING_START - if is_timing_enabled then + if has_timing then req_dyn_hook_run_hooks(ctx, "timing", "after:balancer") end @@ -1410,7 +1410,7 @@ function Kong.balancer() -- start_time() is kept in seconds with millisecond resolution. ctx.KONG_PROXY_LATENCY = ctx.KONG_BALANCER_ENDED_AT - ctx.KONG_PROCESSING_START - if is_timing_enabled then + if has_timing then req_dyn_hook_run_hooks(ctx, "timing", "after:balancer") end end @@ -1437,9 +1437,9 @@ do function Kong.response() local ctx = ngx.ctx - local is_timing_enabled = ctx.is_timing_enabled + local has_timing = ctx.has_timing - if is_timing_enabled then + if has_timing then req_dyn_hook_run_hooks(ctx, "timing", "before:response") end @@ -1460,7 +1460,7 @@ do ctx.KONG_PHASE = PHASES.error ngx.status = res.status or 502 - if is_timing_enabled then + if has_timing then req_dyn_hook_run_hooks(ctx, "timing", "after:response") end @@ -1514,7 +1514,7 @@ do -- buffered response ngx.print(body) - if is_timing_enabled then + if has_timing then req_dyn_hook_run_hooks(ctx, "timing", "after:response") end @@ -1526,9 +1526,9 @@ end function Kong.header_filter() local ctx = ngx.ctx - local is_timing_enabled = ctx.is_timing_enabled + local has_timing = ctx.has_timing - if is_timing_enabled then + if has_timing then req_dyn_hook_run_hooks(ctx, "timing", "before:header_filter") end @@ -1600,7 +1600,7 @@ function Kong.header_filter() ctx.KONG_HEADER_FILTER_ENDED_AT = get_updated_now_ms() ctx.KONG_HEADER_FILTER_TIME = ctx.KONG_HEADER_FILTER_ENDED_AT - ctx.KONG_HEADER_FILTER_START - if is_timing_enabled then + if has_timing then req_dyn_hook_run_hooks(ctx, "timing", "after:header_filter") end end @@ -1608,9 +1608,9 @@ end function Kong.body_filter() local ctx = ngx.ctx - local is_timing_enabled = ctx.is_timing_enabled + local has_timing = ctx.has_timing - if is_timing_enabled then + if has_timing then req_dyn_hook_run_hooks(ctx, "timing", "before:body_filter") end @@ -1669,7 +1669,7 @@ function Kong.body_filter() execute_collected_plugins_iterator(plugins_iterator, "body_filter", ctx) if not arg[2] then - if is_timing_enabled then + if has_timing then req_dyn_hook_run_hooks(ctx, "timing", "after:body_filter") end @@ -1691,7 +1691,7 @@ function Kong.body_filter() ctx.KONG_ACCESS_ENDED_AT) end - if is_timing_enabled then + if has_timing then req_dyn_hook_run_hooks(ctx, "timing", "after:body_filter") end end @@ -1699,9 +1699,9 @@ end function Kong.log() local ctx = ngx.ctx - local is_timing_enabled = ctx.is_timing_enabled + local has_timing = ctx.has_timing - if is_timing_enabled then + if has_timing then req_dyn_hook_run_hooks(ctx, "timing", "before:log") end @@ -1796,7 +1796,7 @@ function Kong.log() plugins_iterator.release(ctx) runloop.log.after(ctx) - if is_timing_enabled then + if has_timing then req_dyn_hook_run_hooks(ctx, "timing", "after:log") end diff --git a/kong/resty/dns/client.lua b/kong/resty/dns/client.lua index acbb44a988c..c3f460d4b89 100644 --- a/kong/resty/dns/client.lua +++ b/kong/resty/dns/client.lua @@ -142,7 +142,7 @@ local cachelookup = function(qname, qtype) local cached = dnscache:get(key) local ctx = ngx.ctx - if ctx and ctx.is_timing_enabled then + if ctx and ctx.has_timing then req_dyn_hook_run_hooks(ctx, "timing", "dns:cache_lookup", cached ~= nil) end diff --git a/kong/runloop/handler.lua b/kong/runloop/handler.lua index ed6cfb9bed9..250d712f55b 100644 --- a/kong/runloop/handler.lua +++ b/kong/runloop/handler.lua @@ -1151,9 +1151,9 @@ return { -- to plugins in the access phase for doing headers propagation instrumentation.precreate_balancer_span(ctx) - local is_timing_enabled = ctx.is_timing_enabled + local has_timing = ctx.has_timing - if is_timing_enabled then + if has_timing then req_dyn_hook_run_hooks(ctx, "timing", "before:router") end @@ -1161,7 +1161,7 @@ return { local router = get_updated_router() local match_t = router:exec(ctx) - if is_timing_enabled then + if has_timing then req_dyn_hook_run_hooks(ctx, "timing", "after:router") end @@ -1182,7 +1182,7 @@ return { ctx.workspace = match_t.route and match_t.route.ws_id - if is_timing_enabled then + if has_timing then req_dyn_hook_run_hooks(ctx, "timing", "workspace_id:got", ctx.workspace) end