Plugins: Introduce Plugin Registry (#47200)
* introduce registry write/read separation * internal + external registries * fix tests * fixup * rename * move interfaces * back to plugins.Store * fix registry name * remove context.TODOs * remove some ctx for now * tidy * remove dupe logic * update naming * move from manager.go to store * amend logger name * new store writer svc * restrict changes * more simplifying * move interfaces around * remove unused * fix linter * tidy * add registry test * fix tests * revert testdata changes * revert testdata changes #1 * revert testdata changes #2 * revert testdata changes #3 * revert testdata changes #4 * revert testdata changes #5 * revert testdata changes * fixup testdata * remove unused log * update naming in test * adjust ctx in test
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/plugins/backendplugin/coreplugin"
|
||||
"github.com/grafana/grafana/pkg/plugins/backendplugin/provider"
|
||||
"github.com/grafana/grafana/pkg/plugins/manager/loader"
|
||||
"github.com/grafana/grafana/pkg/plugins/manager/registry"
|
||||
"github.com/grafana/grafana/pkg/plugins/manager/signature"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"github.com/grafana/grafana/pkg/services/licensing"
|
||||
@@ -92,16 +93,17 @@ func TestPluginManager_int_init(t *testing.T) {
|
||||
coreRegistry := coreplugin.ProvideCoreRegistry(am, cw, cm, es, grap, idb, lk, otsdb, pr, tmpo, td, pg, my, ms, graf)
|
||||
|
||||
pmCfg := plugins.FromGrafanaCfg(cfg)
|
||||
pm, err := ProvideService(cfg, loader.New(pmCfg, license, signature.NewUnsignedAuthorizer(pmCfg),
|
||||
pm, err := ProvideService(cfg, registry.NewInMemory(), loader.New(pmCfg, license, signature.NewUnsignedAuthorizer(pmCfg),
|
||||
provider.ProvideService(coreRegistry)))
|
||||
require.NoError(t, err)
|
||||
|
||||
verifyCorePluginCatalogue(t, pm)
|
||||
verifyBundledPlugins(t, pm)
|
||||
verifyPluginStaticRoutes(t, pm)
|
||||
ctx := context.Background()
|
||||
verifyCorePluginCatalogue(t, ctx, pm)
|
||||
verifyBundledPlugins(t, ctx, pm)
|
||||
verifyPluginStaticRoutes(t, ctx, pm)
|
||||
}
|
||||
|
||||
func verifyCorePluginCatalogue(t *testing.T, pm *PluginManager) {
|
||||
func verifyCorePluginCatalogue(t *testing.T, ctx context.Context, pm *PluginManager) {
|
||||
t.Helper()
|
||||
|
||||
expPanels := map[string]struct{}{
|
||||
@@ -167,44 +169,44 @@ func verifyCorePluginCatalogue(t *testing.T, pm *PluginManager) {
|
||||
"test-app": {},
|
||||
}
|
||||
|
||||
panels := pm.Plugins(context.Background(), plugins.Panel)
|
||||
panels := pm.Plugins(ctx, plugins.Panel)
|
||||
assert.Equal(t, len(expPanels), len(panels))
|
||||
for _, p := range panels {
|
||||
p, exists := pm.Plugin(context.Background(), p.ID)
|
||||
p, exists := pm.Plugin(ctx, p.ID)
|
||||
require.NotEqual(t, plugins.PluginDTO{}, p)
|
||||
assert.True(t, exists)
|
||||
assert.Contains(t, expPanels, p.ID)
|
||||
assert.Contains(t, pm.registeredPlugins(), p.ID)
|
||||
assert.Contains(t, pm.registeredPlugins(ctx), p.ID)
|
||||
}
|
||||
|
||||
dataSources := pm.Plugins(context.Background(), plugins.DataSource)
|
||||
dataSources := pm.Plugins(ctx, plugins.DataSource)
|
||||
assert.Equal(t, len(expDataSources), len(dataSources))
|
||||
for _, ds := range dataSources {
|
||||
p, exists := pm.Plugin(context.Background(), ds.ID)
|
||||
p, exists := pm.Plugin(ctx, ds.ID)
|
||||
require.NotEqual(t, plugins.PluginDTO{}, p)
|
||||
assert.True(t, exists)
|
||||
assert.Contains(t, expDataSources, ds.ID)
|
||||
assert.Contains(t, pm.registeredPlugins(), ds.ID)
|
||||
assert.Contains(t, pm.registeredPlugins(ctx), ds.ID)
|
||||
}
|
||||
|
||||
apps := pm.Plugins(context.Background(), plugins.App)
|
||||
apps := pm.Plugins(ctx, plugins.App)
|
||||
assert.Equal(t, len(expApps), len(apps))
|
||||
for _, app := range apps {
|
||||
p, exists := pm.Plugin(context.Background(), app.ID)
|
||||
p, exists := pm.Plugin(ctx, app.ID)
|
||||
require.NotEqual(t, plugins.PluginDTO{}, p)
|
||||
assert.True(t, exists)
|
||||
assert.Contains(t, expApps, app.ID)
|
||||
assert.Contains(t, pm.registeredPlugins(), app.ID)
|
||||
assert.Contains(t, pm.registeredPlugins(ctx), app.ID)
|
||||
}
|
||||
|
||||
assert.Equal(t, len(expPanels)+len(expDataSources)+len(expApps), len(pm.Plugins(context.Background())))
|
||||
assert.Equal(t, len(expPanels)+len(expDataSources)+len(expApps), len(pm.Plugins(ctx)))
|
||||
}
|
||||
|
||||
func verifyBundledPlugins(t *testing.T, pm *PluginManager) {
|
||||
func verifyBundledPlugins(t *testing.T, ctx context.Context, pm *PluginManager) {
|
||||
t.Helper()
|
||||
|
||||
dsPlugins := make(map[string]struct{})
|
||||
for _, p := range pm.Plugins(context.Background(), plugins.DataSource) {
|
||||
for _, p := range pm.Plugins(ctx, plugins.DataSource) {
|
||||
dsPlugins[p.ID] = struct{}{}
|
||||
}
|
||||
|
||||
@@ -213,7 +215,7 @@ func verifyBundledPlugins(t *testing.T, pm *PluginManager) {
|
||||
pluginRoutes[r.PluginID] = r
|
||||
}
|
||||
|
||||
inputPlugin, exists := pm.Plugin(context.Background(), "input")
|
||||
inputPlugin, exists := pm.Plugin(ctx, "input")
|
||||
require.NotEqual(t, plugins.PluginDTO{}, inputPlugin)
|
||||
assert.True(t, exists)
|
||||
assert.NotNil(t, dsPlugins["input"])
|
||||
@@ -224,7 +226,7 @@ func verifyBundledPlugins(t *testing.T, pm *PluginManager) {
|
||||
}
|
||||
}
|
||||
|
||||
func verifyPluginStaticRoutes(t *testing.T, pm *PluginManager) {
|
||||
func verifyPluginStaticRoutes(t *testing.T, ctx context.Context, pm *PluginManager) {
|
||||
routes := make(map[string]*plugins.StaticRoute)
|
||||
for _, route := range pm.Routes() {
|
||||
routes[route.PluginID] = route
|
||||
@@ -232,11 +234,11 @@ func verifyPluginStaticRoutes(t *testing.T, pm *PluginManager) {
|
||||
|
||||
assert.Len(t, routes, 2)
|
||||
|
||||
inputPlugin, _ := pm.Plugin(context.Background(), "input")
|
||||
inputPlugin, _ := pm.Plugin(ctx, "input")
|
||||
assert.NotNil(t, routes["input"])
|
||||
assert.Equal(t, routes["input"].Directory, inputPlugin.PluginDir)
|
||||
|
||||
testAppPlugin, _ := pm.Plugin(context.Background(), "test-app")
|
||||
testAppPlugin, _ := pm.Plugin(ctx, "test-app")
|
||||
assert.Contains(t, routes, "test-app")
|
||||
assert.Equal(t, routes["test-app"].Directory, testAppPlugin.PluginDir)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user