Developer guide for beginners on contributing to Fluent Bit
Last updated
Was this helpful?
Last updated
Was this helpful?
If you have some knowledge of C, this guide should help you understand how to make code changes to Fluent Bit.
Most external libraries are embedded in the project in the folder. To keep its footprint low and maximize compatibility in cross-platform builds, Fluent Bit attempts to keep its dependency graph small.
The external library that you're mostly likely to interact with is .
For cryptographic support, Fluent Bit uses the system installed version of OpenSSL. You must install OpenSSL libraries and headers before Building Fluent Bit.
When you write Fluent Bit code, you'll use the Fluent Bit versions of the standard C functions for working with memory:
: Equivalent to malloc
, allocates memory.
: Equivalent to calloc
, allocates memory and initializes it to zero.
: Equivalent to realloc
.
: Equivalent to free
, releases allocated memory.
Fluent Bit has a stripped down version of the popular string library. See for the API.
In general, you should use SDS strings in any string processing code. SDS strings are fully compatible with any C function that accepts a null-terminated sequence of characters. To understand how they work, see the .
Fluent Bit has its own network connection library. The key types and functions are defined in the following header files:
The following code demonstrates an HTTP request in Fluent Bit:
The flb_upstream
structure represents the host/endpoint that you want to call. Normally, you'd store this structure somewhere so that it can be reused. An flb_upstream_conn
represents a connection to that host for a single HTTP request. This connection structure shouldn't be used for more than one request.
Input plugins can use threaded mode if the flag FLB_INPUT_THREADED
is provided.
To enable threading in your plugin, add the FLB_INPUT_THREADED
to the set of flags
when registering:
Filter plugins can not asynchronously make HTTP requests. If your plugin needs to make a request, add the following code when you initialize your flb_upstream
:
Fluent Bit provides a standalone environment for development. Developers who use different operating systems or distributions can develop on a basic, common stack. The development environment provides the required libraries and tools for you.
Development environments are provided for:
During development, you can build Fluent Bit as follows:
To enable the unit tests, run the following command:
Internal tests are for the internal libraries of Fluent Bit. Runtime tests are for the plugins.
You can run the unit tests with make test
. However, this is inconvenient in practice. Each test file will create an executable in the build/bin
directory, which you can run directly. For example, if you want to run the SDS tests, you can invoke them as follows:
Fluent Bit contains a library for constructing linked lists: . The type stores data as a circular linked list.
The header file contains several macros and functions for use with the lists. The following example shows how to create a list, iterate through it, and delete an element.
Fluent Bit uses to internally store data. If you write code for Fluent Bit, it's almost certain that you will interact with MessagePack.
Fluent Bit embeds the library. The following example shows how to manipulate message pack to add a new key/value pair to a record. In Fluent Bit, the plugin adds or deletes keys from records. See its code for more.
For more info, see the MessagePack examples in the .
Each plugin is a shared object which is using dlopen
and dlsym
.
The input plugin structure is defined in . There are a number of functions which a plugin can implement, but most only implement cb_init
, cb_collect
, and cb_exit
.
The is very basic and is an excellent example to review to understand more.
The structure for filter plugins is defined in . Each plugin must implement cb_init
, cb_filter
, and cb_exit
.
The is a good example of a filter plugin.
Output plugins are defined in . Each plugin must implement cb_init
, cb_flush
, and cb_exit
.
The is very basic; review its code to understand how output plugins work.
.