From 9bc2faa1ffea93f97459f277fa33626c0c5d9010 Mon Sep 17 00:00:00 2001 From: Qi Date: Tue, 27 Feb 2024 10:16:23 +0800 Subject: [PATCH] fix(request-debugging): add missing `router` section of the timing output (#12234) (cherry picked from commit 184250b6f1e99bbd4447f5d9bf541ba2f8362f65) --- .../fix-missing-router-section-of-request-debugging.yml | 3 +++ kong/timing/init.lua | 8 ++++++++ .../21-request-debug/01-request-debug_spec.lua | 4 ++++ 3 files changed, 15 insertions(+) create mode 100644 changelog/unreleased/kong/fix-missing-router-section-of-request-debugging.yml diff --git a/changelog/unreleased/kong/fix-missing-router-section-of-request-debugging.yml b/changelog/unreleased/kong/fix-missing-router-section-of-request-debugging.yml new file mode 100644 index 000000000000..7ae106f21bb3 --- /dev/null +++ b/changelog/unreleased/kong/fix-missing-router-section-of-request-debugging.yml @@ -0,0 +1,3 @@ +message: Fix the missing router section for the output of the request-debugging +type: bugfix +scope: Core diff --git a/kong/timing/init.lua b/kong/timing/init.lua index 8b15304c319b..9b9c5df3199b 100644 --- a/kong/timing/init.lua +++ b/kong/timing/init.lua @@ -306,6 +306,14 @@ function _M.register_hooks() _M.leave_context() -- leave plugin_id _M.leave_context() -- leave plugin_name end) + + req_dyn_hook.hook("timing", "before:router", function() + _M.enter_context("router") + end) + + req_dyn_hook.hook("timing", "after:router", function() + _M.leave_context() -- leave router + end) end diff --git a/spec/02-integration/21-request-debug/01-request-debug_spec.lua b/spec/02-integration/21-request-debug/01-request-debug_spec.lua index 8be19151782d..13d626f474cd 100644 --- a/spec/02-integration/21-request-debug/01-request-debug_spec.lua +++ b/spec/02-integration/21-request-debug/01-request-debug_spec.lua @@ -535,6 +535,7 @@ describe(desc, function() assert.truthy(header_output.child.rewrite) assert.truthy(header_output.child.access) assert.truthy(header_output.child.access.child.dns) -- upstream is resolved in access phase + assert.truthy(header_output.child.access.child.router) -- router is executed in access phase assert(header_output.child.access.child.dns.child.localhost.child.resolve.cache_hit ~= nil, "dns cache hit should be recorded") assert.truthy(header_output.child.balancer) assert.truthy(header_output.child.header_filter) @@ -542,6 +543,7 @@ describe(desc, function() assert.truthy(log_output.child.rewrite) assert.truthy(log_output.child.access) assert.truthy(log_output.child.access.child.dns) -- upstream is resolved in access phase + assert.truthy(log_output.child.access.child.router) -- router is executed in access phase assert(log_output.child.access.child.dns.child.localhost.child.resolve.cache_hit ~= nil, "dns cache hit should be recorded") assert.truthy(log_output.child.balancer) assert.truthy(log_output.child.header_filter) @@ -573,11 +575,13 @@ describe(desc, function() assert.truthy(header_output.child.rewrite) assert.truthy(header_output.child.access) assert.truthy(header_output.child.access.child.dns) -- upstream is resolved in access phase + assert.truthy(header_output.child.access.child.router) -- router is executed in access phase assert.truthy(header_output.child.response) assert.truthy(log_output.child.rewrite) assert.truthy(log_output.child.access) assert.truthy(log_output.child.access.child.dns) -- upstream is resolved in access phase + assert.truthy(header_output.child.access.child.router) -- router is executed in access phase assert.truthy(log_output.child.body_filter) assert.truthy(log_output.child.log)