Plugins: Use public store instead of internal registry (#57631)

* Plugins: Use public store instead of internal registry

* update comments

* fix import

* fix test
pull/57776/head
Will Browne 3 years ago committed by GitHub
parent facf2b1ee8
commit 9f77bd4728
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      pkg/plugins/ifaces.go
  2. 2
      pkg/plugins/manager/registry/ifaces.go
  3. 14
      pkg/services/store/resolver/ds_cache.go
  4. 17
      pkg/services/store/resolver/service.go
  5. 18
      pkg/services/store/resolver/service_test.go

@ -8,7 +8,7 @@ import (
"github.com/grafana/grafana/pkg/plugins/backendplugin"
)
// Store is the storage for plugins.
// Store is the publicly accessible storage for plugins.
type Store interface {
// Plugin finds a plugin by its ID.
Plugin(ctx context.Context, pluginID string) (PluginDTO, bool)

@ -6,7 +6,7 @@ import (
"github.com/grafana/grafana/pkg/plugins"
)
// Service is responsible for the storing and retrieval of plugins.
// Service is responsible for the internal storing and retrieval of plugins.
type Service interface {
// Plugin finds a plugin by its ID.
Plugin(ctx context.Context, id string) (*plugins.Plugin, bool)

@ -6,7 +6,7 @@ import (
"sync"
"time"
"github.com/grafana/grafana/pkg/plugins/manager/registry"
"github.com/grafana/grafana/pkg/plugins"
"github.com/grafana/grafana/pkg/services/datasources"
"github.com/grafana/grafana/pkg/services/store"
"github.com/grafana/grafana/pkg/tsdb/grafanads"
@ -22,11 +22,11 @@ type dsVal struct {
}
type dsCache struct {
ds datasources.DataSourceService
pluginRegistry registry.Service
cache map[int64]map[string]*dsVal
timestamp time.Time // across all orgIDs
mu sync.Mutex
ds datasources.DataSourceService
pluginStore plugins.Store
cache map[int64]map[string]*dsVal
timestamp time.Time // across all orgIDs
mu sync.Mutex
}
func (c *dsCache) refreshCache(ctx context.Context) error {
@ -56,7 +56,7 @@ func (c *dsCache) refreshCache(ctx context.Context) error {
Type: ds.Type,
IsDefault: ds.IsDefault,
}
_, ok := c.pluginRegistry.Plugin(ctx, val.Type)
_, ok := c.pluginStore.Plugin(ctx, val.Type)
val.PluginExists = ok
orgCache, ok := cache[ds.OrgId]

@ -7,7 +7,6 @@ import (
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/plugins"
"github.com/grafana/grafana/pkg/plugins/manager/registry"
"github.com/grafana/grafana/pkg/services/datasources"
)
@ -32,19 +31,19 @@ type ObjectReferenceResolver interface {
Resolve(ctx context.Context, ref *models.ObjectExternalReference) (ResolutionInfo, error)
}
func ProvideObjectReferenceResolver(ds datasources.DataSourceService, pluginRegistry registry.Service) ObjectReferenceResolver {
func ProvideObjectReferenceResolver(ds datasources.DataSourceService, pluginStore plugins.Store) ObjectReferenceResolver {
return &standardReferenceResolver{
pluginRegistry: pluginRegistry,
pluginStore: pluginStore,
ds: dsCache{
ds: ds,
pluginRegistry: pluginRegistry,
ds: ds,
pluginStore: pluginStore,
},
}
}
type standardReferenceResolver struct {
pluginRegistry registry.Service
ds dsCache
pluginStore plugins.Store
ds dsCache
}
func (r *standardReferenceResolver) Resolve(ctx context.Context, ref *models.ObjectExternalReference) (ResolutionInfo, error) {
@ -101,8 +100,8 @@ func (r *standardReferenceResolver) resolveDatasource(ctx context.Context, ref *
}
func (r *standardReferenceResolver) resolvePlugin(ctx context.Context, ref *models.ObjectExternalReference) (ResolutionInfo, error) {
p, ok := r.pluginRegistry.Plugin(ctx, ref.UID)
if !ok || p == nil {
p, ok := r.pluginStore.Plugin(ctx, ref.UID)
if !ok {
return ResolutionInfo{
OK: false,
Timestamp: getNow(),

@ -6,7 +6,6 @@ import (
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/plugins"
"github.com/grafana/grafana/pkg/plugins/manager/registry"
"github.com/grafana/grafana/pkg/services/datasources"
fakeDatasources "github.com/grafana/grafana/pkg/services/datasources/fakes"
"github.com/grafana/grafana/pkg/services/store"
@ -36,20 +35,17 @@ func TestResolver(t *testing.T) {
},
}
p1 := &plugins.Plugin{}
p2 := &plugins.Plugin{}
p3 := &plugins.Plugin{}
p1 := plugins.PluginDTO{}
p2 := plugins.PluginDTO{}
p3 := plugins.PluginDTO{}
p1.ID = "influx"
p2.ID = "heatmap"
p3.ID = "xyz"
pluginRegistry := registry.ProvideService()
_ = pluginRegistry.Add(ctxOrg1, p1)
_ = pluginRegistry.Add(ctxOrg1, p2)
_ = pluginRegistry.Add(ctxOrg1, p3)
provider := ProvideObjectReferenceResolver(ds, pluginRegistry)
pluginStore := plugins.FakePluginStore{
PluginList: []plugins.PluginDTO{p1, p2, p3},
}
provider := ProvideObjectReferenceResolver(ds, pluginStore)
scenarios := []struct {
name string

Loading…
Cancel
Save