Chore: Advisor stats (#103711)

This commit is contained in:
Andres Martinez Gotor
2025-04-10 10:51:00 +02:00
committed by GitHub
parent 3f3a4c1e8a
commit 89c70fcdcf
7 changed files with 314 additions and 9 deletions
+15 -3
View File
@@ -19,6 +19,7 @@ import (
"github.com/grafana/grafana/pkg/registry"
"github.com/grafana/grafana/pkg/services/datasources"
"github.com/grafana/grafana/pkg/services/featuremgmt"
"github.com/grafana/grafana/pkg/services/pluginsintegration/advisor"
"github.com/grafana/grafana/pkg/services/pluginsintegration/pluginstore"
"github.com/grafana/grafana/pkg/services/pluginsintegration/sandbox"
"github.com/grafana/grafana/pkg/services/stats"
@@ -41,6 +42,7 @@ type Service struct {
datasources datasources.DataSourceService
httpClientProvider httpclient.Provider
sandbox sandbox.Sandbox
advisor advisor.AdvisorStats
log log.Logger
@@ -61,6 +63,7 @@ func ProvideService(
datasourceService datasources.DataSourceService,
httpClientProvider httpclient.Provider,
sandbox sandbox.Sandbox,
advisor advisor.AdvisorStats,
) *Service {
s := &Service{
cfg: cfg,
@@ -73,9 +76,9 @@ func ProvideService(
datasources: datasourceService,
httpClientProvider: httpClientProvider,
sandbox: sandbox,
startTime: time.Now(),
log: log.New("infra.usagestats.collector"),
advisor: advisor,
startTime: time.Now(),
log: log.New("infra.usagestats.collector"),
}
collectors := []usagestats.MetricsFunc{
@@ -215,6 +218,15 @@ func (s *Service) collectSystemStats(ctx context.Context) (map[string]any, error
m["stats.uptime"] = int64(time.Since(s.startTime).Seconds())
report, err := s.advisor.ReportSummary(ctx)
if err != nil {
s.log.Error("Failed to get advisor usage stats", "error", err)
} else {
m["stats.plugins.advisor.outdated_plugins"] = report.PluginsOutdated
m["stats.plugins.advisor.deprecated_plugins"] = report.PluginsDeprecated
m["stats.plugins.advisor.unhealthy_datasources"] = report.DatasourcesUnhealthy
}
featureUsageStats := s.features.GetUsageStats(ctx)
for k, v := range featureUsageStats {
m[k] = v
@@ -23,6 +23,7 @@ import (
"github.com/grafana/grafana/pkg/registry"
"github.com/grafana/grafana/pkg/services/datasources"
"github.com/grafana/grafana/pkg/services/featuremgmt"
"github.com/grafana/grafana/pkg/services/pluginsintegration/advisor"
"github.com/grafana/grafana/pkg/services/pluginsintegration/pluginstore"
"github.com/grafana/grafana/pkg/services/pluginsintegration/sandbox"
"github.com/grafana/grafana/pkg/services/stats"
@@ -353,6 +354,13 @@ func (m *mockSocial) GetOAuthProviders() map[string]bool {
return m.OAuthProviders
}
type mockAdvisor struct {
}
func (m *mockAdvisor) ReportSummary(ctx context.Context) (*advisor.ReportInfo, error) {
return &advisor.ReportInfo{}, nil
}
func setupSomeDataSourcePlugins(t *testing.T, s *Service) {
t.Helper()
@@ -387,6 +395,7 @@ func createService(t testing.TB, cfg *setting.Cfg, store db.DB, statsService sta
o.datasources,
httpclient.NewProvider(sdkhttpclient.ProviderOptions{Middlewares: []sdkhttpclient.Middleware{}}),
sandbox.ProvideService(cfg),
&mockAdvisor{},
)
}