Skip to content

Commit

Permalink
fix(*): fix worker notice logging when setting dynamic log level (#10897
Browse files Browse the repository at this point in the history
)

This PR fixes a bug when worker consuming dynamic log level setting event and using a wrong reference for notice logging

```
2023/05/18 14:29:06 [error] 23010#0: *3 [lua] callback.lua:98: do_handlerlist(): worker-events: event callback failed; source=debug, event=log_level, wid=0 error='./kong/runloop/handler.lua:937: bad argument #2 to 'log' (expected table to have __tostring metamethod)
stack traceback:
        [C]: in function 'log'
        ./kong/runloop/handler.lua:937: in function <./kong/runloop/handler.lua:925>
        [C]: in function 'xpcall'
        ...uild/kong-dev/openresty/lualib/resty/events/callback.lua:83: in function 'do_handlerlist'
        ...uild/kong-dev/openresty/lualib/resty/events/callback.lua:130: in function 'do_event'
        .../build/kong-dev/openresty/lualib/resty/events/worker.lua:68: in function 'do_event'
        .../build/kong-dev/openresty/lualib/resty/events/worker.lua:239: in function <.../build/kong-dev/openresty/lualib/resty/events/worker.lua:221>', data={"timeout":60,"log_level":8}, context: ngx.timer
```
  • Loading branch information
windmgc authored May 19, 2023
1 parent c7d2820 commit 76170a1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@

#### Core

- Fix a bug when worker consuming dynamic log level setting event and using a wrong reference for notice logging
[#10897](https://github.com/Kong/kong/pull/10897)

#### Admin API

#### Plugins
Expand Down
8 changes: 4 additions & 4 deletions kong/runloop/handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ local DEFAULT_MATCH_LRUCACHE_SIZE = Router.DEFAULT_MATCH_LRUCACHE_SIZE


local kong_shm = ngx.shared.kong
local PLUGINS_REBUILD_COUNTER_KEY =
local PLUGINS_REBUILD_COUNTER_KEY =
constants.PLUGINS_REBUILD_COUNTER_KEY
local ROUTERS_REBUILD_COUNTER_KEY =
local ROUTERS_REBUILD_COUNTER_KEY =
constants.ROUTERS_REBUILD_COUNTER_KEY


Expand Down Expand Up @@ -495,7 +495,7 @@ end
local new_plugins_iterator
do
local PluginsIterator_new = PluginsIterator.new
new_plugins_iterator = function(version)
new_plugins_iterator = function(version)
local plugin_iterator, err = PluginsIterator_new(version)
if not plugin_iterator then
return nil, err
Expand Down Expand Up @@ -934,7 +934,7 @@ return {
return
end

log(NOTICE, "log level changed to ", data, " for worker ", worker)
log(NOTICE, "log level changed to ", data.log_level, " for worker ", worker)
end, "debug", "log_level")
end

Expand Down
3 changes: 3 additions & 0 deletions spec/02-integration/04-admin_api/22-debug_spec.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local helpers = require("spec.helpers")
local cjson = require("cjson")
local fmt = string.format

local strategies = {}
for _, strategy in helpers.each_strategy() do
Expand Down Expand Up @@ -183,6 +184,8 @@ describe("Admin API - Kong debug route with strategy #" .. strategy, function()
return json.message == message
end, 30)

assert.logfile().has.line(fmt("log level changed to %s", ngx.DEBUG), true, 2)

-- e2e test: we are printing higher than debug
helpers.clean_logfile()
res = assert(helpers.proxy_client():send {
Expand Down

1 comment on commit 76170a1

@khcp-gha-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bazel Build

Docker image available kong/kong:76170a1bc2130dc719f149094559b63877c4b34d
Artifacts available https://github.com/Kong/kong/actions/runs/5021968370

Please sign in to comment.