Advisor: Include deprecated and filter by plugin slug (#105383)
This commit is contained in:
@@ -32,7 +32,6 @@ type check struct {
|
||||
PluginClient plugins.Client
|
||||
PluginRepo repo.Service
|
||||
GrafanaVersion string
|
||||
pluginIndex map[string]repo.PluginInfo
|
||||
}
|
||||
|
||||
func New(
|
||||
@@ -81,15 +80,6 @@ func (c *check) ID() string {
|
||||
}
|
||||
|
||||
func (c *check) Init(ctx context.Context) error {
|
||||
compatOpts := repo.NewCompatOpts(c.GrafanaVersion, sysruntime.GOOS, sysruntime.GOARCH)
|
||||
plugins, err := c.PluginRepo.GetPluginsInfo(ctx, compatOpts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
c.pluginIndex = make(map[string]repo.PluginInfo)
|
||||
for _, p := range plugins {
|
||||
c.pluginIndex[p.Slug] = p
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -102,8 +92,8 @@ func (c *check) Steps() []checks.Step {
|
||||
},
|
||||
&missingPluginStep{
|
||||
PluginStore: c.PluginStore,
|
||||
PluginRepo: c.PluginRepo,
|
||||
GrafanaVersion: c.GrafanaVersion,
|
||||
pluginIndex: c.pluginIndex,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -221,8 +211,8 @@ func (s *healthCheckStep) Run(ctx context.Context, log logging.Logger, obj *advi
|
||||
|
||||
type missingPluginStep struct {
|
||||
PluginStore pluginstore.Store
|
||||
PluginRepo repo.Service
|
||||
GrafanaVersion string
|
||||
pluginIndex map[string]repo.PluginInfo
|
||||
}
|
||||
|
||||
func (s *missingPluginStep) Title() string {
|
||||
@@ -255,8 +245,14 @@ func (s *missingPluginStep) Run(ctx context.Context, log logging.Logger, obj *ad
|
||||
Url: fmt.Sprintf("/connections/datasources/edit/%s", ds.UID),
|
||||
},
|
||||
}
|
||||
_, ok := s.pluginIndex[ds.Type]
|
||||
if ok {
|
||||
plugins, err := s.PluginRepo.GetPluginsInfo(ctx, repo.GetPluginsInfoOptions{
|
||||
IncludeDeprecated: true,
|
||||
Plugins: []string{ds.Type},
|
||||
}, repo.NewCompatOpts(s.GrafanaVersion, sysruntime.GOOS, sysruntime.GOARCH))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(plugins) > 0 {
|
||||
// Plugin is available in the repo
|
||||
links = append(links, advisor.CheckErrorLink{
|
||||
Message: "Install plugin",
|
||||
|
||||
@@ -276,6 +276,6 @@ type MockPluginRepo struct {
|
||||
plugins []repo.PluginInfo
|
||||
}
|
||||
|
||||
func (m *MockPluginRepo) GetPluginsInfo(context.Context, repo.CompatOpts) ([]repo.PluginInfo, error) {
|
||||
func (m *MockPluginRepo) GetPluginsInfo(context.Context, repo.GetPluginsInfoOptions, repo.CompatOpts) ([]repo.PluginInfo, error) {
|
||||
return m.plugins, nil
|
||||
}
|
||||
|
||||
@@ -64,7 +64,15 @@ func (c *check) Item(ctx context.Context, id string) (any, error) {
|
||||
|
||||
func (c *check) Init(ctx context.Context) error {
|
||||
compatOpts := repo.NewCompatOpts(c.GrafanaVersion, sysruntime.GOOS, sysruntime.GOARCH)
|
||||
plugins, err := c.PluginRepo.GetPluginsInfo(ctx, compatOpts)
|
||||
ps := c.PluginStore.Plugins(ctx)
|
||||
pluginIDs := make([]string, len(ps))
|
||||
for i, p := range ps {
|
||||
pluginIDs[i] = p.ID
|
||||
}
|
||||
plugins, err := c.PluginRepo.GetPluginsInfo(ctx, repo.GetPluginsInfoOptions{
|
||||
IncludeDeprecated: true,
|
||||
Plugins: pluginIDs,
|
||||
}, compatOpts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -168,7 +168,7 @@ type mockPluginRepo struct {
|
||||
pluginInfo []repo.PluginInfo
|
||||
}
|
||||
|
||||
func (m *mockPluginRepo) GetPluginsInfo(ctx context.Context, compatOpts repo.CompatOpts) ([]repo.PluginInfo, error) {
|
||||
func (m *mockPluginRepo) GetPluginsInfo(ctx context.Context, options repo.GetPluginsInfoOptions, compatOpts repo.CompatOpts) ([]repo.PluginInfo, error) {
|
||||
return m.pluginInfo, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user