Comment on page
Due to the necessity to have a flexible filtering mechanism, now is possible to extend Fluent Bit capabilities writing simple filters using Lua programming language. A Lua based filter takes two steps:
- Configure the Filter in the main configuration
- Prepare a Lua script that will be used by the Filter
The plugin supports the following configuration parameters:
In order to test the filter, you can run the plugin from the command line or through the configuration file. The following examples uses the dummy input plugin for data ingestion, invoke Lua filter using the test.lua script and calls the cb_print() function which only print the same information to the standard output:
From the command line you can use the following options:
$ fluent-bit -i dummy -F lua -p script=test.lua -p call=cb_print -m '*' -o null
In your main configuration file append the following Input, Filter & Output sections:
The life cycle of a filter have the following steps:
- Upon Tag matching by filter_lua, it may process or bypass the record.
- If filter_lua accepts the record, it will invoke the function defined in the call property which basically is the name of a function defined in the Lua script.
- Invoke Lua function passing each record in JSON format.
- Upon return, validate return value and take some action (described above)
The Lua script can have one or multiple callbacks that can be used by filter_lua, it prototype is as follows:
function cb_print(tag, timestamp, record)
return code, timestamp, record
Each callback must return three values:
For functional examples of this interface, please refer to the code samples provided in the source code of the project located here:
In Lua, Fluent Bit treats number as double. It means an integer field (e.g. IDs, log levels) will be converted double. To avoid type conversion, Type_int_key property is available.
Last modified 4yr ago