@@ -7,12 +7,13 @@ specified instance configuration to the input callback.
7
7
8
8
Every output plugin go through four callbacks associated to different phases:
9
9
10
- | Plugin Phase | Callback |
11
- | ---------------------| ----------------------------|
12
- | Registration | FLBPluginRegister() |
13
- | Initialization | FLBPluginInit() |
14
- | Input Callback | FLBPluginInputCallback() |
15
- | Exit | FLBPluginExit() |
10
+ | Plugin Phase | Callback |
11
+ | ------------------------| ---------------------------------|
12
+ | Registration | FLBPluginRegister() |
13
+ | Initialization | FLBPluginInit() |
14
+ | Input Callback | FLBPluginInputCallback() |
15
+ | Input Cleanup Callback | FLBPluginInputCleanupCallback() |
16
+ | Exit | FLBPluginExit() |
16
17
17
18
## Plugin Registration
18
19
@@ -58,10 +59,6 @@ func alloc(size int) unsafe.Pointer {
58
59
func makeSlice (p unsafe .Pointer , n int ) *Slice {
59
60
data := &c_slice_t{p, n}
60
61
61
- runtime.SetFinalizer (data, func (data *c_slice_t){
62
- C.free (data.p )
63
- })
64
-
65
62
s := &Slice{data: data}
66
63
h := (*reflect.SliceHeader )(unsafe.Pointer (&s.Data ))
67
64
h.Data = uintptr (p)
@@ -93,6 +90,29 @@ func FLBPluginInputCallback(data **C.void, size *C.size_t) int {
93
90
}
94
91
```
95
92
93
+ ### Input Cleanup Callback
94
+
95
+ For cleaning up to be allocated resources, this callback will be triggered after _ Input Callback_ .
96
+
97
+ This callback is mainly used for deallocating heap memories which are allocated by ` C.malloc ` or ` C.calloc ` .
98
+
99
+ ``` go
100
+ import " sync"
101
+
102
+ var barrior sync.Mutex
103
+
104
+ // export FLBPluginInputCleanupCallback
105
+ 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 ()
109
+
110
+ return input.FLB_OK
111
+ }
112
+ ```
113
+
114
+ #### Returning Status Values
115
+
96
116
> for more details about how to process the sending msgpack data into Fluent Bit core, please refer to the [ in_gdummy.go] ( in_gdummy.go ) file.
97
117
98
118
When done, there are three returning values available:
@@ -103,6 +123,7 @@ When done, there are three returning values available:
103
123
| FLB\_ ERROR | An internal error have ocurred, the plugin will not handle the set of records/data again. |
104
124
| FLB\_ RETRY | A recoverable error have ocurred, the engine can try to flush the records/data later.|
105
125
126
+
106
127
## Plugin Exit
107
128
108
129
When Fluent Bit will stop using the instance of the plugin, it will trigger the exit callback. e.g:
0 commit comments