From 72026b896f22c9e6daf7601d2ded0640935f9e06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Mur=C3=A9?= Date: Tue, 24 Sep 2019 14:32:27 +0900 Subject: [PATCH] plugins: support Close() for Tracer plugins as well Most of the tracers available need to properly close to send the remaining traces before the process exit. --- plugin/daemon.go | 1 - plugin/loader/loader.go | 5 +++-- plugin/plugin.go | 5 ++++- plugin/tracer.go | 1 + 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/plugin/daemon.go b/plugin/daemon.go index 8ed86b764ee..04b18b33b96 100644 --- a/plugin/daemon.go +++ b/plugin/daemon.go @@ -10,5 +10,4 @@ type PluginDaemon interface { Plugin Start(coreiface.CoreAPI) error - Close() error } diff --git a/plugin/loader/loader.go b/plugin/loader/loader.go index face2810755..63481b4f708 100644 --- a/plugin/loader/loader.go +++ b/plugin/loader/loader.go @@ -2,6 +2,7 @@ package loader import ( "fmt" + "io" "os" "path/filepath" "strings" @@ -266,8 +267,8 @@ func (loader *PluginLoader) Close() error { started := loader.started loader.started = nil for _, pl := range started { - if pl, ok := pl.(plugin.PluginDaemon); ok { - err := pl.Close() + if closer, ok := pl.(io.Closer); ok { + err := closer.Close() if err != nil { errs = append(errs, fmt.Sprintf( "error closing plugin %s: %s", diff --git a/plugin/plugin.go b/plugin/plugin.go index fcf86e490b9..35e618747ca 100644 --- a/plugin/plugin.go +++ b/plugin/plugin.go @@ -9,8 +9,11 @@ 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 +// +// Optionally, Plugins can implement io.Closer if they want to +// have a termination step when unloading. type Plugin interface { // Name should return unique name of the plugin Name() string diff --git a/plugin/tracer.go b/plugin/tracer.go index 2f1d8f814ca..b6b56939d44 100644 --- a/plugin/tracer.go +++ b/plugin/tracer.go @@ -7,5 +7,6 @@ import ( // PluginTracer is an interface that can be implemented to add a tracer type PluginTracer interface { Plugin + InitTracer() (opentracing.Tracer, error) }