Advisor: Avoid one GCOM request per plugin (#105180)

This commit is contained in:
Andres Martinez Gotor
2025-05-12 09:45:56 +02:00
committed by GitHub
parent cb28213f1d
commit 0d4884cb3b
13 changed files with 137 additions and 115 deletions
@@ -32,6 +32,7 @@ type check struct {
PluginClient plugins.Client
PluginRepo repo.Service
GrafanaVersion string
pluginIndex map[string]repo.PluginInfo
}
func New(
@@ -79,6 +80,19 @@ func (c *check) ID() string {
return CheckID
}
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
}
func (c *check) Steps() []checks.Step {
return []checks.Step{
&uidValidationStep{},
@@ -88,8 +102,8 @@ func (c *check) Steps() []checks.Step {
},
&missingPluginStep{
PluginStore: c.PluginStore,
PluginRepo: c.PluginRepo,
GrafanaVersion: c.GrafanaVersion,
pluginIndex: c.pluginIndex,
},
}
}
@@ -207,8 +221,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 {
@@ -241,9 +255,8 @@ func (s *missingPluginStep) Run(ctx context.Context, log logging.Logger, obj *ad
Url: fmt.Sprintf("/connections/datasources/edit/%s", ds.UID),
},
}
compatOpts := repo.NewCompatOpts(s.GrafanaVersion, sysruntime.GOOS, sysruntime.GOARCH)
_, err := s.PluginRepo.PluginInfo(ctx, ds.Type, compatOpts)
if err == nil {
_, ok := s.pluginIndex[ds.Type]
if ok {
// Plugin is available in the repo
links = append(links, advisor.CheckErrorLink{
Message: "Install plugin",