Skip to content

Commit

Permalink
filter_lua: support enable_flb_null
Browse files Browse the repository at this point in the history
Signed-off-by: Takahiro Yamashita <[email protected]>
  • Loading branch information
nokute78 authored and edsiper committed Sep 23, 2023
1 parent 44d6555 commit e139f6c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
11 changes: 11 additions & 0 deletions plugins/filter_lua/lua.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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}
};
Expand Down
1 change: 1 addition & 0 deletions plugins/filter_lua/lua_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit e139f6c

Please sign in to comment.