Skip to content

Commit

Permalink
plugins: support Close() for Tracer plugins as well
Browse files Browse the repository at this point in the history
Most of the tracers available need to properly close to send
the remaining traces before the process exit.
  • Loading branch information
MichaelMure committed Sep 24, 2019
1 parent ad9cbbd commit 92ae72f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
3 changes: 1 addition & 2 deletions plugin/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import (
// PluginDaemon is an interface for daemon plugins. These plugins will be run on
// the daemon and will be given access to an implementation of the CoreAPI.
type PluginDaemon interface {
Plugin
Closer

Start(coreiface.CoreAPI) error
Close() error
}
2 changes: 1 addition & 1 deletion plugin/loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ func (loader *PluginLoader) Close() error {
started := loader.started
loader.started = nil
for _, pl := range started {
if pl, ok := pl.(plugin.PluginDaemon); ok {
if pl, ok := pl.(plugin.Closer); ok {
err := pl.Close()
if err != nil {
errs = append(errs, fmt.Sprintf(
Expand Down
10 changes: 9 additions & 1 deletion plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type Environment struct {
Config interface{}
}

// Plugin is base interface for all kinds of go-ipfs plugins
// Plugin is the base interface for all kinds of go-ipfs plugins
// It will be included in interfaces of different Plugins
type Plugin interface {
// Name should return unique name of the plugin
Expand All @@ -23,3 +23,11 @@ type Plugin interface {
// (possibly uninitialized) IPFS repo and the plugin's config.
Init(env *Environment) error
}

// Closer plugin support closing when go-ipfs is terminating
type Closer interface {
Plugin

// Close is called once when the Plugin is being unloaded
Close() error
}
3 changes: 2 additions & 1 deletion plugin/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

// PluginTracer is an interface that can be implemented to add a tracer
type PluginTracer interface {
Plugin
Closer

InitTracer() (opentracing.Tracer, error)
}

0 comments on commit 92ae72f

Please sign in to comment.