@@ -3,6 +3,7 @@ package filter
3
3
import (
4
4
"strconv"
5
5
"strings"
6
+ "regexp"
6
7
7
8
"github.com/fluent/fluent-operator/v2/apis/fluentbit/v1alpha2/plugins"
8
9
"github.com/fluent/fluent-operator/v2/apis/fluentbit/v1alpha2/plugins/params"
@@ -20,6 +21,8 @@ type Lua struct {
20
21
// Lua function name that will be triggered to do filtering.
21
22
// It's assumed that the function is declared inside the Script defined above.
22
23
Call string `json:"call"`
24
+ // Inline LUA code instead of loading from a path via script.
25
+ Code string `json:"code"`
23
26
// If these keys are matched, the fields are converted to integer.
24
27
// If more than one key, delimit by space.
25
28
// Note that starting from Fluent Bit v1.6 integer data types are preserved
@@ -45,7 +48,28 @@ func (l *Lua) Params(_ plugins.SecretLoader) (*params.KVs, error) {
45
48
if err != nil {
46
49
return kvs , err
47
50
}
48
- kvs .Insert ("script" , "/fluent-bit/config/" + l .Script .Key )
51
+
52
+ if l .Code != "" {
53
+ var singleLineLua string = ""
54
+ var lineTrim = ""
55
+ for _ , line := range strings .Split (strings .TrimSuffix (l .Code , "\n " ), "\n " ) {
56
+ lineTrim = strings .TrimSpace (line )
57
+ if lineTrim != "" {
58
+ operator , _ := regexp .MatchString ("^function |^if |^for |^else|^elseif |^end|--[[]+" , lineTrim )
59
+ if operator {
60
+ singleLineLua = singleLineLua + lineTrim + " "
61
+ } else {
62
+ singleLineLua = singleLineLua + lineTrim + "; "
63
+ }
64
+ }
65
+ }
66
+ kvs .Insert ("code" , singleLineLua )
67
+ }
68
+
69
+ if l .Script .Key != "" {
70
+ kvs .Insert ("script" , "/fluent-bit/config/" + l .Script .Key )
71
+ }
72
+
49
73
kvs .Insert ("call" , l .Call )
50
74
51
75
if l .TypeIntKey != nil && len (l .TypeIntKey ) > 0 {
0 commit comments