How to Write Input Plugin
Extend Fluent::Plugin::Input
class and implement its methods.
See Plugin Base Class API for details on the common APIs for all plugin types.
In most cases, input plugins start timers, threads, or network servers to listen on ports in #start
method and then call router.emit
in the callbacks of timers, threads or network servers to emit events.
Example:
To submit events, use router.emit(tag, time, record)
method, where:
tag
is aString
,time
is theFluent::EventTime
orInteger
as Unix time; and,record
is aHash
object.
Example:
To submit multiple events, use router.emit_stream(tag, es)
method, where:
tag
is aString
; and,es
is aMultiEventStream
object.
Example:
Record Format
Fluentd plugins assume the record is in JSON format so the key should be the String
, not Symbol
. If you emit a record with a key as Symbol
, it may cause a problem.
Example:
Methods
There are no specific methods for the Input plugins.
Writing Tests
Fluentd input plugin has one or more points to be tested. Others aspects (parsing configurations, controlling buffers, retries, flushes, etc.) are controlled by the Fluentd core.
Fluentd also provides the test drivers for plugins. You can write tests for your own plugins very easily:
Overview of Tests
Testing for input plugins is mainly for:
Validation of configuration (i.e.
#configure
)Validation of the emitted events
To make testing easy, the test driver provides a dummy router, a logger and the functionality to override system and parser configurations, etc.
The lifecycle of plugin and test driver is:
Instantiate plugin driver which then instantiates the plugin
Configure plugin
Register conditions to stop/break running tests
Run test code (provided as a block for
d.run
)Assert results of tests by data provided by the driver
Test driver calls methods for plugin lifecycle at the beginning of Step # 4 (i.e. #start
) and at the end (i.e. #stop
, #shutdown
, etc.). It can be skipped by optional arguments of #run
.
See Testing API for Plugins for details.
For:
configuration tests, repeat steps # 1-2
full feature tests, repeat steps # 1-5
If this article is incorrect or outdated, or omits critical information, please let us know. Fluentd is an open-source project under Cloud Native Computing Foundation (CNCF). All components are available under the Apache 2 License.
Last updated