mirror of
https://github.com/grafana/grafana.git
synced 2025-07-30 16:02:31 +08:00
Advisor: Ensure User-Agent header is set for checks (#105122)
This commit is contained in:

committed by
GitHub

parent
0978ec5e91
commit
8ef8185379
@ -14,6 +14,7 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/pluginsintegration/pluginstore"
|
"github.com/grafana/grafana/pkg/services/pluginsintegration/pluginstore"
|
||||||
"github.com/grafana/grafana/pkg/services/pluginsintegration/provisionedplugins"
|
"github.com/grafana/grafana/pkg/services/pluginsintegration/provisionedplugins"
|
||||||
"github.com/grafana/grafana/pkg/services/ssosettings"
|
"github.com/grafana/grafana/pkg/services/ssosettings"
|
||||||
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CheckService interface {
|
type CheckService interface {
|
||||||
@ -30,12 +31,14 @@ type Service struct {
|
|||||||
managedPlugins managedplugins.Manager
|
managedPlugins managedplugins.Manager
|
||||||
provisionedPlugins provisionedplugins.Manager
|
provisionedPlugins provisionedplugins.Manager
|
||||||
ssoSettingsSvc ssosettings.Service
|
ssoSettingsSvc ssosettings.Service
|
||||||
|
GrafanaVersion string
|
||||||
}
|
}
|
||||||
|
|
||||||
func ProvideService(datasourceSvc datasources.DataSourceService, pluginStore pluginstore.Store,
|
func ProvideService(datasourceSvc datasources.DataSourceService, pluginStore pluginstore.Store,
|
||||||
pluginContextProvider *plugincontext.Provider, pluginClient plugins.Client,
|
pluginContextProvider *plugincontext.Provider, pluginClient plugins.Client,
|
||||||
pluginRepo repo.Service, pluginPreinstall plugininstaller.Preinstall, managedPlugins managedplugins.Manager,
|
pluginRepo repo.Service, pluginPreinstall plugininstaller.Preinstall, managedPlugins managedplugins.Manager,
|
||||||
provisionedPlugins provisionedplugins.Manager, ssoSettingsSvc ssosettings.Service,
|
provisionedPlugins provisionedplugins.Manager, ssoSettingsSvc ssosettings.Service, settings *setting.Cfg,
|
||||||
|
|
||||||
) *Service {
|
) *Service {
|
||||||
return &Service{
|
return &Service{
|
||||||
datasourceSvc: datasourceSvc,
|
datasourceSvc: datasourceSvc,
|
||||||
@ -47,6 +50,7 @@ func ProvideService(datasourceSvc datasources.DataSourceService, pluginStore plu
|
|||||||
managedPlugins: managedPlugins,
|
managedPlugins: managedPlugins,
|
||||||
provisionedPlugins: provisionedPlugins,
|
provisionedPlugins: provisionedPlugins,
|
||||||
ssoSettingsSvc: ssoSettingsSvc,
|
ssoSettingsSvc: ssoSettingsSvc,
|
||||||
|
GrafanaVersion: settings.BuildVersion,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,6 +62,7 @@ func (s *Service) Checks() []checks.Check {
|
|||||||
s.pluginContextProvider,
|
s.pluginContextProvider,
|
||||||
s.pluginClient,
|
s.pluginClient,
|
||||||
s.pluginRepo,
|
s.pluginRepo,
|
||||||
|
s.GrafanaVersion,
|
||||||
),
|
),
|
||||||
plugincheck.New(
|
plugincheck.New(
|
||||||
s.pluginStore,
|
s.pluginStore,
|
||||||
@ -65,6 +70,7 @@ func (s *Service) Checks() []checks.Check {
|
|||||||
s.pluginPreinstall,
|
s.pluginPreinstall,
|
||||||
s.managedPlugins,
|
s.managedPlugins,
|
||||||
s.provisionedPlugins,
|
s.provisionedPlugins,
|
||||||
|
s.GrafanaVersion,
|
||||||
),
|
),
|
||||||
authchecks.New(s.ssoSettingsSvc),
|
authchecks.New(s.ssoSettingsSvc),
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
sysruntime "runtime"
|
||||||
|
|
||||||
"github.com/grafana/grafana-app-sdk/logging"
|
"github.com/grafana/grafana-app-sdk/logging"
|
||||||
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
||||||
@ -30,6 +31,7 @@ type check struct {
|
|||||||
PluginContextProvider pluginContextProvider
|
PluginContextProvider pluginContextProvider
|
||||||
PluginClient plugins.Client
|
PluginClient plugins.Client
|
||||||
PluginRepo repo.Service
|
PluginRepo repo.Service
|
||||||
|
GrafanaVersion string
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(
|
func New(
|
||||||
@ -38,6 +40,7 @@ func New(
|
|||||||
pluginContextProvider pluginContextProvider,
|
pluginContextProvider pluginContextProvider,
|
||||||
pluginClient plugins.Client,
|
pluginClient plugins.Client,
|
||||||
pluginRepo repo.Service,
|
pluginRepo repo.Service,
|
||||||
|
grafanaVersion string,
|
||||||
) checks.Check {
|
) checks.Check {
|
||||||
return &check{
|
return &check{
|
||||||
DatasourceSvc: datasourceSvc,
|
DatasourceSvc: datasourceSvc,
|
||||||
@ -45,6 +48,7 @@ func New(
|
|||||||
PluginContextProvider: pluginContextProvider,
|
PluginContextProvider: pluginContextProvider,
|
||||||
PluginClient: pluginClient,
|
PluginClient: pluginClient,
|
||||||
PluginRepo: pluginRepo,
|
PluginRepo: pluginRepo,
|
||||||
|
GrafanaVersion: grafanaVersion,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,8 +87,9 @@ func (c *check) Steps() []checks.Step {
|
|||||||
PluginClient: c.PluginClient,
|
PluginClient: c.PluginClient,
|
||||||
},
|
},
|
||||||
&missingPluginStep{
|
&missingPluginStep{
|
||||||
PluginStore: c.PluginStore,
|
PluginStore: c.PluginStore,
|
||||||
PluginRepo: c.PluginRepo,
|
PluginRepo: c.PluginRepo,
|
||||||
|
GrafanaVersion: c.GrafanaVersion,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -201,8 +206,9 @@ func (s *healthCheckStep) Run(ctx context.Context, log logging.Logger, obj *advi
|
|||||||
}
|
}
|
||||||
|
|
||||||
type missingPluginStep struct {
|
type missingPluginStep struct {
|
||||||
PluginStore pluginstore.Store
|
PluginStore pluginstore.Store
|
||||||
PluginRepo repo.Service
|
PluginRepo repo.Service
|
||||||
|
GrafanaVersion string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *missingPluginStep) Title() string {
|
func (s *missingPluginStep) Title() string {
|
||||||
@ -235,7 +241,8 @@ func (s *missingPluginStep) Run(ctx context.Context, log logging.Logger, obj *ad
|
|||||||
Url: fmt.Sprintf("/connections/datasources/edit/%s", ds.UID),
|
Url: fmt.Sprintf("/connections/datasources/edit/%s", ds.UID),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
_, err := s.PluginRepo.PluginInfo(ctx, ds.Type)
|
compatOpts := repo.NewCompatOpts(s.GrafanaVersion, sysruntime.GOOS, sysruntime.GOARCH)
|
||||||
|
_, err := s.PluginRepo.PluginInfo(ctx, ds.Type, compatOpts)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
// Plugin is available in the repo
|
// Plugin is available in the repo
|
||||||
links = append(links, advisor.CheckErrorLink{
|
links = append(links, advisor.CheckErrorLink{
|
||||||
|
@ -260,7 +260,7 @@ type MockPluginRepo struct {
|
|||||||
exists bool
|
exists bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MockPluginRepo) PluginInfo(context.Context, string) (*repo.PluginInfo, error) {
|
func (m *MockPluginRepo) PluginInfo(context.Context, string, repo.CompatOpts) (*repo.PluginInfo, error) {
|
||||||
if !m.exists {
|
if !m.exists {
|
||||||
return nil, errors.New("plugin not found")
|
return nil, errors.New("plugin not found")
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,6 @@ import (
|
|||||||
"github.com/grafana/grafana-app-sdk/logging"
|
"github.com/grafana/grafana-app-sdk/logging"
|
||||||
advisor "github.com/grafana/grafana/apps/advisor/pkg/apis/advisor/v0alpha1"
|
advisor "github.com/grafana/grafana/apps/advisor/pkg/apis/advisor/v0alpha1"
|
||||||
"github.com/grafana/grafana/apps/advisor/pkg/app/checks"
|
"github.com/grafana/grafana/apps/advisor/pkg/app/checks"
|
||||||
"github.com/grafana/grafana/pkg/cmd/grafana-cli/services"
|
|
||||||
"github.com/grafana/grafana/pkg/plugins/repo"
|
"github.com/grafana/grafana/pkg/plugins/repo"
|
||||||
"github.com/grafana/grafana/pkg/services/pluginsintegration/managedplugins"
|
"github.com/grafana/grafana/pkg/services/pluginsintegration/managedplugins"
|
||||||
"github.com/grafana/grafana/pkg/services/pluginsintegration/plugininstaller"
|
"github.com/grafana/grafana/pkg/services/pluginsintegration/plugininstaller"
|
||||||
@ -30,6 +29,7 @@ func New(
|
|||||||
pluginPreinstall plugininstaller.Preinstall,
|
pluginPreinstall plugininstaller.Preinstall,
|
||||||
managedPlugins managedplugins.Manager,
|
managedPlugins managedplugins.Manager,
|
||||||
provisionedPlugins provisionedplugins.Manager,
|
provisionedPlugins provisionedplugins.Manager,
|
||||||
|
grafanaVersion string,
|
||||||
) checks.Check {
|
) checks.Check {
|
||||||
return &check{
|
return &check{
|
||||||
PluginStore: pluginStore,
|
PluginStore: pluginStore,
|
||||||
@ -37,6 +37,7 @@ func New(
|
|||||||
PluginPreinstall: pluginPreinstall,
|
PluginPreinstall: pluginPreinstall,
|
||||||
ManagedPlugins: managedPlugins,
|
ManagedPlugins: managedPlugins,
|
||||||
ProvisionedPlugins: provisionedPlugins,
|
ProvisionedPlugins: provisionedPlugins,
|
||||||
|
GrafanaVersion: grafanaVersion,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,6 +47,7 @@ type check struct {
|
|||||||
PluginPreinstall plugininstaller.Preinstall
|
PluginPreinstall plugininstaller.Preinstall
|
||||||
ManagedPlugins managedplugins.Manager
|
ManagedPlugins managedplugins.Manager
|
||||||
ProvisionedPlugins provisionedplugins.Manager
|
ProvisionedPlugins provisionedplugins.Manager
|
||||||
|
GrafanaVersion string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *check) ID() string {
|
func (c *check) ID() string {
|
||||||
@ -76,12 +78,14 @@ func (c *check) Steps() []checks.Step {
|
|||||||
PluginPreinstall: c.PluginPreinstall,
|
PluginPreinstall: c.PluginPreinstall,
|
||||||
ManagedPlugins: c.ManagedPlugins,
|
ManagedPlugins: c.ManagedPlugins,
|
||||||
ProvisionedPlugins: c.ProvisionedPlugins,
|
ProvisionedPlugins: c.ProvisionedPlugins,
|
||||||
|
GrafanaVersion: c.GrafanaVersion,
|
||||||
},
|
},
|
||||||
&updateStep{
|
&updateStep{
|
||||||
PluginRepo: c.PluginRepo,
|
PluginRepo: c.PluginRepo,
|
||||||
PluginPreinstall: c.PluginPreinstall,
|
PluginPreinstall: c.PluginPreinstall,
|
||||||
ManagedPlugins: c.ManagedPlugins,
|
ManagedPlugins: c.ManagedPlugins,
|
||||||
ProvisionedPlugins: c.ProvisionedPlugins,
|
ProvisionedPlugins: c.ProvisionedPlugins,
|
||||||
|
GrafanaVersion: c.GrafanaVersion,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -91,6 +95,7 @@ type deprecationStep struct {
|
|||||||
PluginPreinstall plugininstaller.Preinstall
|
PluginPreinstall plugininstaller.Preinstall
|
||||||
ManagedPlugins managedplugins.Manager
|
ManagedPlugins managedplugins.Manager
|
||||||
ProvisionedPlugins provisionedplugins.Manager
|
ProvisionedPlugins provisionedplugins.Manager
|
||||||
|
GrafanaVersion string
|
||||||
provisionedPlugins []string
|
provisionedPlugins []string
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,7 +141,8 @@ func (s *deprecationStep) Run(ctx context.Context, log logging.Logger, _ *adviso
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if plugin is deprecated
|
// Check if plugin is deprecated
|
||||||
i, err := s.PluginRepo.PluginInfo(ctx, p.ID)
|
compatOpts := repo.NewCompatOpts(s.GrafanaVersion, sysruntime.GOOS, sysruntime.GOARCH)
|
||||||
|
i, err := s.PluginRepo.PluginInfo(ctx, p.ID, compatOpts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Unable to check deprecation status
|
// Unable to check deprecation status
|
||||||
return nil, nil
|
return nil, nil
|
||||||
@ -164,6 +170,7 @@ type updateStep struct {
|
|||||||
ManagedPlugins managedplugins.Manager
|
ManagedPlugins managedplugins.Manager
|
||||||
ProvisionedPlugins provisionedplugins.Manager
|
ProvisionedPlugins provisionedplugins.Manager
|
||||||
provisionedPlugins []string
|
provisionedPlugins []string
|
||||||
|
GrafanaVersion string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *updateStep) Title() string {
|
func (s *updateStep) Title() string {
|
||||||
@ -207,7 +214,7 @@ func (s *updateStep) Run(ctx context.Context, log logging.Logger, _ *advisor.Che
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if plugin has a newer version available
|
// Check if plugin has a newer version available
|
||||||
compatOpts := repo.NewCompatOpts(services.GrafanaVersion, sysruntime.GOOS, sysruntime.GOARCH)
|
compatOpts := repo.NewCompatOpts(s.GrafanaVersion, sysruntime.GOOS, sysruntime.GOARCH)
|
||||||
info, err := s.PluginRepo.GetPluginArchiveInfo(ctx, p.ID, "", compatOpts)
|
info, err := s.PluginRepo.GetPluginArchiveInfo(ctx, p.ID, "", compatOpts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Unable to check updates
|
// Unable to check updates
|
||||||
|
@ -163,7 +163,7 @@ func TestRun(t *testing.T) {
|
|||||||
pluginPreinstall := &mockPluginPreinstall{pinned: tt.pluginPreinstalled}
|
pluginPreinstall := &mockPluginPreinstall{pinned: tt.pluginPreinstalled}
|
||||||
managedPlugins := &mockManagedPlugins{managed: tt.pluginManaged}
|
managedPlugins := &mockManagedPlugins{managed: tt.pluginManaged}
|
||||||
provisionedPlugins := &mockProvisionedPlugins{provisioned: tt.pluginProvisioned}
|
provisionedPlugins := &mockProvisionedPlugins{provisioned: tt.pluginProvisioned}
|
||||||
check := New(pluginStore, pluginRepo, pluginPreinstall, managedPlugins, provisionedPlugins)
|
check := New(pluginStore, pluginRepo, pluginPreinstall, managedPlugins, provisionedPlugins, "12.0.0")
|
||||||
|
|
||||||
items, err := check.Items(context.Background())
|
items, err := check.Items(context.Background())
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
@ -199,7 +199,7 @@ type mockPluginRepo struct {
|
|||||||
pluginArchiveInfo map[string]*repo.PluginArchiveInfo
|
pluginArchiveInfo map[string]*repo.PluginArchiveInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockPluginRepo) PluginInfo(ctx context.Context, id string) (*repo.PluginInfo, error) {
|
func (m *mockPluginRepo) PluginInfo(ctx context.Context, id string, compatOpts repo.CompatOpts) (*repo.PluginInfo, error) {
|
||||||
return m.pluginInfo[id], nil
|
return m.pluginInfo[id], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -272,7 +272,7 @@ func (r *FakePluginRepo) PluginVersion(ctx context.Context, pluginID, version st
|
|||||||
return repo.VersionData{}, nil
|
return repo.VersionData{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *FakePluginRepo) PluginInfo(ctx context.Context, pluginID string) (*repo.PluginInfo, error) {
|
func (r *FakePluginRepo) PluginInfo(ctx context.Context, pluginID string, compatOpts repo.CompatOpts) (*repo.PluginInfo, error) {
|
||||||
return &repo.PluginInfo{}, nil
|
return &repo.PluginInfo{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ type Service interface {
|
|||||||
// PluginVersion will return plugin version based on the requested information.
|
// PluginVersion will return plugin version based on the requested information.
|
||||||
PluginVersion(ctx context.Context, pluginID, version string, compatOpts CompatOpts) (VersionData, error)
|
PluginVersion(ctx context.Context, pluginID, version string, compatOpts CompatOpts) (VersionData, error)
|
||||||
// PluginInfo will return generic plugin information from grafana.com/api/plugins.
|
// PluginInfo will return generic plugin information from grafana.com/api/plugins.
|
||||||
PluginInfo(ctx context.Context, pluginID string) (*PluginInfo, error)
|
PluginInfo(ctx context.Context, pluginID string, compatOpts CompatOpts) (*PluginInfo, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type CompatOpts struct {
|
type CompatOpts struct {
|
||||||
|
@ -132,7 +132,7 @@ func (m *Manager) grafanaCompatiblePluginVersions(ctx context.Context, pluginID
|
|||||||
return v.Versions, nil
|
return v.Versions, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Manager) PluginInfo(ctx context.Context, pluginID string) (*PluginInfo, error) {
|
func (m *Manager) PluginInfo(ctx context.Context, pluginID string, compatOpts CompatOpts) (*PluginInfo, error) {
|
||||||
u, err := url.Parse(m.client.grafanaComAPIURL)
|
u, err := url.Parse(m.client.grafanaComAPIURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -140,7 +140,7 @@ func (m *Manager) PluginInfo(ctx context.Context, pluginID string) (*PluginInfo,
|
|||||||
|
|
||||||
u.Path = path.Join(u.Path, pluginID)
|
u.Path = path.Join(u.Path, pluginID)
|
||||||
|
|
||||||
body, err := m.client.SendReq(ctx, u, CompatOpts{})
|
body, err := m.client.SendReq(ctx, u, compatOpts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -126,7 +126,7 @@ func TestPluginInfo(t *testing.T) {
|
|||||||
BaseURL: srv.URL,
|
BaseURL: srv.URL,
|
||||||
Logger: log.NewTestPrettyLogger(),
|
Logger: log.NewTestPrettyLogger(),
|
||||||
})
|
})
|
||||||
pi, err := m.PluginInfo(context.Background(), pluginID)
|
pi, err := m.PluginInfo(context.Background(), pluginID, CompatOpts{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, 1, pi.ID)
|
require.Equal(t, 1, pi.ID)
|
||||||
require.Equal(t, pluginID, pi.Slug)
|
require.Equal(t, pluginID, pi.Slug)
|
||||||
|
Reference in New Issue
Block a user