Plugins: Move discovery logic to plugin sources (#106911)
* move finder behaviour to source * tidy * undo go.mod changes * fix comment * tidy unsafe local source
This commit is contained in:
@@ -4,6 +4,8 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/infra/tracing"
|
||||
"github.com/grafana/grafana/pkg/plugins"
|
||||
@@ -23,7 +25,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/pluginsintegration/pipeline"
|
||||
"github.com/grafana/grafana/pkg/services/pluginsintegration/pluginerrs"
|
||||
"github.com/grafana/grafana/pkg/services/rendering"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
func ProvideService(cfg *config.PluginManagementCfg, pluginEnvProvider envvars.Provider,
|
||||
@@ -84,7 +85,7 @@ func (m *Manager) Renderer(ctx context.Context) (rendering.Plugin, bool) {
|
||||
return m.renderer, true
|
||||
}
|
||||
|
||||
srcs, err := sources.DirAsLocalSources(m.cfg.PluginsPath, plugins.ClassExternal)
|
||||
srcs, err := sources.DirAsLocalSources(m.cfg, m.cfg.PluginsPath, plugins.ClassExternal)
|
||||
if err != nil {
|
||||
m.log.Error("Failed to get renderer plugin sources", "error", err)
|
||||
return nil, false
|
||||
@@ -109,7 +110,7 @@ func (m *Manager) Renderer(ctx context.Context) (rendering.Plugin, bool) {
|
||||
func createLoader(cfg *config.PluginManagementCfg, pluginEnvProvider envvars.Provider,
|
||||
pr registry.Service, tracer trace.Tracer) (loader.Service, error) {
|
||||
d := discovery.New(cfg, discovery.Opts{
|
||||
FindFilterFuncs: []discovery.FindFilterFunc{
|
||||
FilterFuncs: []discovery.FilterFunc{
|
||||
discovery.NewPermittedPluginTypesFilterStep([]plugins.Type{plugins.TypeRenderer}),
|
||||
func(ctx context.Context, class plugins.Class, bundles []*plugins.FoundBundle) ([]*plugins.FoundBundle, error) {
|
||||
return pipeline.NewDuplicatePluginIDFilterStep(pr).Filter(ctx, bundles)
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/plugins"
|
||||
"github.com/grafana/grafana/pkg/plugins/config"
|
||||
"github.com/grafana/grafana/pkg/plugins/manager/fakes"
|
||||
"github.com/grafana/grafana/pkg/plugins/manager/sources"
|
||||
)
|
||||
|
||||
func TestRenderer(t *testing.T) {
|
||||
@@ -22,8 +23,14 @@ func TestRenderer(t *testing.T) {
|
||||
loader := &fakes.FakeLoader{
|
||||
LoadFunc: func(ctx context.Context, src plugins.PluginSource) ([]*plugins.Plugin, error) {
|
||||
require.True(t, src.PluginClass(ctx) == plugins.ClassExternal)
|
||||
require.Len(t, src.PluginURIs(ctx), 1)
|
||||
require.True(t, strings.HasPrefix(src.PluginURIs(ctx)[0], testdataDir))
|
||||
|
||||
if localSrc, ok := src.(*sources.LocalSource); ok {
|
||||
paths := localSrc.Paths()
|
||||
require.Len(t, paths, 1)
|
||||
require.True(t, strings.HasPrefix(paths[0], testdataDir))
|
||||
} else {
|
||||
t.Fatalf("Expected LocalSource, got %T", src)
|
||||
}
|
||||
|
||||
numLoaded++
|
||||
return []*plugins.Plugin{}, nil
|
||||
@@ -55,9 +62,16 @@ func TestRenderer(t *testing.T) {
|
||||
loader := &fakes.FakeLoader{
|
||||
LoadFunc: func(ctx context.Context, src plugins.PluginSource) ([]*plugins.Plugin, error) {
|
||||
numLoaded++
|
||||
if strings.HasPrefix(src.PluginURIs(ctx)[0], filepath.Join(testdataDir, "renderer")) {
|
||||
return []*plugins.Plugin{p}, nil
|
||||
|
||||
if localSrc, ok := src.(*sources.LocalSource); ok {
|
||||
paths := localSrc.Paths()
|
||||
if strings.HasPrefix(paths[0], filepath.Join(testdataDir, "renderer")) {
|
||||
return []*plugins.Plugin{p}, nil
|
||||
}
|
||||
} else {
|
||||
t.Fatalf("Expected LocalSource, got %T", src)
|
||||
}
|
||||
|
||||
return []*plugins.Plugin{}, nil
|
||||
},
|
||||
UnloadFunc: func(_ context.Context, _ *plugins.Plugin) (*plugins.Plugin, error) {
|
||||
|
||||
Reference in New Issue
Block a user