merge backend-datasource and datasource type

This commit is contained in:
bergquist
2017-12-15 17:17:58 +01:00
parent 8573f73d72
commit 7977d6b669
3 changed files with 61 additions and 13 deletions

View File

@ -3,7 +3,16 @@ package plugins
import (
"encoding/json"
"os"
"os/exec"
"path"
"path/filepath"
"github.com/grafana/grafana/pkg/log"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/plugins/backend"
"github.com/grafana/grafana/pkg/tsdb"
shared "github.com/grafana/grafana/pkg/tsdb/models/proxy"
plugin "github.com/hashicorp/go-plugin"
)
type DataSourcePlugin struct {
@ -16,6 +25,12 @@ type DataSourcePlugin struct {
Mixed bool `json:"mixed,omitempty"`
HasQueryHelp bool `json:"hasQueryHelp,omitempty"`
Routes []*AppPluginRoute `json:"routes"`
Backend bool `json:"backend,omitempty"`
Executable string `json:"executable,omitempty"`
log log.Logger
client *plugin.Client
}
func (p *DataSourcePlugin) Load(decoder *json.Decoder, pluginDir string) error {
@ -39,3 +54,37 @@ func (p *DataSourcePlugin) Load(decoder *json.Decoder, pluginDir string) error {
DataSources[p.Id] = p
return nil
}
func (p *DataSourcePlugin) initBackendPlugin(log log.Logger) error {
p.log = log.New("plugin-id", p.Id)
p.client = plugin.NewClient(&plugin.ClientConfig{
HandshakeConfig: handshakeConfig,
Plugins: map[string]plugin.Plugin{p.Id: &shared.TsdbPluginImpl{}},
Cmd: exec.Command(path.Join(p.PluginDir, p.Executable)),
AllowedProtocols: []plugin.Protocol{plugin.ProtocolGRPC},
Logger: backend.LogWrapper{Logger: p.log},
})
rpcClient, err := p.client.Client()
if err != nil {
return err
}
raw, err := rpcClient.Dispense(p.Id)
if err != nil {
return err
}
plugin := raw.(shared.TsdbPlugin)
tsdb.RegisterTsdbQueryEndpoint(p.Id, func(dsInfo *models.DataSource) (tsdb.TsdbQueryEndpoint, error) {
return &shared.TsdbWrapper{TsdbPlugin: plugin}, nil
})
return nil
}
func (p *DataSourcePlugin) Kill() {
p.client.Kill()
}