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: add EmmyLuaDebugger hook #12899

Merged
merged 1 commit into from
Apr 29, 2024
Merged

feat: add EmmyLuaDebugger hook #12899

merged 1 commit into from
Apr 29, 2024

Conversation

hanshuebner
Copy link
Contributor

@hanshuebner hanshuebner commented Apr 22, 2024

Summary

The change provides a hook in the init_worker phase to start the EmmyLua debugger. The debugger is enabled by setting the KONG_EMMY_DEBUGGER to the absolute pathname of the EmmyLuaDebugger shared library (e.g. /usr/local/bin/emmy_core.dylib). The host and port that the debugger interface listens on can be defined by setting the KONG_EMMY_DEBUGGER_HOST and KONG_EMMY_DEBUGGER_PORT environment variables, respectively.

If the environment variable KONG_EMMY_DEBUGGER_WAIT is set, the debugger hook waits for the IDE to connect at the beginning of the worker startup process to allow debugging of startup issues.

Kong should be started withKONG_NGINX_WORKER_PROCESSES set to 1 to enable only one worker process. Debugging multiple worker processes is not supported.

This feature is based on work by @mehuled, published in
https://dev.to/mehuled/breakpoint-debugging-with-kong-plugin-development-75a

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 - PUT DOCS PR HERE

KAG-4316

@github-actions github-actions bot added the cherry-pick kong-ee schedule this PR for cherry-picking to kong/kong-ee label Apr 22, 2024
@pull-request-size pull-request-size bot added size/L and removed size/M labels Apr 24, 2024
@hanshuebner hanshuebner force-pushed the feat/emmy-lua-debugger branch 3 times, most recently from 21a587b to 78e96a6 Compare April 24, 2024 15:37
dndx
dndx previously requested changes Apr 25, 2024
kong/init.lua Outdated Show resolved Hide resolved
@hanshuebner hanshuebner marked this pull request as ready for review April 25, 2024 06:50
@hanshuebner hanshuebner requested a review from dndx April 25, 2024 06:51
@hanshuebner hanshuebner force-pushed the feat/emmy-lua-debugger branch 2 times, most recently from fb32b72 to 555551d Compare April 25, 2024 07:36
@dndx dndx requested a review from bungle April 25, 2024 07:46
kong/tools/emmy_debugger.lua Outdated Show resolved Hide resolved
Copy link
Member

@gszr gszr left a comment

Choose a reason for hiding this comment

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

Very nice addition, @hanshuebner! Wondering if this shouldn't be loaded along with luacov -- see https://github.com/kong/kong/blob/38ddd0e203240cdb1d6c5352ea4b5dca9de0ce51/kong/templates/nginx_kong.lua#L43. Maybe introducing a "dev" mode would be appropriate?

@hanshuebner
Copy link
Contributor Author

@gszr writes:

Maybe introducing a "dev" mode would be appropriate?

I'm not quite sure - luacov seems to be useful when running (all) tests, while the debugger really only helps in interactive mode. Also, if I understand you well, you're suggesting that a "dev" mode should exist which enables certain things. We'd have to ship EmmyLuaDebugger in that case, otherwise one would have to enable "dev" mode and specify the location of the debugger shared library. If it'd be the other way round and setting KONG_EMMY_DEBUGGER would enable "dev" mode, I'd find that to be kind of awkward as well.

I think debuggers are most useful if they require little or no setup. I think with the current setup, it is possible to always set the KONG_EMMY_DEBUGGER and KONG_NGINX_WORKER_PROCESSES variable (i.e. in .profile) and thus basically always have the debugger available. This could certainly work with a "dev" mode as well, but I'm not certain as to what that should exactly encompass.

bungle
bungle previously requested changes Apr 25, 2024
Copy link
Member

@bungle bungle left a comment

Choose a reason for hiding this comment

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

Just checking.

kong/tools/emmy_debugger.lua Outdated Show resolved Hide resolved
@hanshuebner hanshuebner force-pushed the feat/emmy-lua-debugger branch 2 times, most recently from 502ebb7 to 8f17e34 Compare April 25, 2024 11:04
@hanshuebner hanshuebner requested a review from bungle April 25, 2024 12:58
@hanshuebner hanshuebner force-pushed the feat/emmy-lua-debugger branch 2 times, most recently from 030167d to 1c5661c Compare April 25, 2024 15:48
Copy link
Contributor

@jschmid1 jschmid1 left a comment

Choose a reason for hiding this comment

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

successfully tested on Ubuntu 22.04.

Ubuntu 20.04's GLIBC version is too low however. We may want to include glibc version requirements in the docs at some point.

The change provides a hook in the init_worker phase to start the
EmmyLua debugger.  The debugger is enabled by setting the
`KONG_EMMY_DEBUGGER` to the absolute pathname of the EmmyLuaDebugger
shared library (e.g. /usr/local/bin/emmy_core.dylib).  The host and
port that the debugger interface listens on can be defined by setting
the `KONG_EMMY_DEBUGGER_HOST` and `KONG_EMMY_DEBUGGER_PORT`
environment variables, respectively.

If the environment variable `KONG_EMMY_DEBUGGER_WAIT` is set, the
debugger hook waits for the IDE to connect at the beginning of the
worker startup process to allow debugging of startup issues.

Kong should be started with KONG_NGINX_WORKER_PROCESSES set to 1 to
enable only one worker process.  Debugging multiple worker processes
is not supported.

This feature is based on work by @mehuled, published in
https://dev.to/mehuled/breakpoint-debugging-with-kong-plugin-development-75a
@hanshuebner
Copy link
Contributor Author

Ubuntu 20.04's GLIBC version is too low however. We may want to include glibc version requirements in the docs at some point.

I've added a paragraph to DEVELOPER.md.

@hanshuebner hanshuebner dismissed stale reviews from bungle and dndx April 29, 2024 18:23

Comment resolved - cpath is now only changed while loading debugger

@hanshuebner hanshuebner merged commit a554d36 into master Apr 29, 2024
25 checks passed
@hanshuebner hanshuebner deleted the feat/emmy-lua-debugger branch April 29, 2024 18:24
@team-gateway-bot
Copy link
Collaborator

Successfully created cherry-pick PR for master:

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/docs size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants