diff --git a/pkg/plugins/backend/log-wrapper.go b/pkg/plugins/backend/log-wrapper.go index cf623695581..c4f7d80b856 100644 --- a/pkg/plugins/backend/log-wrapper.go +++ b/pkg/plugins/backend/log-wrapper.go @@ -11,11 +11,21 @@ type LogWrapper struct { Logger glog.Logger } -func (lw LogWrapper) Trace(msg string, args ...interface{}) {} -func (lw LogWrapper) Debug(msg string, args ...interface{}) {} -func (lw LogWrapper) Info(msg string, args ...interface{}) {} -func (lw LogWrapper) Warn(msg string, args ...interface{}) {} -func (lw LogWrapper) Error(msg string, args ...interface{}) {} +func (lw LogWrapper) Trace(msg string, args ...interface{}) { + glog.Debug2(msg, args...) +} +func (lw LogWrapper) Debug(msg string, args ...interface{}) { + glog.Debug2(msg, args...) +} +func (lw LogWrapper) Info(msg string, args ...interface{}) { + glog.Info2(msg, args...) +} +func (lw LogWrapper) Warn(msg string, args ...interface{}) { + glog.Warn2(msg, args...) +} +func (lw LogWrapper) Error(msg string, args ...interface{}) { + glog.Error2(msg, args...) +} func (lw LogWrapper) IsTrace() bool { return true } func (lw LogWrapper) IsDebug() bool { return true } diff --git a/pkg/plugins/datasource_plugin.go b/pkg/plugins/datasource_plugin.go index 5ef64b81352..1fe54482c7e 100644 --- a/pkg/plugins/datasource_plugin.go +++ b/pkg/plugins/datasource_plugin.go @@ -9,6 +9,7 @@ import ( "path/filepath" "runtime" "strings" + "time" "github.com/grafana/grafana/pkg/log" "github.com/grafana/grafana/pkg/models" @@ -71,6 +72,13 @@ func buildExecutablePath(pluginDir, executable, os, arch string) string { func (p *DataSourcePlugin) initBackendPlugin(log log.Logger) error { p.log = log.New("plugin-id", p.Id) + p.spawnSubProcess() + go p.reattachKilledProcess() + + return nil +} + +func (p *DataSourcePlugin) spawnSubProcess() error { cmd := buildExecutablePath(p.PluginDir, p.Executable, runtime.GOOS, runtime.GOARCH) p.client = plugin.NewClient(&plugin.ClientConfig{ @@ -94,12 +102,28 @@ func (p *DataSourcePlugin) initBackendPlugin(log log.Logger) error { plugin := raw.(shared.TsdbPlugin) tsdb.RegisterTsdbQueryEndpoint(p.Id, func(dsInfo *models.DataSource) (tsdb.TsdbQueryEndpoint, error) { - return &shared.TsdbWrapper{TsdbPlugin: plugin}, nil + return &shared.DatasourcePluginWrapper{TsdbPlugin: plugin}, nil }) return nil } +func (p *DataSourcePlugin) reattachKilledProcess() { + ticker := time.NewTicker(time.Second * 1) + + for { + select { + case <-ticker.C: + if p.client.Exited() { + err := p.spawnSubProcess() + if err != nil { + p.log.Error("Failed to spawn subprocess") + } + } + } + } +} + func (p *DataSourcePlugin) Kill() { if p.client != nil { p.client.Kill() diff --git a/pkg/tsdb/models/proxy/wrapper.go b/pkg/tsdb/models/proxy/datasource_plugin_wrapper.go similarity index 92% rename from pkg/tsdb/models/proxy/wrapper.go rename to pkg/tsdb/models/proxy/datasource_plugin_wrapper.go index 85a49294c25..d7ebeb07ecb 100644 --- a/pkg/tsdb/models/proxy/wrapper.go +++ b/pkg/tsdb/models/proxy/datasource_plugin_wrapper.go @@ -9,11 +9,11 @@ import ( "golang.org/x/net/context" ) -type TsdbWrapper struct { +type DatasourcePluginWrapper struct { TsdbPlugin } -func (tw *TsdbWrapper) Query(ctx context.Context, ds *models.DataSource, query *tsdb.TsdbQuery) (*tsdb.Response, error) { +func (tw *DatasourcePluginWrapper) Query(ctx context.Context, ds *models.DataSource, query *tsdb.TsdbQuery) (*tsdb.Response, error) { jsonData, err := ds.JsonData.MarshalJSON() if err != nil { return nil, err