@@ -27,30 +27,33 @@ var (
2727
2828 // Current plugin metadata. This is nil if the plugin has not been registered yet.
2929 // This is set by the RegisterInput, RegisterOutput, or RegisterCustom functions.
30- pluginMeta atomic.Pointer [pluginMetadata ]
30+ pluginMeta atomic.Pointer [pluginMetadata ]
31+ unregisterFunc atomic.Pointer [func ()]
32+
33+ // currInstanceMu guards access to currInstance
34+ currInstanceMu sync.Mutex
35+ // Current instance of the plugin, used by functions called from fluent-bit like FLBPluginInit.
36+ currInstance * pluginInstance
3137)
3238
3339// pluginMeta describes a plugin and exposes hooks into its implementation.
3440type pluginMetadata struct {
35- name string
36- desc string
41+ name string
42+ desc string
43+
44+ // Exactly one of the following will be set:
3745 input InputPlugin
3846 output OutputPlugin
3947 custom CustomPlugin
4048}
4149
42- var (
43- currInstanceMu sync.Mutex // Guards access to currInstance
44- currInstance * pluginInstance
45- )
46-
4750type instanceState string
4851
4952const (
53+ instanceStateCreated instanceState = ""
5054 instanceStateInitialized instanceState = "initialized"
5155 instanceStateRunnable instanceState = "runnable"
5256 instanceStatePreExit instanceState = "preExit"
53- instanceStateStopped instanceState = "stopped"
5457)
5558
5659type retryableError error
@@ -75,31 +78,38 @@ func newPluginInstance(meta pluginMetadata) *pluginInstance {
7578 configLoaderProvider : func (ptr unsafe.Pointer ) ConfigLoader {
7679 return & flbInputConfigLoader {ptr : ptr }
7780 },
81+ state : instanceStateCreated ,
7882 }
7983}
8084
85+ // pluginInstance is an instance of a plugin.
8186type pluginInstance struct {
8287 meta pluginMetadata
8388 cmetricsCtxProvider cmetricsContextProvider
8489 configLoaderProvider configLoaderProvider
8590
86- mu sync.RWMutex
91+ mu sync.RWMutex // Protects all members below:
8792 state instanceState
8893 runCtx context.Context
8994 runCancel context.CancelFunc
9095 msgChannel chan Message
9196}
9297
98+ // withCMetricsContextProvider overrides the cmetricsContextProvider.
99+ // This must be called immediately after creating the instance.
93100func (p * pluginInstance ) withCMetricsContextProvider (provider cmetricsContextProvider ) * pluginInstance {
94101 p .cmetricsCtxProvider = provider
95102 return p
96103}
97104
105+ // withConfigLoaderProvider overrides the configLoaderProvider.
106+ // This must be called immediately after creating the instance.
98107func (p * pluginInstance ) withConfigLoaderProvider (provider configLoaderProvider ) * pluginInstance {
99108 p .configLoaderProvider = provider
100109 return p
101110}
102111
112+ // init initializes a newly created plugin instance.
103113func (p * pluginInstance ) init (ptr unsafe.Pointer ) (initErr error ) {
104114 p .mu .Lock ()
105115 defer p .mu .Unlock ()
0 commit comments