The Processor plugin performs secondary processing on the input data. The following will guide how to develop the Processor plugin.
The Processor plugin interface method is very easy to understand. In addition to the two standard methods Init/Description, there is only one ProcessLogs method. Its input and output are both []*Log, which accepts a Log list, and returns a Log list after processing. Naturally, the processor plugin instance triggers a serial processing chain through this method.
// Processor also can be a filter
type Processor interface {
// Init called for init some system resources, like socket, mutex...
Init(Context) error
// Description returns a one-sentence description on the Input
Description() string
// Apply the filter to the given metric
ProcessLogs(logArray []*protocol.Log) []*protocol.Log
}
The development of MetricInput is divided into the following steps:
- Create an Issue to describe the function of the plugin development. There will be community committers participating in the discussion. If the community review passes, please refer to step 2 to continue.
- Implement the Processor interface. We use processor/addfields as an example to introduce how to do. Also, You can use example.json to experiment with this plugin function.
- Register your plugin to Processors in init function. The registered name (a.k.a. plugin_type in json configuration) of a Processor plugin must start with "processor_". We use processor/addfields as an example to introduce how to do.
- Add the plugin to the Global Plugin Definition Center. If it only runs on the specified system, please add it to the Linux Plugin Definition Center Or Windows Plugin Definition Center.
- For unit test or E2E test, please refer to How to write single test and How to write E2E test .
- Use make lint to check the code specification.
- Submit a Pull Request.