-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
POC: purego plugins (not for merge) #6520
Conversation
PR Reviewer Guide 🔍
|
PR Code Suggestions ✨
|
API Changes --- prev.txt 2024-09-16 16:23:18.253582937 +0000
+++ current.txt 2024-09-16 16:23:15.153562093 +0000
@@ -10836,15 +10836,18 @@
FUNCTIONS
-func GetAnalyticsHandler(path string, symbol string) (func(record *analytics.AnalyticsRecord), error)
-func GetHandler(path string, symbol string) (http.HandlerFunc, error)
+func GetAnalyticsHandler(name string, symbol string) (func(record *analytics.AnalyticsRecord), error)
+func GetHandler(modulePath string, symbol string) (http.HandlerFunc, error)
func GetPluginFileNameToLoad(pluginStorage storage, pluginPath string) (string, error)
GetPluginFileNameToLoad check which file to load based on name, tyk version,
os and architecture but it also takes care of returning the name of the file
that exists
-func GetResponseHandler(path string, symbol string) (func(rw http.ResponseWriter, res *http.Response, req *http.Request), error)
+func GetResponseHandler(modulePath string, symbol string) (func(rw http.ResponseWriter, res *http.Response, req *http.Request), error)
func GetSymbol(modulePath string, symbol string) (interface{}, error)
+ GetSymbol only tests plugin loading. Used in tyk plugin cli. Don't encourage
+ internal use.
+
TYPES
|
Quality Gate failedFailed conditions |
User description
PR uses purego to replace dlopen, which has libc couplings. Attempt a static build with plugin functionality.
CGO_ENABLED=0
and -cflags to produce a static buildStatus: Blocked, more info.
The build does compile to a static binary, so there is some success (as expected).
The main issue is that just stubbing out dlopen doesn't give us full plugin compatibility. Restrictions around purego make it look like they would only be able to consume C plugins, but some type conversions are hinted at: https://pkg.go.dev/github.com/ebitengine/purego#RegisterFunc ; Things here get blurry, but at least a few things are omitted from the internal plugin fork:
Folow up with:
func(w http.ResponseWriter, r *httpRequest)
? It doesn't seem possible because there's still purego limiting us here. Depends on plugin internals.init
, and other concernsPR Type
enhancement, tests
Description
dlopen
anddlsym
withpurego
for plugin loading and symbol resolution.plugin2
to handle plugin operations.go.mod
andgo.sum
to include thepurego
dependency.Changes walkthrough 📝
analyticsplugin.go
Replace plugin.Open with plugin2.Open in analyticsplugin
goplugin/analyticsplugin.go
plugin.Open
withplugin2.Open
.plugin2
.goplugin.go
Replace plugin.Open with plugin2.Open in goplugin
goplugin/goplugin.go
plugin.Open
withplugin2.Open
.plugin2
.plugin.go
Add new plugin package with Open and Lookup functions
internal/plugins2/plugin.go
Open
andLookup
functions.Plugin
andSymbol
types.plugin_purego.go
Implement plugin loading using purego
internal/plugins2/plugin_purego.go
purego.Dlopen
andpurego.Dlsym
.plugin_test.go
Add basic test for plugin package import
internal/plugins2/plugin_test.go
go.mod
Add purego dependency to go.mod
go.mod
github.com/ebitengine/purego
.go.sum
Update go.sum with purego checksums
go.sum
purego
dependency.