Path: blob/main/docs/developer/writing-exporter-flow-components.md
5333 views
Create Prometheus Exporter Flow Components
This guide will walk you through the process of creating a new Prometheus exporter Flow component and best practices for implementing it.
It is required that the exporter has an existing Agent integration in order to wrap it as a Flow component. In the future, we will drop this requirement and Flow components will expose the logic of the exporter directly.
Use the following exporters as a reference:
Arguments (Configuration)
Arguments struct defines the arguments that can be passed to the component. In most cases, this would be exactly the same as the arguments that the integration for this exporter uses. Some recommendations:
Use
attrtag for representing values. Useattr,optionaltag for optional arguments.Use
rivertypes.Secrettype for sensitive arguments (e.g. API keys, passwords, etc). The original integration should have a similar field type calledSecretfrom Prometheus.Use
blocktag for representing nested values such slices or structs. For example, the process_exporterArgumentsstruct hasProcessExporterparam which is a[]MatcherGroup. The name of the parameter should be in singular. This will allow the user to define multiple blocks of the same type.
The river config would look like this using matcher block multiple times:
Use
labeltag in field of struct represented as block to define named blocks. For example, the blackbox_exporterBlackboxTargetstruct has aNameparam which represents the name of the block.
The river config would look like this:
Define
DefaultArgumentsas a global variable to define the default arguments for the component.
Functions
Define
initfunction to register the component usingcomponent.Register.The
Buildparam should be a function that returns acomponent.Componentinterface.The name used in the second parameter of
exporter.Newwhen defining theBuildfunction it's important as it will define the labeljobin the form ofintegrations/<name>.Avoid creating components with
Singleton: trueas it will make it impossible to run multiple instances of the exporter.
If the exporter follows the multi-target pattern, add a function to define Prometheus discovery targets and use
exporter.NewMultiTargetfor theBuildparam of thecomponent.Registerfunction.Define
UnmarshalRiverfunction to unmarshal the arguments from the river config into theArgumentsstruct. Please, add a test to validate the unmarshalling covering as many cases as possible.Define a
Convertfunction to convert nested structs to the ones that the integration uses. Please, also add a test to validate the conversion covering as many cases as possible.
Registering the component
In order to make the component visible for Agent Flow, it needs to be added to all.go file.
Documentation
Writing the documentation for the component is very important. Please, follow the Writing documentation for Flow components and take a look at the existing documentation for other exporters.