Skip to content
Closed
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
7 changes: 7 additions & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ globals = {
"_KONG",
"kong",
"ngx.IS_CLI",
"ngx.DEBUG_CORE",
"ngx.DEBUG_ALLOC",
"ngx.DEBUG_MUTEX",
"ngx.DEBUG_EVENT",
"ngx.DEBUG_HTTP",
"ngx.DEBUG_MAIL",
"ngx.DEBUG_STREAM",
}


Expand Down
7 changes: 7 additions & 0 deletions changelog/unreleased/kong/feat-extra-debug-modes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
message: |
Expose seven additional Nginx log levels that are not normally
exposed by OpenResty, which allows for finer-grained debugging
with less noise in the debug-level logs: `debug_core`, `debug_alloc`,
`debug_mutex`, `debug_event`, `debug_http`, `debug_mail`, `debug_stream`.
type: feature
scope: Configuration
6 changes: 6 additions & 0 deletions kong.conf.default
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@

#log_level = notice # Log level of the Nginx server. Logs are
# found at `<prefix>/logs/error.log`.
# Supported values are: `debug`, `info`,
# `notice`, `warn`, `error`, `crit`, `alert`,
# `emerg`, `debug_core`, `debug_alloc`,
# `debug_mutex`, `debug_event`, `debug_http`,
# `debug_mail`, `debug_stream`.


# See http://nginx.org/en/docs/ngx_core_module.html#error_log for a list
# of accepted values.
Expand Down
7 changes: 7 additions & 0 deletions kong/conf_loader/constants.lua
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,13 @@ local CONF_PARSERS = {
"crit",
"alert",
"emerg",
"debug_core",
"debug_alloc",
"debug_mutex",
"debug_event",
"debug_http",
"debug_mail",
"debug_stream",
}
},
vaults = { typ = "array" },
Expand Down
22 changes: 22 additions & 0 deletions kong/constants.lua
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ for k in pairs(key_formats_map) do
key_formats[#key_formats + 1] = k
end

ngx.DEBUG_CORE = 0x010
ngx.DEBUG_ALLOC = 0x020
ngx.DEBUG_MUTEX = 0x040
ngx.DEBUG_EVENT = 0x080
ngx.DEBUG_HTTP = 0x100
ngx.DEBUG_MAIL = 0x200
ngx.DEBUG_STREAM = 0x400

local constants = {
CJSON_MAX_PRECISION = 16,
BUNDLED_PLUGINS = plugin_map,
Expand Down Expand Up @@ -244,6 +252,20 @@ local constants = {
crit = ngx.CRIT,
alert = ngx.ALERT,
emerg = ngx.EMERG,
debug_core = ngx.DEBUG_CORE,
debug_alloc = ngx.DEBUG_ALLOC,
debug_mutex = ngx.DEBUG_MUTEX,
debug_event = ngx.DEBUG_EVENT,
debug_http = ngx.DEBUG_HTTP,
debug_mail = ngx.DEBUG_MAIL,
debug_stream = ngx.DEBUG_STREAM,
[ngx.DEBUG_CORE] = "debug_core",
[ngx.DEBUG_ALLOC] = "debug_alloc",
[ngx.DEBUG_MUTEX] = "debug_mutex",
[ngx.DEBUG_EVENT] = "debug_event",
[ngx.DEBUG_HTTP] = "debug_http",
[ngx.DEBUG_MAIL] = "debug_mail",
[ngx.DEBUG_STREAM] = "debug_stream",
[ngx.DEBUG] = "debug",
[ngx.INFO] = "info",
[ngx.NOTICE] = "notice",
Expand Down
30 changes: 30 additions & 0 deletions spec/02-integration/04-admin_api/22-debug_spec.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
local helpers = require("spec.helpers")
local cjson = require("cjson")
local fmt = string.format
require("kong.constants")

local strategies = {}
for _, strategy in helpers.each_strategy() do
Expand Down Expand Up @@ -169,6 +170,35 @@ describe("Admin API - Kong debug route with strategy #" .. strategy, function()
-- from timers pre-created by timer-ng (datadog plugin)
assert.logfile().has.no.line("failed to send data to", true, 2)

--[[
-- TODO: needs https://github.com/Kong/lua-kong-nginx-module/pull/87

-- can change to Nginx fine-grained debug levels (debug_mail)
res = assert(helpers.admin_client():send {
method = "PUT",
path = "/debug/node/log-level/debug_mail",
})
body = assert.res_status(200, res)
json = cjson.decode(body)
message = "log level changed"
assert(json.message == message)

-- make sure we changed to debug
helpers.wait_until(function()
res = assert(helpers.admin_client():send {
method = "GET",
path = "/debug/node/log-level",
})
body = assert.res_status(200, res)
json = cjson.decode(body)
message = "log level: debug_mail"
return json.message == message
end, 30)

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

--]]

-- go back to default (debug)
res = assert(helpers.admin_client():send {
method = "PUT",
Expand Down