-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
refactor(pluginservers): code refactor & testing #12858
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
github-actions
bot
added
core/language/go
core/proxy
core/configuration
core/language/python
core/language/js
chore
Not part of the core functionality of kong, but still needed
cherry-pick kong-ee
schedule this PR for cherry-picking to kong/kong-ee
labels
Apr 13, 2024
gszr
force-pushed
the
chore/plugin-server-improvements
branch
2 times, most recently
from
April 13, 2024 13:29
50d7d76
to
38ddd0e
Compare
hanshuebner
approved these changes
Apr 24, 2024
gszr
force-pushed
the
chore/plugin-server-improvements
branch
3 times, most recently
from
September 24, 2024 20:13
16a4581
to
dcad94d
Compare
gszr
force-pushed
the
chore/plugin-server-improvements
branch
2 times, most recently
from
October 10, 2024 16:09
5b3e1df
to
4807471
Compare
gszr
force-pushed
the
chore/plugin-server-improvements
branch
3 times, most recently
from
October 10, 2024 17:55
318a540
to
1ca4b8b
Compare
gszr
force-pushed
the
chore/plugin-server-improvements
branch
3 times, most recently
from
October 10, 2024 18:01
3e69461
to
2245cde
Compare
brentos
reviewed
Oct 10, 2024
brentos
reviewed
Oct 10, 2024
brentos
reviewed
Oct 10, 2024
brentos
reviewed
Oct 11, 2024
gszr
force-pushed
the
chore/plugin-server-improvements
branch
6 times, most recently
from
October 15, 2024 17:41
65c0931
to
748ebc3
Compare
Context ------- The overall goal of this commit is to refactor the external plugins implementation, with the following goals in mind: - Make plugin server code more approachable to unfamiliar engineers and easier to evolve with confidence - Harden configuration; ensure configuration defects are caught before Kong is started - Extend testing coverage This is related to ongoing work on the Go PDK, with similar goals in mind. Summary ------- This commit implements the following overall changes to plugin server code: - Move configuration related code into conf loader, so that configuration loading and validation happens at startup time, rather than lazily, when plugin data is loaded or pluginservers are started. Add tests for current behavior. - Move process-management code - for starting up plugin servers as well as querying external plugins info - into the `process.lua` module. - Introduce a `kong.runloop.plugin_servers.rpc` module that encapsulates RPC initialization and protocol-specific implementations. This further simplifies the main plugin server main module. - Factor exposed API and phase handlers bridging code into a new `plugin` module, which encapsulates an external plugin representation, including the expected fields for any Kong plugin, plus external plugin-specific bits, such as the RPC instance. Part of this external plugin-specific part is the instance life cycle management. With this structure, the `kong.runloop.plugin_servers` main module contains only general external plugin code, including a list of loaded external plugins, and associated start/stop functions for plugin servers. Testing ------- This commit also implements the following improvements to tests: - Restructure fixtures to accommodate new external plugin servers -- namely, targeting for now in the existing Python and Javascript - Add new test cases for external plugins: * External plugin configuration: add test cases for current behavior; in particular: - Fail if no `query_cmd` is provided; - Warn if no `start_cmd` is provided - this is by design, as external plugins servers can be managed outside of Kong * Plugin server start / stop - for both Go and Python plugins * External plugin info querying for both Go and Python plugins * External plugin execution - for both Go and Python plugins Internal flow ------------- `.plugin_servers.init:` loads all external plugins, by calling .plugin_servers.process and `.plugin_servers.plugin` `.plugin_servers.process`: queries external plugins info with the command specified in `_query_cmd` proeprties `.plugin_servers.plugin`: with info obtained as described above, `.plugin:new` returns a kong-compatible representation of an external plugin, with phase handlers, PRIORITY, and wrappers to the PDK. Calls `.plugin_servers.rpc` to create an RPC through which Kong communicates with the plugin process `.plugin_servers.rpc`: based on info contained in the plugin (protocol field), creates the correct RPC for the given external plugin `.plugin_servers.rpc.pb_rpc`: protobuf rpc implementation - used by Golang `.plugin_servers.rpc.mp.rpc`: messagepack rpc implementation - used by JS and Python `.plugin_servers.init`: calls `.plugin_servers.process` to start external plugin servers `.plugin_servers.process`: optionally starts all external plugin servers (if a `_start_cmd` is found) uses the resty pipe API to manage the external plugin process
gszr
force-pushed
the
chore/plugin-server-improvements
branch
from
October 15, 2024 21:25
748ebc3
to
be40499
Compare
brentos
approved these changes
Oct 22, 2024
flrgh
reviewed
Nov 6, 2024
locao
approved these changes
Nov 6, 2024
Cherry-pick failed for Please cherry-pick the changes locally. git remote add upstream https://github.com/kong/kong-ee
git fetch upstream master
git worktree add -d .worktree/cherry-pick-12858-to-master-to-upstream upstream/master
cd .worktree/cherry-pick-12858-to-master-to-upstream
git checkout -b cherry-pick-12858-to-master-to-upstream
ancref=$(git merge-base 9ae36382db4b9485f8889b8cd80d66a0885c86e7 be4049980e16448b609a00b6a1f7453013d57fcf)
git cherry-pick -x $ancref..be4049980e16448b609a00b6a1f7453013d57fcf |
github-actions
bot
added
the
incomplete-cherry-pick
A cherry-pick was incomplete and needs manual intervention
label
Nov 13, 2024
locao
removed
the
incomplete-cherry-pick
A cherry-pick was incomplete and needs manual intervention
label
Nov 18, 2024
lhanjian
pushed a commit
that referenced
this pull request
Dec 23, 2024
Context ------- The overall goal of this commit is to refactor the external plugins implementation, with the following goals in mind: - Make plugin server code more approachable to unfamiliar engineers and easier to evolve with confidence - Harden configuration; ensure configuration defects are caught before Kong is started - Extend testing coverage This is related to ongoing work on the Go PDK, with similar goals in mind. Summary ------- This commit implements the following overall changes to plugin server code: - Move configuration related code into conf loader, so that configuration loading and validation happens at startup time, rather than lazily, when plugin data is loaded or pluginservers are started. Add tests for current behavior. - Move process-management code - for starting up plugin servers as well as querying external plugins info - into the `process.lua` module. - Introduce a `kong.runloop.plugin_servers.rpc` module that encapsulates RPC initialization and protocol-specific implementations. This further simplifies the main plugin server main module. - Factor exposed API and phase handlers bridging code into a new `plugin` module, which encapsulates an external plugin representation, including the expected fields for any Kong plugin, plus external plugin-specific bits, such as the RPC instance. Part of this external plugin-specific part is the instance life cycle management. With this structure, the `kong.runloop.plugin_servers` main module contains only general external plugin code, including a list of loaded external plugins, and associated start/stop functions for plugin servers. Testing ------- This commit also implements the following improvements to tests: - Restructure fixtures to accommodate new external plugin servers -- namely, targeting for now in the existing Python and Javascript - Add new test cases for external plugins: * External plugin configuration: add test cases for current behavior; in particular: - Fail if no `query_cmd` is provided; - Warn if no `start_cmd` is provided - this is by design, as external plugins servers can be managed outside of Kong * Plugin server start / stop - for both Go and Python plugins * External plugin info querying for both Go and Python plugins * External plugin execution - for both Go and Python plugins Internal flow ------------- `.plugin_servers.init:` loads all external plugins, by calling .plugin_servers.process and `.plugin_servers.plugin` `.plugin_servers.process`: queries external plugins info with the command specified in `_query_cmd` proeprties `.plugin_servers.plugin`: with info obtained as described above, `.plugin:new` returns a kong-compatible representation of an external plugin, with phase handlers, PRIORITY, and wrappers to the PDK. Calls `.plugin_servers.rpc` to create an RPC through which Kong communicates with the plugin process `.plugin_servers.rpc`: based on info contained in the plugin (protocol field), creates the correct RPC for the given external plugin `.plugin_servers.rpc.pb_rpc`: protobuf rpc implementation - used by Golang `.plugin_servers.rpc.mp.rpc`: messagepack rpc implementation - used by JS and Python `.plugin_servers.init`: calls `.plugin_servers.process` to start external plugin servers `.plugin_servers.process`: optionally starts all external plugin servers (if a `_start_cmd` is found) uses the resty pipe API to manage the external plugin process (cherry picked from commit f88da7d)
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
chore
Not part of the core functionality of kong, but still needed
core/configuration
core/language/go
core/language/js
core/language/python
core/proxy
size/XXL
skip-changelog
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context
The overall goal of this commit is to refactor the external plugins
implementation, with the following goals in mind:
easier to evolve with confidence
Kong is started
This is related to ongoing work on the Go PDK, with similar goals in
mind.
Summary
This commit implements the following overall changes to plugin server
code:
Move configuration related code into conf loader, so that configuration
loading and validation happens at startup time, rather than lazily, when
plugin data is loaded or pluginservers are started. Add tests for
current behavior.
Move process-management code - for starting up plugin servers as well
as querying external plugins info - into the
process.lua
module.Introduce a
kong.runloop.plugin_servers.rpc
module that encapsulatesRPC initialization and protocol-specific implementations. This further
simplifies the main plugin server main module.
Factor exposed API and phase handlers bridging code into a new
plugin
module, which encapsulates an external plugin representation, including
the expected fields for any Kong plugin, plus external plugin-specific
bits, such as the RPC instance. Part of this external plugin-specific part
is the instance life cycle management. With this structure, the
kong.runloop.plugin_servers
main module contains only general external plugin code, including a list
of loaded external plugins, and associated start/stop functions for
plugin servers.
Testing
This commit also implements the following improvements to tests:
namely, targeting for now in the existing Python and Javascript
in particular:
query_cmd
is provided;start_cmd
is provided - this is by design, asexternal plugins servers can be managed outside of Kong
KAG-2496