From e139f6cdd2fce6c2c00ae81c3b43a8a6acd0e8fa Mon Sep 17 00:00:00 2001 From: Takahiro Yamashita Date: Sat, 9 Sep 2023 07:40:19 +0900 Subject: [PATCH] filter_lua: support enable_flb_null Signed-off-by: Takahiro Yamashita --- plugins/filter_lua/lua.c | 11 +++++++++++ plugins/filter_lua/lua_config.h | 1 + 2 files changed, 12 insertions(+) diff --git a/plugins/filter_lua/lua.c b/plugins/filter_lua/lua.c index a95c87da1fe..bb7bb566ab4 100644 --- a/plugins/filter_lua/lua.c +++ b/plugins/filter_lua/lua.c @@ -61,6 +61,10 @@ static int cb_lua_init(struct flb_filter_instance *f_ins, } ctx->lua = lj; + if (ctx->enable_flb_null) { + flb_lua_enable_flb_null(lj->state); + } + /* Lua script source code */ if (ctx->code) { ret = flb_luajit_load_buffer(ctx->lua, @@ -683,6 +687,13 @@ static struct flb_config_map config_map[] = { "If enabled, Fluent-bit will pass the timestamp as a Lua table " "with keys \"sec\" for seconds since epoch and \"nsec\" for nanoseconds." }, + { + FLB_CONFIG_MAP_BOOL, "enable_flb_null", "false", + 0, FLB_TRUE, offsetof(struct lua_filter, enable_flb_null), + "If enabled, null will be converted to flb_null in Lua. " + "It is useful to prevent removing key/value " + "since nil is a special value to remove key value from map in Lua." + }, {0} }; diff --git a/plugins/filter_lua/lua_config.h b/plugins/filter_lua/lua_config.h index e5cc1a9b4e5..af8d6f12858 100644 --- a/plugins/filter_lua/lua_config.h +++ b/plugins/filter_lua/lua_config.h @@ -35,6 +35,7 @@ struct lua_filter { flb_sds_t buffer; /* json dec buffer */ int protected_mode; /* exec lua function in protected mode */ int time_as_table; /* timestamp as a Lua table */ + int enable_flb_null; /* Use flb_null in Lua */ struct flb_lua_l2c_config l2cc; /* lua -> C config */ struct flb_luajit *lua; /* state context */ struct flb_filter_instance *ins; /* filter instance */