Commit 05362a96 by bergquist

plugins: restart killed plugins

parent 4aeef320
......@@ -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 }
......
......@@ -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()
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment