You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: DEVELOPER_GUIDE.md
+83Lines changed: 83 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,6 +15,7 @@ changes to Fluent Bit.
15
15
-[Input](#input)
16
16
-[Filter](#filter)
17
17
-[Output](#output)
18
+
-[Config Maps](#config-maps)
18
19
-[Testing](#testing)
19
20
-[Valgrind](#valgrind)
20
21
-[Need more help?](#need-more-help)
@@ -422,6 +423,88 @@ Output plugins are defined in [flb_output.h](https://github.com/fluent/fluent-bi
422
423
423
424
The [stdout plugin](plugins/out_stdout) is very simple; review its code to understand how output plugins work.
424
425
426
+
#### Config Maps
427
+
428
+
Config maps are an improvement to the previous Fluent Bit API that was used by plugins to read configuration values. The new config maps feature warns the user if there is an unknown configuration key and reduces risk of bad configuration due to typos or deprecated property names. They will also allow dynamic configuration reloading to be implemented in the future.
429
+
430
+
There are various types of supported configuration types. Full list available [here](https://github.com/fluent/fluent-bit/blob/v1.4.2/include/fluent-bit/flb_config_map.h#L29). The most used ones are:
| FLB_CONFIG_MAP_INT | Represents integer data type |
435
+
| FLB_CONFIG_MAP_BOOL | Represents boolean data type |
436
+
| FLB_CONFIG_MAP_DOUBLE | Represents a double |
437
+
| FLB_CONFIG_MAP_SIZE | Provides size_type as an integer datatype large enough to represent any possible string size. |
438
+
| FLB_CONFIG_MAP_STR | Represents string data type |
439
+
| FLB_CONFIG_MAP_CLIST | Comma separated list of strings |
440
+
| FLB_CONFIG_MAP_SLIST | Empty space separated list of strings |
441
+
442
+
A config map expects certain public fields at registration.
443
+
444
+
| Public Fields | Description |
445
+
| --------------|:---------------------|
446
+
| Type | This field is the data type of the property that we are writing to the config map. If the property is of type `int` we use `FLB_CONFIG_MAP_INT`, if `string``FLB_CONFIG_MAP_STR` etc. |
447
+
| Name | This field is the name of the configuration property. For example for the property flush count we use `flush_count`|
448
+
| Default Value | This field allows the user to set the default value of the property. For example, for a property of type `FLB_CONFIG_MAP_BOOL` (boolean), the default value may be false. Then we have to give `false` as default value. If there is no default value, `NULL` is given.|
449
+
| Flags | This field allows the user to set option flags. For example, it specifies in certain cases if multiple entries are allowed. |
450
+
| Set Property | This field decides if the property needs to be written to plugin context or just validated. If the property needs to be written to the plugin context, the value of this field needs to `FLB_TRUE` or else the value will be `FLB_FALSE`.|
451
+
| Offset | This field represents the member offset. It is 0 if the property is not written to the plugin context and if the property is being written to the plugin context it is ```offsetof(struct name_of_plugin_structure, name_of_property)```. The macro offsetof() returns the offset of the field *member* from the start of the structure type.|
452
+
| Description | This field is so that the user can give a short description of the property. It is `NULL` if no description is needed or given. |
453
+
454
+
For example for [stdout](https://github.com/fluent/fluent-bit/blob/v1.4.2/plugins/out_stdout/stdout.c#L158) plugin the config map is something like:
455
+
456
+
```c
457
+
/* Configuration properties map */
458
+
staticstruct flb_config_map config_map[] = {
459
+
{
460
+
FLB_CONFIG_MAP_STR, "format", NULL,
461
+
0, FLB_FALSE, 0,
462
+
"Specifies the data format to be printed. Supported formats are msgpack json, json_lines and json_stream."
"Specifies the format of the date. Supported formats are double, iso8601 and epoch."
473
+
},
474
+
475
+
/* EOF */
476
+
{0}
477
+
};
478
+
479
+
/* Plugin registration */
480
+
struct flb_output_plugin out_stdout_plugin = {
481
+
.name = "stdout",
482
+
.description = "Prints events to STDOUT",
483
+
.cb_init = cb_stdout_init,
484
+
.cb_flush = cb_stdout_flush,
485
+
.cb_exit = cb_stdout_exit,
486
+
.flags = 0,
487
+
.config_map = config_map
488
+
};
489
+
490
+
```
491
+
In the above code snippet, the property *format* is of type string which supports formats like json, msgpack etc. It has default value NULL(in which case it uses msgpack), no flags, and it is being only validated by the config map and hence set_property field is `FLB_FALSE` with member offset 0. No description is written for *format* property at present.
492
+
Similarly, for the property *json_date_key*, type is string, default value is date, and it is being written to context so the set_property field is `FLB_TRUE` with a member offset. Again, no description is written for it.
493
+
494
+
495
+
Upon initilization the engine loads the config map like [this](https://github.com/fluent/fluent-bit/blob/v1.4.2/plugins/out_stdout/stdout.c#L48):
496
+
497
+
```c
498
+
ret = flb_output_config_map_set(ins, (void *) ctx);
499
+
```
500
+
501
+
[flb_output_config_map_set](https://github.com/fluent/fluent-bit/blob/v1.4.2/include/fluent-bit/flb_output.h#L510) returns [flb_config_map_set](https://github.com/fluent/fluent-bit/blob/v1.4.2/src/flb_config_map.c#L513) which is a function used by plugins that needs to populate their context structure with the configuration properties already mapped.
502
+
503
+
Some points to keep in mind while migrating an existing plugin to a config map interface:
504
+
- All memory allocations and releases of properties on exit are handled by the config map interface.
505
+
- The config map does not parse host and port properties since these properties are handled automatically for plugins that perform network operations.
506
+
- Some plugins might also have an empty config_map. This is so that it would show an error when someone tried to use a non-existent parameter.
507
+
425
508
### Testing
426
509
427
510
During development, you can build Fluent Bit as follows:
0 commit comments