|
@@ -9,6 +9,7 @@ import (
|
|
|
"path/filepath"
|
|
"path/filepath"
|
|
|
"runtime"
|
|
"runtime"
|
|
|
"strings"
|
|
"strings"
|
|
|
|
|
+ "time"
|
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/log"
|
|
"github.com/grafana/grafana/pkg/log"
|
|
|
"github.com/grafana/grafana/pkg/models"
|
|
"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 {
|
|
func (p *DataSourcePlugin) initBackendPlugin(log log.Logger) error {
|
|
|
p.log = log.New("plugin-id", p.Id)
|
|
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)
|
|
cmd := buildExecutablePath(p.PluginDir, p.Executable, runtime.GOOS, runtime.GOARCH)
|
|
|
|
|
|
|
|
p.client = plugin.NewClient(&plugin.ClientConfig{
|
|
p.client = plugin.NewClient(&plugin.ClientConfig{
|
|
@@ -94,12 +102,28 @@ func (p *DataSourcePlugin) initBackendPlugin(log log.Logger) error {
|
|
|
plugin := raw.(shared.TsdbPlugin)
|
|
plugin := raw.(shared.TsdbPlugin)
|
|
|
|
|
|
|
|
tsdb.RegisterTsdbQueryEndpoint(p.Id, func(dsInfo *models.DataSource) (tsdb.TsdbQueryEndpoint, error) {
|
|
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
|
|
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() {
|
|
func (p *DataSourcePlugin) Kill() {
|
|
|
if p.client != nil {
|
|
if p.client != nil {
|
|
|
p.client.Kill()
|
|
p.client.Kill()
|