Skip to content
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

[Backport release/3.5.x] fix(request-debugging): fix can't set root properties when enable the phase filter #12149

Merged
merged 2 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 46 additions & 46 deletions kong/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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
Expand All @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -1122,17 +1122,17 @@ 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


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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -1211,17 +1211,17 @@ 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


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

Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -1600,17 +1600,17 @@ 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


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

Expand Down Expand Up @@ -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

Expand All @@ -1691,17 +1691,17 @@ 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


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

Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion kong/resty/dns/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions kong/runloop/handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1151,17 +1151,17 @@ 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

-- routing request
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

Expand All @@ -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

Expand Down
4 changes: 0 additions & 4 deletions kong/timing/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,6 @@ end


function _M.set_root_context_prop(k, v)
if not should_run() then
return
end

ngx.ctx.req_trace_ctx:set_root_context_prop(k, v)
end

Expand Down