Stats: Propagate context when listing sandbox plugins (#102207)
This commit is contained in:
@@ -150,7 +150,7 @@ func (s *Service) collectSystemStats(ctx context.Context) (map[string]any, error
|
||||
m["stats.plugins.apps.count"] = s.appCount(ctx)
|
||||
m["stats.plugins.panels.count"] = s.panelCount(ctx)
|
||||
m["stats.plugins.datasources.count"] = s.dataSourceCount(ctx)
|
||||
m["stats.plugins.sandboxed_plugins.count"] = s.sandboxCount()
|
||||
m["stats.plugins.sandboxed_plugins.count"] = s.sandboxCount(ctx)
|
||||
m["stats.alerts.count"] = statsResult.Alerts
|
||||
m["stats.active_users.count"] = statsResult.ActiveUsers
|
||||
m["stats.active_admins.count"] = statsResult.ActiveAdmins
|
||||
@@ -367,8 +367,8 @@ func (s *Service) dataSourceCount(ctx context.Context) int {
|
||||
return len(s.plugins.Plugins(ctx, plugins.TypeDataSource))
|
||||
}
|
||||
|
||||
func (s *Service) sandboxCount() int {
|
||||
ps, err := s.sandbox.Plugins()
|
||||
func (s *Service) sandboxCount(ctx context.Context) int {
|
||||
ps, err := s.sandbox.Plugins(ctx)
|
||||
if err != nil {
|
||||
s.log.Error("Failed to get sandboxed plugin count", "error", err)
|
||||
return 0
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
package sandbox
|
||||
|
||||
import "github.com/grafana/grafana/pkg/setting"
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
)
|
||||
|
||||
type Sandbox interface {
|
||||
Plugins() ([]string, error)
|
||||
Plugins(ctx context.Context) ([]string, error)
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
@@ -16,6 +20,6 @@ func ProvideService(cfg *setting.Cfg) *Service {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Service) Plugins() ([]string, error) {
|
||||
func (s *Service) Plugins(ctx context.Context) ([]string, error) {
|
||||
return s.cfg.EnableFrontendSandboxForPlugins, nil
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package sandbox
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
@@ -13,7 +14,7 @@ func TestService_Plugins(t *testing.T) {
|
||||
}
|
||||
service := ProvideService(cfg)
|
||||
|
||||
plugins, err := service.Plugins()
|
||||
plugins, err := service.Plugins(context.Background())
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, []string{"plugin1", "plugin2"}, plugins)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user