-
Notifications
You must be signed in to change notification settings - Fork 3
Encapsulation for Go plugin instances [sc-141627] #110
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
base: main
Are you sure you want to change the base?
Conversation
|
This change is part of the following stack: Change managed by git-spice. |
d9607df to
beb6f18
Compare
| // also, the interfaces for input and output plugins. | ||
| package plugin | ||
|
|
||
| import "C" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is coming in from C.size_t use here:
func (p *pluginInstance) callback(data *unsafe.Pointer, csize *C.size_t) int {
If there's some reason we want to contain CGO to cshared.go, that's doable.
| "github.com/calyptia/plugin/metric" | ||
| ) | ||
|
|
||
| var ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the globals are in this var block.
4e14c14 to
f02efa2
Compare
d641376 to
5add7d9
Compare
cbb2a94 to
06cf1dc
Compare
| return input.FLB_ERROR | ||
| } | ||
|
|
||
| func cleanup() int { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Global cleanup logic moved into FLBPluginExit, which was previously calling this.
stoksc
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this looks really good, nice. all questions are just for my own learning.
| initWG.Add(1) | ||
| defer initWG.Done() | ||
| func FLBPluginInit(ptr unsafe.Pointer) (respCode int) { | ||
| currInstanceMu.Lock() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just so i'm following, currInstanceMu replaces initWG? i'm guessing the ordering it looked like it was enforcing was already assured, just needed mutual exclusion?
| if runCancel != nil { | ||
| runCancel() | ||
| runCancel = nil | ||
| currInstanceMu.Lock() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why did the previous code do a trylock and just bail if it didn't work..? would it have left the plugin unpaused?
| p.mu.Lock() | ||
| defer p.mu.Unlock() | ||
|
|
||
| if p.state != instanceStateInitialized { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice that paused can just be initialized
| if p.state == instanceStatePreExit { | ||
| return nil | ||
| } | ||
| if p.state != instanceStateRunnable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i notice this can newly cause FLBPluginOutputPreExit to panic
how concerned are you that there are paths through the state machine that don't make sense / arent really supposed to happen but do
| p.runCancel() | ||
|
|
||
| // Wait for any running callback/flush to finish before closing the message channel | ||
| p.runningWG.Wait() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
noticed this used to not block to. i imagine this is on purpose, but any concern about unintended fallout?
|
obviously it is still in draft, but approved in concept and that once tests are passing think it is great |
This refactors the Go plugin glue code with a few goals in mind:
theInputLockor test-only branching aroundmultiInstance.This cleanly separates the stateless CGO boundary functions in cshared.go, such as
FLBPluginInit, from the stateful implementations. The C interface functions and their behavior are unchanged.The changes are largely:
pluginMetadatastruct.pluginInstancestruct.The new
TestInputCallbackLifecyclegives a sense of how this comes together. This test notably relies on no global state.You can view this PR as a precursor to supporting multiple instances of the same plugin in fluent-bit.