@@ -12,9 +12,16 @@ Every output plugin go through four callbacks associated to different phases:
1212| Registration | FLBPluginRegister() |
1313| Initialization | FLBPluginInit() |
1414| Input Callback | FLBPluginInputCallback() |
15- | Input Cleanup Callback | FLBPluginInputCleanupCallback() |
1615| Exit | FLBPluginExit() |
1716
17+ And _ Input Cleanup Callback_ is optional.
18+
19+ This callback is called right after _ Input Callback_ .
20+
21+ | Plugin Phase | Callback |
22+ | ------------------------| ---------------------------------|
23+ | Input Cleanup Callback | FLBPluginInputCleanupCallback() |
24+
1825## Plugin Registration
1926
2027When Fluent Bit loads a Golang input plugin, it looks up and loads the registration
@@ -49,6 +56,8 @@ When Fluent Bit wants to collect logs from Golang input plugin, the input callba
4956
5057The callback will send a raw buffer of msgpack data with it proper bytes length into Fluent Bit core.
5158
59+ ` data ` will collect the assigned pointer and this passing pointer should be allocated by C style allocation (C.calloc/C.malloc).
60+
5261``` go
5362import " reflect" // Import reflect package.
5463
@@ -69,7 +78,7 @@ func makeSlice(p unsafe.Pointer, n int) *Slice {
6978}
7079
7180// export FLBPluginInputCallback
72- func FLBPluginInputCallback (data ** C . void , size *C .size_t ) int {
81+ func FLBPluginInputCallback (data *unsafe . Pointer , size *C .size_t ) int {
7382 now := time.Now ()
7483 // To handle nanosecond precision on Golang input plugin, you must wrap up time instances with input.FLBTime type.
7584 flb_time := input.FLBTime {now}
@@ -92,20 +101,14 @@ func FLBPluginInputCallback(data **C.void, size *C.size_t) int {
92101
93102### Input Cleanup Callback
94103
95- For cleaning up to be allocated resources, this callback will be triggered after _ Input Callback_ .
104+ For cleaning up some sort of allocated resources, this callback will be triggered after _ Input Callback_ .
96105
97- This callback is mainly used for deallocating heap memories which are allocated by ` C.malloc ` or ` C.calloc ` .
106+ This callback is mainly used for cleaning up resources not for the first argument of input callback .
98107
99108``` go
100- import " sync"
101-
102- var barrior sync.Mutex
103-
104109// export FLBPluginInputCleanupCallback
105110func FLBPluginInputCleanupCallback (data unsafe .Pointer ) int {
106- barrior.Lock () // Guarding for deallocating region is needed for safety.
107- C.free (unsafe.Pointer (data))
108- barrior.Unlock ()
111+ // Some sort of cleaning up resources
109112
110113 return input.FLB_OK
111114}
0 commit comments