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

feat(conf): support Nginx fine-grained debug levels #12842

Closed
wants to merge 2 commits into from

Conversation

hishamhm
Copy link
Contributor

@hishamhm hishamhm commented Apr 9, 2024

Summary

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.

By setting a quieter value such as debug_mail, Kong Gateway debug logs are usable again, as the Kong (and WasmX) logs are still shown, but the other Nginx debug logs (memory allocations, etc.) are not shown.

Checklist

  • The Pull Request has tests
  • A changelog file has been created under changelog/unreleased/kong or skip-changelog label added on PR if changelog is unnecessary. README.md
  • There is a user-facing docs PR against https://github.com/Kong/docs.konghq.com - updated docs are auto-generated from kong.conf.default

Support for dynamically setting these additional levels depends on this companion PR for lua-kong-nginx-module: Kong/lua-kong-nginx-module#87

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`.
Dynamically enabling the extended debug log levels requires a
new version of lua-kong-nginx-module which incorporates
Kong/lua-kong-nginx-module#87
@hishamhm hishamhm force-pushed the feat/extra-debug-modes branch from 0926b64 to e8defcb Compare April 9, 2024 21:03
@hishamhm hishamhm marked this pull request as ready for review April 9, 2024 21:19
@hishamhm
Copy link
Contributor Author

hishamhm commented Apr 9, 2024

If Kong/lua-kong-nginx-module#87 gets merged and the lua-kong-nginx-module is bumped, then the second commit from this branch (e8defcb) can be removed, and extended debug modes will work both statically and dynamically.

As this PR stands right now, these extra debug_* log levels now work only statically (e.g. export KONG_LOG_LEVEL=debug_mail, etc.); I've been using this extensively in the past weeks to get readable debug logs when working on WasmX running in Kong Gateway.

@bungle
Copy link
Member

bungle commented Apr 12, 2024

@hishamhm, freaky, what is DEBUG_MAIL is that something that is reserved when using nginx just with mail module, aka mail { } that we don't have?

@bungle
Copy link
Member

bungle commented Apr 12, 2024

Kong Gateway debug logs are usable again

@hishamhm I suggest you add:

build --//:debug=false

in HOME/.bazelrc (I think we should by default build without debug, it is so rarely usable - both on CI and local)

But in case you want that still, then perhaps the new debug levels make sense?

@bungle
Copy link
Member

bungle commented Apr 12, 2024

It is also strange that DEBUG_MAIL is quieter as it is 512 level, while normal DEBUG is 8 and ERR is 4. Are these also used as some kind of bit mask (I guess so)?

@hishamhm
Copy link
Contributor Author

@hishamhm, freaky, what is DEBUG_MAIL is that something that is reserved when using nginx just with mail module, aka mail { } that we don't have?

@bungle Yes, so it never shows up and it quiets down the other C-level nginx debug logs, leaving only the debug logs we care about (OpenResty+Kong and WasmX).

build --//:debug=false

I'll try that out, thanks!! @locao, was that the local trick you were referring to?

(I think we should by default build without debug, it is so rarely usable - both on CI and local)
But in case you want that still, then perhaps the new debug levels make sense?

Kong packages/containers are already built like that right? So if I have a way to do that locally (and I can never see those gazillion malloc messages again :) ), then that bazel setting would address my issue (and yes, it should probably be the default, as the common case for Kong debugging is not debugging Nginx itself).

(True story: I forgot a Kong instance running idle on my local machine after a day of debugging and woke up the next day to find everything failing on my machine due to zero disk space... twice!)

@bungle
Copy link
Member

bungle commented Apr 16, 2024

Kong packages/containers are already built like that right?

Kong distributions (those that we ship) are build without debug aka with --//:debug=false, AFAIK (need a confirmation). But for some reason this debug thing is enabled on local builds and I think CI. There is a slack thread somewhere with arguments on it. The noise level has gone down a bit with --//:debug=false.

@locao
Copy link
Contributor

locao commented Jun 12, 2024

@locao, was that the local trick you were referring to?

Yes, it will silence the C-level logs.

(After two months I am sure you already tested it, but maybe someone else can benefit from it 😁)

@hishamhm
Copy link
Contributor Author

@locao Indeed, thanks! Given those tips serve as a usable alternative, I think we can retire this PR!

@hishamhm hishamhm closed this Jun 13, 2024
@hishamhm hishamhm deleted the feat/extra-debug-modes branch June 13, 2024 17:29
@thibaultcha
Copy link
Member

But in case you want that still, then perhaps the new debug levels make sense?

Hmm too bad, this is precisely why those debug levels are painful to us. When working on an Nginx module embedded in the Gateway (be it kong-lua-module or ngx-wasm-module), we still want our module's debug logs be enabled, while still silencing the other Nginx debug logs that Hisham mentioned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cherry-pick kong-ee schedule this PR for cherry-picking to kong/kong-ee core/configuration size/M
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants