@cryptotaxi247 / kubo / commits / 72026b896

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.

Michael Muré committed Sep 24, 2019 at 14:32 UTC 72026b896f22c9e6daf7601d2ded0640935f9e06
4 files changed +8 -4
plugin/daemon.go
-1
@@ -10,5 +10,4 @@ type PluginDaemon interface {
10 Plugin
11
12 Start(coreiface.CoreAPI) error
13 - Close() error
13 }
plugin/loader/loader.go
+3 -2
@@ -2,6 +2,7 @@ package loader
2
3 import (
4 "fmt"
5 + "io"
6 "os"
7 "path/filepath"
8 "strings"
@@ -266,8 +267,8 @@ func (loader *PluginLoader) Close() error {
267 started := loader.started
268 loader.started = nil
269 for _, pl := range started {
269 - if pl, ok := pl.(plugin.PluginDaemon); ok {
270 - err := pl.Close()
270 + if closer, ok := pl.(io.Closer); ok {
271 + err := closer.Close()
272 if err != nil {
273 errs = append(errs, fmt.Sprintf(
274 "error closing plugin %s: %s",
plugin/plugin.go
+4 -1
@@ -9,8 +9,11 @@ type Environment struct {
9 Config interface{}
10 }
11
12 -// Plugin is base interface for all kinds of go-ipfs plugins
12 +// Plugin is the base interface for all kinds of go-ipfs plugins
13 // It will be included in interfaces of different Plugins
14 +//
15 +// Optionally, Plugins can implement io.Closer if they want to
16 +// have a termination step when unloading.
17 type Plugin interface {
18 // Name should return unique name of the plugin
19 Name() string
plugin/tracer.go
+1
@@ -7,5 +7,6 @@ import (
7 // PluginTracer is an interface that can be implemented to add a tracer
8 type PluginTracer interface {
9 Plugin
10 +
11 InitTracer() (opentracing.Tracer, error)
12 }