Before you understand how to develop the Input plugin, you need to understand the Input plugin interface. The current Input plugins are divided into two categories, namely MetricInput and ServiceInput. MetricInput can be used to control the collection frequency globally, which is suitable for the pull of Metric indicators. ServiceInput is more suitable to receive external input, such as receiving SkyWalking's Trace data.
- Init: The plugin initialization interface, mainly for the plugin to do some parameter checking, and provide the context object Context for it. The first parameter of the return value represents the call frequency (milliseconds), and the plugin system will use this value as the data fetch frequency. If it returns 0, the plugin system will use the global data fetch frequency. The second parameter of the return value indicates an error occurred during initialization. Once an error occurs, the plugin instance will be ignored.
- Description: plugin self-describing interface.
- Collect: The most critical interface of MetricInput, the plugin system fetch data from plugin instances through this interface. The plugin system will periodically call this interface to collect data into the incoming Collector.
// MetricInput ...
type MetricInput interface {
// Init called for init some system resources, like socket, mutex...
// return call interval(ms) and error flag, if interval is 0, use default interval
Init(Context) (int, error)
// Description returns a one-sentence description on the Input
Description() string
// Collect takes in an accumulator and adds the metrics that the Input
// gathers. This is called every "interval"
Collect(Collector) error
}
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 MetricInput interface. We use input/example/metric as an example mode to introduce how to do. Also, You can use example.json to experiment with this plugin function.
- 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.
- Init/Description: Same as MetricInput interface, but a return value of Init has no meaning for ServiceInput because it will not be called periodically.
- Start: Since the positioning of ServiceInput is a continues input, the plugin system creates an independent goroutine for the plugin instance, and calls this interface in the goroutine to start data collection. Collector is still to act as a data pipeline between the plugin instance and the plugin system.
- Stop: Provides the ability to terminate the plugin. The plugin must implement this method correctly to prevent blocking of the plugin system.
// ServiceInput ...
type ServiceInput interface {
// Init called for init some system resources, like socket, mutex...
// return interval(ms) and error flag, if interval is 0, use default interval
Init(Context) (int, error)
// Description returns a one-sentence description on the Input
Description() string
// Start starts the ServiceInput's service, whatever that may be
Start(Collector) error
// Stop stops the services and closes any necessary channels and connections
Stop() error
}
The development of ServiceInput 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 ServiceInput interface. We use input/example/service as an example mode to introduce how to do. Also, You can use example.json to experiment with this plugin function.
- 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.