Plugins: Replace CDN class with FS CDN type (#113968)
replace cdn class with fs type
This commit is contained in:
@@ -36,7 +36,7 @@ func NewPatternListInspector(detectorsProvider angulardetector.DetectorsProvider
|
||||
|
||||
func (i *PatternsListInspector) Inspect(ctx context.Context, p *plugins.Plugin) (isAngular bool, err error) {
|
||||
// CDN plugins are ignored because they should not be using Angular
|
||||
if p.Class == plugins.ClassCDN {
|
||||
if p.FS.Type().CDN() {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
"github.com/grafana/grafana/pkg/plugins"
|
||||
"github.com/grafana/grafana/pkg/plugins/manager/loader/angular/angulardetector"
|
||||
"github.com/grafana/grafana/pkg/plugins/manager/pluginfakes"
|
||||
)
|
||||
|
||||
type fakeDetector struct {
|
||||
@@ -81,7 +82,11 @@ func TestPatternsListInspector(t *testing.T) {
|
||||
{
|
||||
name: "CDN plugins return false without calling detectors",
|
||||
plugin: &plugins.Plugin{
|
||||
Class: plugins.ClassCDN,
|
||||
FS: &pluginfakes.FakePluginFS{
|
||||
TypeFunc: func() plugins.FSType {
|
||||
return plugins.FSTypeCDN
|
||||
},
|
||||
},
|
||||
},
|
||||
fakeDetectors: []*fakeDetector{
|
||||
{returns: true},
|
||||
|
||||
@@ -18,8 +18,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/pluginsintegration/pluginerrs"
|
||||
)
|
||||
|
||||
const concurrencyLimit = 32
|
||||
|
||||
type Loader struct {
|
||||
cfg *pluginsCfg.PluginManagementCfg
|
||||
discovery discovery.Discoverer
|
||||
@@ -87,37 +85,13 @@ func (l *Loader) Load(ctx context.Context, src plugins.PluginSource) ([]*plugins
|
||||
|
||||
st = time.Now()
|
||||
validatedPlugins := []*plugins.Plugin{}
|
||||
type validateResult struct {
|
||||
bootstrappedPlugin *plugins.Plugin
|
||||
err error
|
||||
}
|
||||
validateResults := make(chan validateResult, len(bootstrappedPlugins))
|
||||
|
||||
var limitSize int
|
||||
if src.PluginClass(ctx) == plugins.ClassCDN {
|
||||
limitSize = min(len(bootstrappedPlugins), concurrencyLimit)
|
||||
} else {
|
||||
limitSize = 1
|
||||
}
|
||||
limit := make(chan struct{}, limitSize)
|
||||
for _, bootstrappedPlugin := range bootstrappedPlugins {
|
||||
limit <- struct{}{}
|
||||
go func(p *plugins.Plugin) {
|
||||
err := l.validation.Validate(ctx, p)
|
||||
validateResults <- validateResult{
|
||||
bootstrappedPlugin: bootstrappedPlugin,
|
||||
err: err,
|
||||
}
|
||||
<-limit
|
||||
}(bootstrappedPlugin)
|
||||
}
|
||||
for i := 0; i < len(bootstrappedPlugins); i++ {
|
||||
r := <-validateResults
|
||||
if r.err != nil {
|
||||
l.recordError(ctx, r.bootstrappedPlugin, r.err)
|
||||
err := l.validation.Validate(ctx, bootstrappedPlugin)
|
||||
if err != nil {
|
||||
l.recordError(ctx, bootstrappedPlugin, err)
|
||||
continue
|
||||
}
|
||||
validatedPlugins = append(validatedPlugins, r.bootstrappedPlugin)
|
||||
validatedPlugins = append(validatedPlugins, bootstrappedPlugin)
|
||||
}
|
||||
l.log.Debug("Validated", "class", src.PluginClass(ctx), "duration", time.Since(st), "total", len(validatedPlugins))
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ func newModuleJSValidator() *ModuleJSValidator {
|
||||
|
||||
func (v *ModuleJSValidator) Validate(_ context.Context, p *plugins.Plugin) error {
|
||||
// CDN plugins are ignored because the module.js is guaranteed to exist
|
||||
if p.Class == plugins.ClassCDN {
|
||||
if p.FS.Type().CDN() {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -96,6 +96,11 @@ func newAngularDetector(cfg *config.PluginManagementCfg, angularInspector angula
|
||||
}
|
||||
|
||||
func (a *AngularDetector) Validate(ctx context.Context, p *plugins.Plugin) error {
|
||||
// CDN plugins are ignored because they should not be using Angular
|
||||
if p.FS.Type().CDN() {
|
||||
return nil
|
||||
}
|
||||
|
||||
if p.IsExternalPlugin() {
|
||||
var err error
|
||||
|
||||
|
||||
@@ -433,6 +433,7 @@ func (f *FakeActionSetRegistry) RegisterActionSets(_ context.Context, _ string,
|
||||
type FakePluginFS struct {
|
||||
OpenFunc func(name string) (fs.File, error)
|
||||
RemoveFunc func() error
|
||||
TypeFunc func() plugins.FSType
|
||||
RelFunc func(string) (string, error)
|
||||
|
||||
base string
|
||||
@@ -444,10 +445,6 @@ func NewFakePluginFS(base string) *FakePluginFS {
|
||||
}
|
||||
}
|
||||
|
||||
func (f *FakePluginFS) Type() string {
|
||||
return "fake"
|
||||
}
|
||||
|
||||
func (f *FakePluginFS) Open(name string) (fs.File, error) {
|
||||
if f.OpenFunc != nil {
|
||||
return f.OpenFunc(name)
|
||||
@@ -462,6 +459,13 @@ func (f *FakePluginFS) Rel(_ string) (string, error) {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
func (f *FakePluginFS) Type() plugins.FSType {
|
||||
if f.TypeFunc != nil {
|
||||
return f.TypeFunc()
|
||||
}
|
||||
return "fake"
|
||||
}
|
||||
|
||||
func (f *FakePluginFS) Base() string {
|
||||
return f.base
|
||||
}
|
||||
|
||||
@@ -345,7 +345,7 @@ func newPathSeparatorOverrideFS(sep string, ufs plugins.FS) (fsPathSeparatorFile
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (f fsPathSeparatorFiles) Type() string {
|
||||
func (f fsPathSeparatorFiles) Type() plugins.FSType {
|
||||
return f.FS.Type()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user