@@ -12,9 +12,16 @@ Every output plugin go through four callbacks associated to different phases:
12
12
| Registration | FLBPluginRegister() |
13
13
| Initialization | FLBPluginInit() |
14
14
| Input Callback | FLBPluginInputCallback() |
15
- | Input Cleanup Callback | FLBPluginInputCleanupCallback() |
16
15
| Exit | FLBPluginExit() |
17
16
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
+
18
25
## Plugin Registration
19
26
20
27
When 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
49
56
50
57
The callback will send a raw buffer of msgpack data with it proper bytes length into Fluent Bit core.
51
58
59
+ ` data ` will collect the assigned pointer and this passing pointer should be allocated by C style allocation (C.calloc/C.malloc).
60
+
52
61
``` go
53
62
import " reflect" // Import reflect package.
54
63
@@ -69,7 +78,7 @@ func makeSlice(p unsafe.Pointer, n int) *Slice {
69
78
}
70
79
71
80
// export FLBPluginInputCallback
72
- func FLBPluginInputCallback (data ** C . void , size *C .size_t ) int {
81
+ func FLBPluginInputCallback (data *unsafe . Pointer , size *C .size_t ) int {
73
82
now := time.Now ()
74
83
// To handle nanosecond precision on Golang input plugin, you must wrap up time instances with input.FLBTime type.
75
84
flb_time := input.FLBTime {now}
@@ -92,20 +101,14 @@ func FLBPluginInputCallback(data **C.void, size *C.size_t) int {
92
101
93
102
### Input Cleanup Callback
94
103
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_ .
96
105
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 .
98
107
99
108
``` go
100
- import " sync"
101
-
102
- var barrior sync.Mutex
103
-
104
109
// export FLBPluginInputCleanupCallback
105
110
func 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
109
112
110
113
return input.FLB_OK
111
114
}
0 commit comments