Plugins: Core plugins register via backend factory provider (#43171)
* refactoring store interface and init flow * fix import * fix linter * refactor resource calling * load with class * re-order args * fix tests * fix linter * remove old creator * add custom config struct * fix some tests * cleanup * fix * tackle plugins * fix linter * refactor and fix test * add connect failure error * add fix for azure, cloud monitoring and test data * restructure * remove unused err * add fake tracer for test * fix grafana ds plugin
This commit is contained in:
@@ -14,8 +14,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/plugins"
|
||||
"github.com/grafana/grafana/pkg/plugins/backendplugin/coreplugin"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/grafana/grafana/pkg/tsdb/testdatasource"
|
||||
)
|
||||
@@ -32,8 +30,6 @@ const DatasourceID = -1
|
||||
// Grafana DS command.
|
||||
const DatasourceUID = "grafana"
|
||||
|
||||
const pluginID = "grafana"
|
||||
|
||||
// Make sure Service implements required interfaces.
|
||||
// This is important to do since otherwise we will only get a
|
||||
// not implemented error response from plugin at runtime.
|
||||
@@ -43,11 +39,11 @@ var (
|
||||
logger = log.New("tsdb.grafana")
|
||||
)
|
||||
|
||||
func ProvideService(cfg *setting.Cfg, pluginStore plugins.Store) *Service {
|
||||
return newService(cfg, pluginStore)
|
||||
func ProvideService(cfg *setting.Cfg) *Service {
|
||||
return newService(cfg)
|
||||
}
|
||||
|
||||
func newService(cfg *setting.Cfg, pluginStore plugins.Store) *Service {
|
||||
func newService(cfg *setting.Cfg) *Service {
|
||||
s := &Service{
|
||||
staticRootPath: cfg.StaticRootPath,
|
||||
roots: []string{
|
||||
@@ -59,14 +55,6 @@ func newService(cfg *setting.Cfg, pluginStore plugins.Store) *Service {
|
||||
},
|
||||
}
|
||||
|
||||
resolver := plugins.CoreDataSourcePathResolver(cfg, pluginID)
|
||||
if err := pluginStore.AddWithFactory(context.Background(), pluginID, coreplugin.New(backend.ServeOpts{
|
||||
CheckHealthHandler: s,
|
||||
QueryDataHandler: s,
|
||||
}), resolver); err != nil {
|
||||
logger.Error("Failed to register plugin", "error", err)
|
||||
return nil
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
package grafanads
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
"github.com/grafana/grafana/pkg/plugins"
|
||||
"github.com/grafana/grafana/pkg/plugins/backendplugin"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
||||
@@ -21,7 +18,7 @@ func asJSON(v interface{}) json.RawMessage {
|
||||
}
|
||||
|
||||
func TestReadFolderListing(t *testing.T) {
|
||||
ds := newService(&setting.Cfg{StaticRootPath: "../../../public"}, &fakePluginStore{})
|
||||
ds := newService(&setting.Cfg{StaticRootPath: "../../../public"})
|
||||
dr := ds.doListQuery(backend.DataQuery{
|
||||
QueryType: "x",
|
||||
JSON: asJSON(listQueryModel{
|
||||
@@ -33,7 +30,7 @@ func TestReadFolderListing(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestReadCSVFile(t *testing.T) {
|
||||
ds := newService(&setting.Cfg{StaticRootPath: "../../../public"}, &fakePluginStore{})
|
||||
ds := newService(&setting.Cfg{StaticRootPath: "../../../public"})
|
||||
dr := ds.doReadQuery(backend.DataQuery{
|
||||
QueryType: "x",
|
||||
JSON: asJSON(readQueryModel{
|
||||
@@ -43,11 +40,3 @@ func TestReadCSVFile(t *testing.T) {
|
||||
err := experimental.CheckGoldenDataResponse(path.Join("testdata", "jslib.golden.txt"), &dr, true)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
type fakePluginStore struct {
|
||||
plugins.Store
|
||||
}
|
||||
|
||||
func (ps *fakePluginStore) AddWithFactory(_ context.Context, _ string, _ backendplugin.PluginFactoryFunc, _ plugins.PluginPathResolver) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user