Files
grafana/pkg/plugins/datasource_plugin.go
T

51 lines
1.7 KiB
Go
Raw Normal View History

package plugins
import (
2021-03-08 07:02:49 +01:00
"context"
"encoding/json"
"path/filepath"
"github.com/grafana/grafana/pkg/plugins/backendplugin"
"github.com/grafana/grafana/pkg/plugins/backendplugin/grpcplugin"
"github.com/grafana/grafana/pkg/util/errutil"
)
2018-07-20 17:07:17 +02:00
// DataSourcePlugin contains all metadata about a datasource plugin
type DataSourcePlugin struct {
FrontendPluginBase
Annotations bool `json:"annotations"`
Metrics bool `json:"metrics"`
Alerting bool `json:"alerting"`
Explore bool `json:"explore"`
Table bool `json:"tables"`
Logs bool `json:"logs"`
2020-03-25 12:25:39 +01:00
Tracing bool `json:"tracing"`
QueryOptions map[string]bool `json:"queryOptions,omitempty"`
BuiltIn bool `json:"builtIn,omitempty"`
Mixed bool `json:"mixed,omitempty"`
Routes []*AppPluginRoute `json:"routes"`
Streaming bool `json:"streaming"`
Backend bool `json:"backend,omitempty"`
Executable string `json:"executable,omitempty"`
2019-10-24 18:15:27 +03:00
SDK bool `json:"sdk,omitempty"`
}
2021-03-08 07:02:49 +01:00
func (p *DataSourcePlugin) Load(decoder *json.Decoder, base *PluginBase, backendPluginManager backendplugin.Manager) (
interface{}, error) {
2019-10-28 17:25:35 +01:00
if err := decoder.Decode(p); err != nil {
2021-03-08 07:02:49 +01:00
return nil, errutil.Wrapf(err, "Failed to decode datasource plugin")
}
if p.Backend {
cmd := ComposePluginStartCommand(p.Executable)
2021-03-08 07:02:49 +01:00
fullpath := filepath.Join(base.PluginDir, cmd)
factory := grpcplugin.NewBackendPlugin(p.Id, fullpath)
if err := backendPluginManager.RegisterAndStart(context.Background(), p.Id, factory); err != nil {
2021-03-08 07:02:49 +01:00
return nil, errutil.Wrapf(err, "failed to register backend plugin")
2019-10-11 21:02:15 +02:00
}
}
2019-10-11 21:02:15 +02:00
2021-03-08 07:02:49 +01:00
return p, nil
}