There are three different interfaces to implement, depending on what sort of functionality you are adding:
- Importer: for sourcing data into the system.
- Processor: for manipulating data as it goes through the system.
- Exporter: for sending processed data somewhere.
All plugins should be implemented in the respective importers, processors, or exporters package.
The constructor is registered to the system by name in the init this is how the configuration is able to dynamically create pipelines:
func init() {
exporters.RegisterExporter(noopExporterMetadata.ExpName, exporters.ExporterConstructorFunc(func() exporters.Exporter {
return &noopExporter{}
}))
}
There are similar interfaces for each plugin type.
Each plugin package contains an all.go file. Add your plugin to the import statement, this causes the init function to be called and ensures the plugin is registered.
Generally speaking, you can follow the code in one of the existing plugins.
Each plugin will have it's Init function called once as the pipline is constructed.
The context provided to this function should be saved, and used to terminate any long-running operations if necessary.
Each plugin type has a function which is called once per round:
- Importer:
GetBlockcalled when a particular round is required. Generally this will be increasing over time. - Processor:
Processcalled to process a round. - Exporter:
Receivefor consuming a round.
Called during a graceful shutdown. We make every effort to call this function, but it is not guaranteed.
There are special lifecycle hooks that can be registered on any plugin by implementing additional interfaces.
When all processing has completed for a round, the OnComplete function is called on any plugin that implements it.
// Completed is called by the conduit pipeline after every exporter has
// finished. It can be used for things like finalizing state.
type Completed interface {
// OnComplete will be called by the Conduit framework when the pipeline
// finishes processing a round.
OnComplete(input data.BlockData) error
}After the pipeline has been initialized, and before it has been started, plugins may provide prometheus metric handlers. The subsystem is a configurable value that should be passed into the Prometheus metric constructors. The ProvideMetrics function will only be called once.
// PluginMetrics is for defining plugin specific metrics
type PluginMetrics interface {
ProvideMetrics(subsystem string) []prometheus.Collector
}