diff --git a/apis/fluentbit/v1alpha2/plugins/filter/lua_types.go b/apis/fluentbit/v1alpha2/plugins/filter/lua_types.go index fa5b90eb6..257cff9dc 100644 --- a/apis/fluentbit/v1alpha2/plugins/filter/lua_types.go +++ b/apis/fluentbit/v1alpha2/plugins/filter/lua_types.go @@ -36,6 +36,9 @@ type Lua struct { // If enabled, Lua script will be executed in protected mode. // It prevents to crash when invalid Lua script is executed. Default is true. ProtectedMode *bool `json:"protectedMode,omitempty"` + // If enabled, null will be converted to flb_null in Lua. + // This helps prevent removing key/value since nil is a special value to remove key/value from map in Lua. Default value: false. + EnableFlbNull *bool `json:"enable_flb_null,omitempty"` // By default when the Lua script is invoked, the record timestamp is passed as a // Floating number which might lead to loss precision when the data is converted back. // If you desire timestamp precision enabling this option will pass the timestamp as @@ -90,6 +93,10 @@ func (l *Lua) Params(_ plugins.SecretLoader) (*params.KVs, error) { kvs.Insert("protected_mode", strconv.FormatBool(*l.ProtectedMode)) } + if l.EnableFlbNull != nil { + kvs.Insert("enable_flb_null", strconv.FormatBool(*l.EnableFlbNull)) + } + if l.TimeAsTable { kvs.Insert("time_as_table", "true") } diff --git a/apis/fluentbit/v1alpha2/plugins/filter/zz_generated.deepcopy.go b/apis/fluentbit/v1alpha2/plugins/filter/zz_generated.deepcopy.go index 4eff2535d..bc138d563 100644 --- a/apis/fluentbit/v1alpha2/plugins/filter/zz_generated.deepcopy.go +++ b/apis/fluentbit/v1alpha2/plugins/filter/zz_generated.deepcopy.go @@ -355,6 +355,11 @@ func (in *Lua) DeepCopyInto(out *Lua) { *out = new(bool) **out = **in } + if in.EnableFlbNull != nil { + in, out := &in.EnableFlbNull, &out.EnableFlbNull + *out = new(bool) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Lua. diff --git a/charts/fluent-bit-crds/Chart.yaml b/charts/fluent-bit-crds/Chart.yaml index 4b964481f..bbf98c896 100644 --- a/charts/fluent-bit-crds/Chart.yaml +++ b/charts/fluent-bit-crds/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: v2 name: fluent-bit-crds description: A helm chart for Fluent-Bit custom resource definitions (CRDs) used by fluent-operator. type: application -version: 0.2.0 +version: 0.2.1 appVersion: v3.5.0 keywords: - logging diff --git a/charts/fluent-bit-crds/templates/fluentbit.fluent.io_clusterfilters.yaml b/charts/fluent-bit-crds/templates/fluentbit.fluent.io_clusterfilters.yaml index 86606fd0d..fc55bbcfa 100644 --- a/charts/fluent-bit-crds/templates/fluentbit.fluent.io_clusterfilters.yaml +++ b/charts/fluent-bit-crds/templates/fluentbit.fluent.io_clusterfilters.yaml @@ -429,6 +429,11 @@ spec: description: Inline LUA code instead of loading from a path via script. type: string + enable_flb_null: + description: |- + If enabled, null will be converted to flb_null in Lua. + This helps prevent removing key/value since nil is a special value to remove key/value from map in Lua. Default value: false. + type: boolean protectedMode: description: |- If enabled, Lua script will be executed in protected mode. diff --git a/charts/fluent-bit-crds/templates/fluentbit.fluent.io_filters.yaml b/charts/fluent-bit-crds/templates/fluentbit.fluent.io_filters.yaml index ee0484734..3419f9579 100644 --- a/charts/fluent-bit-crds/templates/fluentbit.fluent.io_filters.yaml +++ b/charts/fluent-bit-crds/templates/fluentbit.fluent.io_filters.yaml @@ -429,6 +429,11 @@ spec: description: Inline LUA code instead of loading from a path via script. type: string + enable_flb_null: + description: |- + If enabled, null will be converted to flb_null in Lua. + This helps prevent removing key/value since nil is a special value to remove key/value from map in Lua. Default value: false. + type: boolean protectedMode: description: |- If enabled, Lua script will be executed in protected mode. diff --git a/config/crd/bases/fluentbit.fluent.io_clusterfilters.yaml b/config/crd/bases/fluentbit.fluent.io_clusterfilters.yaml index 191d0bb6f..594aafb6f 100644 --- a/config/crd/bases/fluentbit.fluent.io_clusterfilters.yaml +++ b/config/crd/bases/fluentbit.fluent.io_clusterfilters.yaml @@ -426,6 +426,11 @@ spec: description: Inline LUA code instead of loading from a path via script. type: string + enable_flb_null: + description: |- + If enabled, null will be converted to flb_null in Lua. + This helps prevent removing key/value since nil is a special value to remove key/value from map in Lua. Default value: false. + type: boolean protectedMode: description: |- If enabled, Lua script will be executed in protected mode. diff --git a/config/crd/bases/fluentbit.fluent.io_filters.yaml b/config/crd/bases/fluentbit.fluent.io_filters.yaml index 2d3f2a111..e68271580 100644 --- a/config/crd/bases/fluentbit.fluent.io_filters.yaml +++ b/config/crd/bases/fluentbit.fluent.io_filters.yaml @@ -426,6 +426,11 @@ spec: description: Inline LUA code instead of loading from a path via script. type: string + enable_flb_null: + description: |- + If enabled, null will be converted to flb_null in Lua. + This helps prevent removing key/value since nil is a special value to remove key/value from map in Lua. Default value: false. + type: boolean protectedMode: description: |- If enabled, Lua script will be executed in protected mode. diff --git a/docs/plugins/fluentbit/filter/lua.md b/docs/plugins/fluentbit/filter/lua.md index b9ecb4af6..751ef35dc 100644 --- a/docs/plugins/fluentbit/filter/lua.md +++ b/docs/plugins/fluentbit/filter/lua.md @@ -11,4 +11,5 @@ The Lua Filter allows you to modify the incoming records using custom Lua Script | typeIntKey | If these keys are matched, the fields are converted to integer. If more than one key, delimit by space. Note that starting from Fluent Bit v1.6 integer data types are preserved and not converted to double as in previous versions. | []string | | typeArrayKey | If these keys are matched, the fields are handled as array. If more than one key, delimit by space. It is useful the array can be empty. | []string | | protectedMode | If enabled, Lua script will be executed in protected mode. It prevents to crash when invalid Lua script is executed. Default is true. | *bool | +| enable_flb_null | If enabled, null will be converted to flb_null in Lua. This helps prevent removing key/value since nil is a special value to remove key/value from map in Lua. Default value: false. | *bool | | timeAsTable | By default when the Lua script is invoked, the record timestamp is passed as a Floating number which might lead to loss precision when the data is converted back. If you desire timestamp precision enabling this option will pass the timestamp as a Lua table with keys sec for seconds since epoch and nsec for nanoseconds. | bool | diff --git a/manifests/setup/fluent-operator-crd.yaml b/manifests/setup/fluent-operator-crd.yaml index 86eb5ae94..82043d2e1 100644 --- a/manifests/setup/fluent-operator-crd.yaml +++ b/manifests/setup/fluent-operator-crd.yaml @@ -425,6 +425,11 @@ spec: description: Inline LUA code instead of loading from a path via script. type: string + enable_flb_null: + description: |- + If enabled, null will be converted to flb_null in Lua. + This helps prevent removing key/value since nil is a special value to remove key/value from map in Lua. Default value: false. + type: boolean protectedMode: description: |- If enabled, Lua script will be executed in protected mode. @@ -15389,6 +15394,11 @@ spec: description: Inline LUA code instead of loading from a path via script. type: string + enable_flb_null: + description: |- + If enabled, null will be converted to flb_null in Lua. + This helps prevent removing key/value since nil is a special value to remove key/value from map in Lua. Default value: false. + type: boolean protectedMode: description: |- If enabled, Lua script will be executed in protected mode. diff --git a/manifests/setup/setup.yaml b/manifests/setup/setup.yaml index 99fe14a04..b4ef87454 100644 --- a/manifests/setup/setup.yaml +++ b/manifests/setup/setup.yaml @@ -425,6 +425,11 @@ spec: description: Inline LUA code instead of loading from a path via script. type: string + enable_flb_null: + description: |- + If enabled, null will be converted to flb_null in Lua. + This helps prevent removing key/value since nil is a special value to remove key/value from map in Lua. Default value: false. + type: boolean protectedMode: description: |- If enabled, Lua script will be executed in protected mode. @@ -15389,6 +15394,11 @@ spec: description: Inline LUA code instead of loading from a path via script. type: string + enable_flb_null: + description: |- + If enabled, null will be converted to flb_null in Lua. + This helps prevent removing key/value since nil is a special value to remove key/value from map in Lua. Default value: false. + type: boolean protectedMode: description: |- If enabled, Lua script will be executed in protected mode.