Add ConfigProvider and modify quota.Service to use it (#109395)
* Add config provider and integrate with wire setup * Refactor quota service to use config provider for configuration management * Enhance OSSConfigProvider to include logging and update ProvideService to return an error. Refactor server initialization to handle potential errors from config provider. Remove unnecessary wire binding for OSSConfigProvider. * Update CODEOWNERS to include the configprovider package under the grafana-backend-services-squad. * Refactor quota service initialization to include context in multiple service providers. Update tests and service implementations to ensure proper context handling during service creation.
This commit is contained in:
@@ -115,6 +115,7 @@
|
||||
/pkg/components/loki/ @grafana/grafana-backend-group
|
||||
/pkg/components/null/ @grafana/grafana-backend-group
|
||||
/pkg/components/simplejson/ @grafana/grafana-backend-group
|
||||
/pkg/configprovider/ @grafana/grafana-backend-services-squad
|
||||
/pkg/events/ @grafana/grafana-backend-group
|
||||
/pkg/extensions/ @grafana/grafana-backend-group
|
||||
/pkg/ifaces/ @grafana/grafana-backend-group
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/grafana/grafana/pkg/configprovider"
|
||||
"github.com/grafana/grafana/pkg/services/authn"
|
||||
"github.com/grafana/grafana/pkg/services/authn/authntest"
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -43,7 +44,9 @@ func setUpGetOrgUsersDB(t *testing.T, sqlStore db.DB, cfg *setting.Cfg) {
|
||||
cfg.AutoAssignOrg = true
|
||||
cfg.AutoAssignOrgId = int(testOrgID)
|
||||
|
||||
quotaService := quotaimpl.ProvideService(sqlStore, cfg)
|
||||
cfgProvider, err := configprovider.ProvideService(cfg)
|
||||
require.NoError(t, err)
|
||||
quotaService := quotaimpl.ProvideService(context.Background(), sqlStore, cfgProvider)
|
||||
orgService, err := orgimpl.ProvideService(sqlStore, cfg, quotaService)
|
||||
require.NoError(t, err)
|
||||
usrSvc, err := userimpl.ProvideService(
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
@@ -19,7 +20,7 @@ import (
|
||||
func runRunnerCommand(command func(commandLine utils.CommandLine, runner server.Runner) error) func(context *cli.Context) error {
|
||||
return func(context *cli.Context) error {
|
||||
cmd := &utils.ContextCommandLine{Context: context}
|
||||
runner, err := initializeRunner(cmd)
|
||||
runner, err := initializeRunner(context.Context, cmd)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%v: %w", "failed to initialize runner", err)
|
||||
}
|
||||
@@ -34,7 +35,7 @@ func runRunnerCommand(command func(commandLine utils.CommandLine, runner server.
|
||||
func runDbCommand(command func(commandLine utils.CommandLine, cfg *setting.Cfg, sqlStore db.DB) error) func(context *cli.Context) error {
|
||||
return func(context *cli.Context) error {
|
||||
cmd := &utils.ContextCommandLine{Context: context}
|
||||
runner, err := initializeRunner(cmd)
|
||||
runner, err := initializeRunner(context.Context, cmd)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%v: %w", "failed to initialize runner", err)
|
||||
}
|
||||
@@ -50,7 +51,7 @@ func runDbCommand(command func(commandLine utils.CommandLine, cfg *setting.Cfg,
|
||||
}
|
||||
}
|
||||
|
||||
func initializeRunner(cmd *utils.ContextCommandLine) (server.Runner, error) {
|
||||
func initializeRunner(ctx context.Context, cmd *utils.ContextCommandLine) (server.Runner, error) {
|
||||
configOptions := strings.Split(cmd.String("configOverrides"), " ")
|
||||
cfg, err := setting.NewCfgFromArgs(setting.CommandLineArgs{
|
||||
Config: cmd.ConfigFile(),
|
||||
@@ -62,7 +63,7 @@ func initializeRunner(cmd *utils.ContextCommandLine) (server.Runner, error) {
|
||||
return server.Runner{}, err
|
||||
}
|
||||
|
||||
runner, err := server.InitializeForCLI(cfg)
|
||||
runner, err := server.InitializeForCLI(ctx, cfg)
|
||||
if err != nil {
|
||||
return server.Runner{}, fmt.Errorf("%v: %w", "failed to initialize runner", err)
|
||||
}
|
||||
|
||||
@@ -106,12 +106,15 @@ func RunServer(opts standalone.BuildInfo, cli *cli.Context) error {
|
||||
|
||||
metrics.SetBuildInformation(metrics.ProvideRegisterer(), opts.Version, opts.Commit, opts.BuildBranch, getBuildstamp(opts))
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
// Initialize the OpenFeature feature flag system
|
||||
if err := featuremgmt.InitOpenFeatureWithCfg(cfg); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
s, err := server.Initialize(
|
||||
ctx,
|
||||
cfg,
|
||||
server.Options{
|
||||
PidFile: PidFile,
|
||||
@@ -125,7 +128,6 @@ func RunServer(opts standalone.BuildInfo, cli *cli.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
go listenToSystemSignals(ctx, s)
|
||||
return s.Run()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package configprovider
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
)
|
||||
|
||||
type ConfigProvider interface {
|
||||
Get(context.Context) *setting.Cfg
|
||||
}
|
||||
|
||||
type OSSConfigProvider struct {
|
||||
Cfg *setting.Cfg
|
||||
log log.Logger
|
||||
}
|
||||
|
||||
func (c *OSSConfigProvider) Get(_ context.Context) *setting.Cfg {
|
||||
c.log.Debug("OSSConfigProvider Get")
|
||||
return c.Cfg
|
||||
}
|
||||
|
||||
func ProvideService(cfg *setting.Cfg) (ConfigProvider, error) {
|
||||
return &OSSConfigProvider{Cfg: cfg, log: log.New("configprovider")}, nil
|
||||
}
|
||||
@@ -27,8 +27,8 @@ func NewService(cfg *setting.Cfg, opts Options, apiOpts api.ServerOptions) (*cor
|
||||
return s, nil
|
||||
}
|
||||
|
||||
func (s *coreService) start(_ context.Context) error {
|
||||
serv, err := Initialize(s.cfg, s.opts, s.apiOpts)
|
||||
func (s *coreService) start(ctx context.Context) error {
|
||||
serv, err := Initialize(ctx, s.cfg, s.opts, s.apiOpts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
+6
-4
@@ -7,6 +7,8 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/wire"
|
||||
"github.com/stretchr/testify/mock"
|
||||
"go.opentelemetry.io/otel"
|
||||
@@ -502,12 +504,12 @@ var wireTestSet = wire.NewSet(
|
||||
wire.Bind(new(cleanup.AlertRuleService), new(*ngstore.DBstore)),
|
||||
)
|
||||
|
||||
func Initialize(cfg *setting.Cfg, opts Options, apiOpts api.ServerOptions) (*Server, error) {
|
||||
func Initialize(ctx context.Context, cfg *setting.Cfg, opts Options, apiOpts api.ServerOptions) (*Server, error) {
|
||||
wire.Build(wireExtsSet)
|
||||
return &Server{}, nil
|
||||
}
|
||||
|
||||
func InitializeForTest(t sqlutil.ITestDB, testingT interface {
|
||||
func InitializeForTest(ctx context.Context, t sqlutil.ITestDB, testingT interface {
|
||||
mock.TestingT
|
||||
Cleanup(func())
|
||||
}, cfg *setting.Cfg, opts Options, apiOpts api.ServerOptions,
|
||||
@@ -516,14 +518,14 @@ func InitializeForTest(t sqlutil.ITestDB, testingT interface {
|
||||
return &TestEnv{Server: &Server{}, TestingT: testingT, SQLStore: &sqlstore.SQLStore{}, Cfg: &setting.Cfg{}}, nil
|
||||
}
|
||||
|
||||
func InitializeForCLI(cfg *setting.Cfg) (Runner, error) {
|
||||
func InitializeForCLI(ctx context.Context, cfg *setting.Cfg) (Runner, error) {
|
||||
wire.Build(wireExtsCLISet)
|
||||
return Runner{}, nil
|
||||
}
|
||||
|
||||
// InitializeForCLITarget is a simplified set of dependencies for the CLI, used
|
||||
// by the server target subcommand to launch specific dskit modules.
|
||||
func InitializeForCLITarget(cfg *setting.Cfg) (ModuleRunner, error) {
|
||||
func InitializeForCLITarget(ctx context.Context, cfg *setting.Cfg) (ModuleRunner, error) {
|
||||
wire.Build(wireExtsBaseCLISet)
|
||||
return ModuleRunner{}, nil
|
||||
}
|
||||
|
||||
+21
-7
@@ -6,6 +6,7 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/google/wire"
|
||||
httpclient2 "github.com/grafana/grafana-plugin-sdk-go/backend/httpclient"
|
||||
"github.com/grafana/grafana/apps/advisor/pkg/app/checkregistry"
|
||||
@@ -13,6 +14,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/api/avatar"
|
||||
"github.com/grafana/grafana/pkg/api/routing"
|
||||
"github.com/grafana/grafana/pkg/bus"
|
||||
"github.com/grafana/grafana/pkg/configprovider"
|
||||
"github.com/grafana/grafana/pkg/expr"
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
"github.com/grafana/grafana/pkg/infra/httpclient"
|
||||
@@ -281,7 +283,7 @@ import (
|
||||
|
||||
// Injectors from wire.go:
|
||||
|
||||
func Initialize(cfg *setting.Cfg, opts Options, apiOpts api.ServerOptions) (*Server, error) {
|
||||
func Initialize(ctx context.Context, cfg *setting.Cfg, opts Options, apiOpts api.ServerOptions) (*Server, error) {
|
||||
routeRegisterImpl := routing.ProvideRegister()
|
||||
tracingConfig, err := tracing.ProvideTracingConfig(cfg)
|
||||
if err != nil {
|
||||
@@ -388,7 +390,11 @@ func Initialize(cfg *setting.Cfg, opts Options, apiOpts api.ServerOptions) (*Ser
|
||||
mysqlService := mysql.ProvideService()
|
||||
mssqlService := mssql.ProvideService(cfg)
|
||||
entityEventsService := store.ProvideEntityEventsService(cfg, sqlStore, featureToggles)
|
||||
quotaService := quotaimpl.ProvideService(sqlStore, cfg)
|
||||
configProvider, err := configprovider.ProvideService(cfg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
quotaService := quotaimpl.ProvideService(ctx, sqlStore, configProvider)
|
||||
orgService, err := orgimpl.ProvideService(sqlStore, cfg, quotaService)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -851,7 +857,7 @@ func Initialize(cfg *setting.Cfg, opts Options, apiOpts api.ServerOptions) (*Ser
|
||||
return server, nil
|
||||
}
|
||||
|
||||
func InitializeForTest(t sqlutil.ITestDB, testingT interface {
|
||||
func InitializeForTest(ctx context.Context, t sqlutil.ITestDB, testingT interface {
|
||||
Cleanup(func())
|
||||
mock.TestingT
|
||||
}, cfg *setting.Cfg, opts Options, apiOpts api.ServerOptions) (*TestEnv, error) {
|
||||
@@ -961,7 +967,11 @@ func InitializeForTest(t sqlutil.ITestDB, testingT interface {
|
||||
mysqlService := mysql.ProvideService()
|
||||
mssqlService := mssql.ProvideService(cfg)
|
||||
entityEventsService := store.ProvideEntityEventsService(cfg, sqlStore, featureToggles)
|
||||
quotaService := quotaimpl.ProvideService(sqlStore, cfg)
|
||||
configProvider, err := configprovider.ProvideService(cfg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
quotaService := quotaimpl.ProvideService(ctx, sqlStore, configProvider)
|
||||
orgService, err := orgimpl.ProvideService(sqlStore, cfg, quotaService)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -1430,7 +1440,7 @@ func InitializeForTest(t sqlutil.ITestDB, testingT interface {
|
||||
return testEnv, nil
|
||||
}
|
||||
|
||||
func InitializeForCLI(cfg *setting.Cfg) (Runner, error) {
|
||||
func InitializeForCLI(ctx context.Context, cfg *setting.Cfg) (Runner, error) {
|
||||
featureManager, err := featuremgmt.ProvideManagerService(cfg)
|
||||
if err != nil {
|
||||
return Runner{}, err
|
||||
@@ -1471,7 +1481,11 @@ func InitializeForCLI(cfg *setting.Cfg) (Runner, error) {
|
||||
return Runner{}, err
|
||||
}
|
||||
secretsMigrator := migrator.ProvideSecretsMigrator(serviceService, secretsService, sqlStore, ossImpl, featureToggles)
|
||||
quotaService := quotaimpl.ProvideService(sqlStore, cfg)
|
||||
configProvider, err := configprovider.ProvideService(cfg)
|
||||
if err != nil {
|
||||
return Runner{}, err
|
||||
}
|
||||
quotaService := quotaimpl.ProvideService(ctx, sqlStore, configProvider)
|
||||
orgService, err := orgimpl.ProvideService(sqlStore, cfg, quotaService)
|
||||
if err != nil {
|
||||
return Runner{}, err
|
||||
@@ -1523,7 +1537,7 @@ func InitializeForCLI(cfg *setting.Cfg) (Runner, error) {
|
||||
|
||||
// InitializeForCLITarget is a simplified set of dependencies for the CLI, used
|
||||
// by the server target subcommand to launch specific dskit modules.
|
||||
func InitializeForCLITarget(cfg *setting.Cfg) (ModuleRunner, error) {
|
||||
func InitializeForCLITarget(ctx context.Context, cfg *setting.Cfg) (ModuleRunner, error) {
|
||||
ossImpl := setting.ProvideProvider(cfg)
|
||||
featureManager, err := featuremgmt.ProvideManagerService(cfg)
|
||||
if err != nil {
|
||||
|
||||
@@ -7,6 +7,7 @@ package server
|
||||
import (
|
||||
"github.com/google/wire"
|
||||
|
||||
"github.com/grafana/grafana/pkg/configprovider"
|
||||
"github.com/grafana/grafana/pkg/infra/metrics"
|
||||
"github.com/grafana/grafana/pkg/infra/tracing"
|
||||
"github.com/grafana/grafana/pkg/plugins"
|
||||
@@ -71,6 +72,10 @@ var provisioningExtras = wire.NewSet(
|
||||
extras.ProvideProvisioningOSSExtras,
|
||||
)
|
||||
|
||||
var configProviderExtras = wire.NewSet(
|
||||
configprovider.ProvideService,
|
||||
)
|
||||
|
||||
var wireExtsBasicSet = wire.NewSet(
|
||||
authimpl.ProvideUserAuthTokenService,
|
||||
wire.Bind(new(auth.UserTokenService), new(*authimpl.UserAuthTokenService)),
|
||||
@@ -144,6 +149,7 @@ var wireExtsBasicSet = wire.NewSet(
|
||||
gsmKMSProviders.ProvideOSSKMSProviders,
|
||||
secret.ProvideSecureValueClient,
|
||||
provisioningExtras,
|
||||
configProviderExtras,
|
||||
)
|
||||
|
||||
var wireExtsSet = wire.NewSet(
|
||||
@@ -173,6 +179,7 @@ var wireExtsBaseCLISet = wire.NewSet(
|
||||
hooks.ProvideService,
|
||||
setting.ProvideProvider, wire.Bind(new(setting.Provider), new(*setting.OSSImpl)),
|
||||
licensing.ProvideService, wire.Bind(new(licensing.Licensing), new(*licensing.OSSLicensingService)),
|
||||
configProviderExtras,
|
||||
)
|
||||
|
||||
// wireModuleServerSet is a wire set for the ModuleServer.
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/grafana/grafana-openapi-client-go/models"
|
||||
"github.com/grafana/grafana/pkg/configprovider"
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
"github.com/grafana/grafana/pkg/infra/tracing"
|
||||
"github.com/grafana/grafana/pkg/services/libraryelements/model"
|
||||
@@ -32,7 +33,9 @@ func TestIntegrationLibraryElementPermissions(t *testing.T) {
|
||||
dir, path := testinfra.CreateGrafDir(t, testinfra.GrafanaOpts{})
|
||||
|
||||
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
|
||||
quotaService := quotaimpl.ProvideService(env.SQLStore, env.Cfg)
|
||||
cfgProvider, err := configprovider.ProvideService(env.Cfg)
|
||||
require.NoError(t, err)
|
||||
quotaService := quotaimpl.ProvideService(context.Background(), env.SQLStore, cfgProvider)
|
||||
orgService, err := orgimpl.ProvideService(env.SQLStore, env.Cfg, quotaService)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -138,7 +141,9 @@ func TestIntegrationLibraryElementGranularPermissions(t *testing.T) {
|
||||
}
|
||||
dir, path := testinfra.CreateGrafDir(t, testinfra.GrafanaOpts{})
|
||||
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
|
||||
quotaService := quotaimpl.ProvideService(env.SQLStore, env.Cfg)
|
||||
cfgProvider, err := configprovider.ProvideService(env.Cfg)
|
||||
require.NoError(t, err)
|
||||
quotaService := quotaimpl.ProvideService(context.Background(), env.SQLStore, cfgProvider)
|
||||
orgService, err := orgimpl.ProvideService(env.SQLStore, env.Cfg, quotaService)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -357,7 +362,9 @@ func createUserInOrg(t *testing.T, db db.DB, cfg *setting.Cfg, cmd user.CreateUs
|
||||
cfg.AutoAssignOrg = true
|
||||
cfg.AutoAssignOrgId = 1
|
||||
|
||||
quotaService := quotaimpl.ProvideService(db, cfg)
|
||||
cfgProvider, err := configprovider.ProvideService(cfg)
|
||||
require.NoError(t, err)
|
||||
quotaService := quotaimpl.ProvideService(context.Background(), db, cfgProvider)
|
||||
orgService, err := orgimpl.ProvideService(db, cfg, quotaService)
|
||||
require.NoError(t, err)
|
||||
usrSvc, err := userimpl.ProvideService(
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/grafana/grafana/pkg/apimachinery/identity"
|
||||
"github.com/grafana/grafana/pkg/configprovider"
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/infra/tracing"
|
||||
@@ -108,7 +109,8 @@ func TestIntegrationOrgDataAccess(t *testing.T) {
|
||||
City: "city",
|
||||
ZipCode: "zip",
|
||||
State: "state",
|
||||
Country: "country"},
|
||||
Country: "country",
|
||||
},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
orga, err := orgStore.Get(context.Background(), ac2.ID)
|
||||
@@ -1039,7 +1041,9 @@ func TestIntegration_SQLStore_RemoveOrgUser(t *testing.T) {
|
||||
func createOrgAndUserSvc(t *testing.T, store db.DB, cfg *setting.Cfg) (org.Service, user.Service) {
|
||||
t.Helper()
|
||||
|
||||
quotaService := quotaimpl.ProvideService(store, cfg)
|
||||
cfgProvider, err := configprovider.ProvideService(cfg)
|
||||
require.NoError(t, err)
|
||||
quotaService := quotaimpl.ProvideService(context.Background(), store, cfgProvider)
|
||||
orgService, err := ProvideService(store, cfg, quotaService)
|
||||
require.NoError(t, err)
|
||||
usrSvc, err := userimpl.ProvideService(
|
||||
|
||||
@@ -7,11 +7,11 @@ import (
|
||||
"go.opentelemetry.io/otel"
|
||||
"golang.org/x/sync/errgroup"
|
||||
|
||||
"github.com/grafana/grafana/pkg/configprovider"
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/quota"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
)
|
||||
|
||||
// tracer is the global tracer for the quota service. Tracer pulls the globally
|
||||
@@ -46,8 +46,8 @@ func (s *serviceDisabled) RegisterQuotaReporter(e *quota.NewUsageReporter) error
|
||||
|
||||
type service struct {
|
||||
store store
|
||||
Cfg *setting.Cfg
|
||||
Logger log.Logger
|
||||
cfg configprovider.ConfigProvider
|
||||
logger log.Logger
|
||||
|
||||
mutex sync.RWMutex
|
||||
reporters map[quota.TargetSrv]quota.UsageReporterFunc
|
||||
@@ -57,26 +57,26 @@ type service struct {
|
||||
targetToSrv *quota.TargetToSrv
|
||||
}
|
||||
|
||||
func ProvideService(db db.DB, cfg *setting.Cfg) quota.Service {
|
||||
func ProvideService(ctx context.Context, db db.DB, configProvider configprovider.ConfigProvider) quota.Service {
|
||||
logger := log.New("quota_service")
|
||||
s := service{
|
||||
store: &sqlStore{db: db, logger: logger},
|
||||
Cfg: cfg,
|
||||
Logger: logger,
|
||||
cfg: configProvider,
|
||||
logger: logger,
|
||||
reporters: make(map[quota.TargetSrv]quota.UsageReporterFunc),
|
||||
defaultLimits: "a.Map{},
|
||||
targetToSrv: quota.NewTargetToSrv(),
|
||||
}
|
||||
|
||||
if s.IsDisabled() {
|
||||
if s.IsDisabled(ctx) {
|
||||
return &serviceDisabled{}
|
||||
}
|
||||
|
||||
return &s
|
||||
}
|
||||
|
||||
func (s *service) IsDisabled() bool {
|
||||
return !s.Cfg.Quota.Enabled
|
||||
func (s *service) IsDisabled(ctx context.Context) bool {
|
||||
return !s.cfg.Get(ctx).Quota.Enabled
|
||||
}
|
||||
|
||||
// QuotaReached checks that quota is reached for a target. Runs CheckQuotaReached and take context and scope parameters from the request context
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/routing"
|
||||
"github.com/grafana/grafana/pkg/bus"
|
||||
"github.com/grafana/grafana/pkg/configprovider"
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
"github.com/grafana/grafana/pkg/infra/httpclient"
|
||||
"github.com/grafana/grafana/pkg/infra/kvstore"
|
||||
@@ -105,7 +106,9 @@ func TestIntegrationQuotaCommandsAndQueries(t *testing.T) {
|
||||
}
|
||||
|
||||
b := bus.ProvideBus(tracing.InitializeTracerForTest())
|
||||
quotaService := ProvideService(sqlStore, cfg)
|
||||
cfgProvider, err := configprovider.ProvideService(cfg)
|
||||
require.NoError(t, err)
|
||||
quotaService := ProvideService(context.Background(), sqlStore, cfgProvider)
|
||||
orgService, err := orgimpl.ProvideService(sqlStore, cfg, quotaService)
|
||||
require.NoError(t, err)
|
||||
userService, err := userimpl.ProvideService(
|
||||
@@ -247,7 +250,9 @@ func TestIntegrationQuotaCommandsAndQueries(t *testing.T) {
|
||||
}()
|
||||
cfg.UnifiedAlerting = setting.UnifiedAlertingSettings{Enabled: util.Pointer(false)}
|
||||
|
||||
quotaSrv := ProvideService(sqlStore, cfg)
|
||||
cfgProvider, err := configprovider.ProvideService(cfg)
|
||||
require.NoError(t, err)
|
||||
quotaSrv := ProvideService(context.Background(), sqlStore, cfgProvider)
|
||||
q, err := getQuotaBySrvTargetScope(t, quotaSrv, ngalertmodels.QuotaTargetSrv, ngalertmodels.QuotaTarget, quota.OrgScope, "a.ScopeParameters{OrgID: o.ID})
|
||||
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/grafana/grafana/pkg/configprovider"
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
"github.com/grafana/grafana/pkg/infra/tracing"
|
||||
"github.com/grafana/grafana/pkg/services/apikey"
|
||||
@@ -43,7 +44,9 @@ func SetupUserServiceAccount(t *testing.T, db db.DB, cfg *setting.Cfg, testUser
|
||||
role = testUser.Role
|
||||
}
|
||||
|
||||
quotaService := quotaimpl.ProvideService(db, cfg)
|
||||
cfgProvider, err := configprovider.ProvideService(cfg)
|
||||
require.NoError(t, err)
|
||||
quotaService := quotaimpl.ProvideService(context.Background(), db, cfgProvider)
|
||||
orgService, err := orgimpl.ProvideService(db, cfg, quotaService)
|
||||
require.NoError(t, err)
|
||||
usrSvc, err := userimpl.ProvideService(
|
||||
@@ -122,7 +125,9 @@ func SetupApiKeys(t *testing.T, store db.DB, cfg *setting.Cfg, testKeys []TestAp
|
||||
func SetupUsersServiceAccounts(t *testing.T, sqlStore db.DB, cfg *setting.Cfg, testUsers []TestUser) (users []user.User, orgID int64) {
|
||||
role := string(org.RoleNone)
|
||||
|
||||
quotaService := quotaimpl.ProvideService(sqlStore, cfg)
|
||||
cfgProvider, err := configprovider.ProvideService(cfg)
|
||||
require.NoError(t, err)
|
||||
quotaService := quotaimpl.ProvideService(context.Background(), sqlStore, cfgProvider)
|
||||
orgService, err := orgimpl.ProvideService(sqlStore, cfg, quotaService)
|
||||
require.NoError(t, err)
|
||||
usrSvc, err := userimpl.ProvideService(
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/grafana/grafana/pkg/apimachinery/identity"
|
||||
"github.com/grafana/grafana/pkg/configprovider"
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
"github.com/grafana/grafana/pkg/infra/tracing"
|
||||
ac "github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
@@ -47,7 +48,9 @@ func TestIntegrationTeamCommandsAndQueries(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
quotaService := quotaimpl.ProvideService(sqlStore, cfg)
|
||||
cfgProvider, err := configprovider.ProvideService(cfg)
|
||||
require.NoError(t, err)
|
||||
quotaService := quotaimpl.ProvideService(context.Background(), sqlStore, cfgProvider)
|
||||
orgSvc, err := orgimpl.ProvideService(sqlStore, cfg, quotaService)
|
||||
require.NoError(t, err)
|
||||
userSvc, err := userimpl.ProvideService(
|
||||
@@ -453,7 +456,9 @@ func TestIntegrationTeamCommandsAndQueries(t *testing.T) {
|
||||
|
||||
t.Run("Should be able to exclude service accounts from teamembers", func(t *testing.T) {
|
||||
sqlStore = db.InitTestDB(t)
|
||||
quotaService := quotaimpl.ProvideService(sqlStore, cfg)
|
||||
cfgProvider, err := configprovider.ProvideService(cfg)
|
||||
require.NoError(t, err)
|
||||
quotaService := quotaimpl.ProvideService(context.Background(), sqlStore, cfgProvider)
|
||||
orgSvc, err := orgimpl.ProvideService(sqlStore, cfg, quotaService)
|
||||
require.NoError(t, err)
|
||||
userSvc, err := userimpl.ProvideService(
|
||||
@@ -609,7 +614,9 @@ func TestIntegrationSQLStore_GetTeamMembers_ACFilter(t *testing.T) {
|
||||
team2, errCreateTeam := teamSvc.CreateTeam(context.Background(), &team2Cmd)
|
||||
require.NoError(t, errCreateTeam)
|
||||
|
||||
quotaService := quotaimpl.ProvideService(store, cfg)
|
||||
cfgProvider, err := configprovider.ProvideService(cfg)
|
||||
require.NoError(t, err)
|
||||
quotaService := quotaimpl.ProvideService(context.Background(), store, cfgProvider)
|
||||
orgSvc, err := orgimpl.ProvideService(store, cfg, quotaService)
|
||||
require.NoError(t, err)
|
||||
userSvc, err := userimpl.ProvideService(
|
||||
@@ -682,7 +689,6 @@ func TestIntegrationSQLStore_GetTeamMembers_ACFilter(t *testing.T) {
|
||||
expectedNumUsers: 0,
|
||||
},
|
||||
{
|
||||
|
||||
desc: "should return some team members",
|
||||
query: &team.GetTeamMembersQuery{
|
||||
OrgID: testOrgID,
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/grafana/grafana/pkg/configprovider"
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
"github.com/grafana/grafana/pkg/infra/tracing"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
@@ -37,7 +38,9 @@ func TestIntegrationUserDataAccess(t *testing.T) {
|
||||
}
|
||||
|
||||
ss, cfg := db.InitTestDBWithCfg(t)
|
||||
quotaService := quotaimpl.ProvideService(ss, cfg)
|
||||
cfgProvider, err := configprovider.ProvideService(cfg)
|
||||
require.NoError(t, err)
|
||||
quotaService := quotaimpl.ProvideService(context.Background(), ss, cfgProvider)
|
||||
orgService, err := orgimpl.ProvideService(ss, cfg, quotaService)
|
||||
require.NoError(t, err)
|
||||
userStore := ProvideStore(ss, setting.NewCfg())
|
||||
@@ -396,7 +399,8 @@ func TestIntegrationUserDataAccess(t *testing.T) {
|
||||
_, err = userStore.GetSignedInUser(context.Background(),
|
||||
&user.GetSignedInUserQuery{
|
||||
OrgID: users[1].OrgID,
|
||||
UserID: userID}) // zero
|
||||
UserID: userID,
|
||||
}) // zero
|
||||
require.Error(t, err)
|
||||
}
|
||||
})
|
||||
@@ -1068,7 +1072,9 @@ func TestIntegrationMetricsUsage(t *testing.T) {
|
||||
}
|
||||
ss, cfg := db.InitTestDBWithCfg(t)
|
||||
userStore := ProvideStore(ss, setting.NewCfg())
|
||||
quotaService := quotaimpl.ProvideService(ss, cfg)
|
||||
cfgProvider, err := configprovider.ProvideService(cfg)
|
||||
require.NoError(t, err)
|
||||
quotaService := quotaimpl.ProvideService(context.Background(), ss, cfgProvider)
|
||||
orgService, err := orgimpl.ProvideService(ss, cfg, quotaService)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -1127,7 +1133,9 @@ func assertEqualUser(t *testing.T, expected, got *user.User) {
|
||||
func createOrgAndUserSvc(t *testing.T, store db.DB, cfg *setting.Cfg) (org.Service, user.Service) {
|
||||
t.Helper()
|
||||
|
||||
quotaService := quotaimpl.ProvideService(store, cfg)
|
||||
cfgProvider, err := configprovider.ProvideService(cfg)
|
||||
require.NoError(t, err)
|
||||
quotaService := quotaimpl.ProvideService(context.Background(), store, cfgProvider)
|
||||
orgService, err := orgimpl.ProvideService(store, cfg, quotaService)
|
||||
require.NoError(t, err)
|
||||
usrSvc, err := ProvideService(
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package alerting
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
@@ -10,8 +11,7 @@ import (
|
||||
"github.com/prometheus/common/model"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"bytes"
|
||||
|
||||
"github.com/grafana/grafana/pkg/configprovider"
|
||||
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
"github.com/grafana/grafana/pkg/services/org"
|
||||
"github.com/grafana/grafana/pkg/services/org/orgimpl"
|
||||
@@ -180,7 +180,9 @@ func TestIntegration_NamespacingForRules(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("org separation", func(t *testing.T) {
|
||||
orgService, err := orgimpl.ProvideService(store, cfg, quotaimpl.ProvideService(store, cfg))
|
||||
cfgProvider, err := configprovider.ProvideService(cfg)
|
||||
require.NoError(t, err)
|
||||
orgService, err := orgimpl.ProvideService(store, cfg, quotaimpl.ProvideService(context.Background(), store, cfgProvider))
|
||||
require.NoError(t, err)
|
||||
newOrg, err := orgService.CreateWithMember(context.Background(), &org.CreateOrgCommand{Name: "Test Org 2"})
|
||||
require.NoError(t, err)
|
||||
@@ -386,7 +388,9 @@ func TestIntegration_NamespacingForPrometheusRules(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("should maintain org separation for Prometheus rules", func(t *testing.T) {
|
||||
orgService, err := orgimpl.ProvideService(store, cfg, quotaimpl.ProvideService(store, cfg))
|
||||
cfgProvider, err := configprovider.ProvideService(cfg)
|
||||
require.NoError(t, err)
|
||||
orgService, err := orgimpl.ProvideService(store, cfg, quotaimpl.ProvideService(context.Background(), store, cfgProvider))
|
||||
require.NoError(t, err)
|
||||
newOrg, err := orgService.CreateWithMember(context.Background(), &org.CreateOrgCommand{Name: "Prometheus Test Org 2"})
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -20,6 +20,7 @@ import (
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"github.com/grafana/grafana/pkg/api"
|
||||
"github.com/grafana/grafana/pkg/configprovider"
|
||||
"github.com/grafana/grafana/pkg/expr"
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
"github.com/grafana/grafana/pkg/infra/tracing"
|
||||
@@ -1460,7 +1461,9 @@ func createUser(t *testing.T, db db.DB, cfg *setting.Cfg, cmd user.CreateUserCom
|
||||
cfg.AutoAssignOrg = true
|
||||
cfg.AutoAssignOrgId = 1
|
||||
|
||||
quotaService := quotaimpl.ProvideService(db, cfg)
|
||||
cfgProvider, err := configprovider.ProvideService(cfg)
|
||||
require.NoError(t, err)
|
||||
quotaService := quotaimpl.ProvideService(context.Background(), db, cfgProvider)
|
||||
orgService, err := orgimpl.ProvideService(db, cfg, quotaService)
|
||||
require.NoError(t, err)
|
||||
usrSvc, err := userimpl.ProvideService(
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/grafana/grafana/pkg/configprovider"
|
||||
"github.com/grafana/grafana/pkg/infra/tracing"
|
||||
"github.com/grafana/grafana/pkg/server"
|
||||
"github.com/grafana/grafana/pkg/services/correlations"
|
||||
@@ -144,7 +145,9 @@ func (c TestContext) createOrg(name string) int64 {
|
||||
c.t.Helper()
|
||||
store := c.env.SQLStore
|
||||
c.env.Cfg.AutoAssignOrg = false
|
||||
quotaService := quotaimpl.ProvideService(store, c.env.Cfg)
|
||||
cfgProvider, err := configprovider.ProvideService(c.env.Cfg)
|
||||
require.NoError(c.t, err)
|
||||
quotaService := quotaimpl.ProvideService(context.Background(), store, cfgProvider)
|
||||
orgService, err := orgimpl.ProvideService(store, c.env.Cfg, quotaService)
|
||||
require.NoError(c.t, err)
|
||||
orgId, err := orgService.GetOrCreate(context.Background(), name)
|
||||
@@ -158,7 +161,9 @@ func (c TestContext) createUser(cmd user.CreateUserCommand) User {
|
||||
c.env.Cfg.AutoAssignOrg = true
|
||||
c.env.Cfg.AutoAssignOrgId = 1
|
||||
|
||||
quotaService := quotaimpl.ProvideService(store, c.env.Cfg)
|
||||
cfgProvider, err := configprovider.ProvideService(c.env.Cfg)
|
||||
require.NoError(c.t, err)
|
||||
quotaService := quotaimpl.ProvideService(context.Background(), store, cfgProvider)
|
||||
orgService, err := orgimpl.ProvideService(store, c.env.Cfg, quotaService)
|
||||
require.NoError(c.t, err)
|
||||
usrSvc, err := userimpl.ProvideService(
|
||||
|
||||
@@ -17,6 +17,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/dtos"
|
||||
"github.com/grafana/grafana/pkg/configprovider"
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
"github.com/grafana/grafana/pkg/infra/tracing"
|
||||
"github.com/grafana/grafana/pkg/plugins"
|
||||
@@ -199,7 +200,9 @@ func createUser(t *testing.T, db db.DB, cfg *setting.Cfg, cmd user.CreateUserCom
|
||||
cfg.AutoAssignOrg = true
|
||||
cfg.AutoAssignOrgId = 1
|
||||
|
||||
quotaService := quotaimpl.ProvideService(db, cfg)
|
||||
cfgProvider, err := configprovider.ProvideService(cfg)
|
||||
require.NoError(t, err)
|
||||
quotaService := quotaimpl.ProvideService(context.Background(), db, cfgProvider)
|
||||
orgService, err := orgimpl.ProvideService(db, cfg, quotaService)
|
||||
require.NoError(t, err)
|
||||
usrSvc, err := userimpl.ProvideService(
|
||||
@@ -224,7 +227,7 @@ func makePostRequest(t *testing.T, URL string) (int, map[string]interface{}) {
|
||||
b, err := io.ReadAll(resp.Body)
|
||||
require.NoError(t, err)
|
||||
|
||||
var body = make(map[string]interface{})
|
||||
body := make(map[string]interface{})
|
||||
err = json.Unmarshal(b, &body)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -251,7 +254,7 @@ func expectedResp(t *testing.T, filename string) dtos.PluginList {
|
||||
}
|
||||
|
||||
func updateRespSnapshot(t *testing.T, filename string, body string) {
|
||||
err := os.WriteFile(filepath.Join("data", filename), []byte(body), 0600)
|
||||
err := os.WriteFile(filepath.Join("data", filename), []byte(body), 0o600)
|
||||
if err != nil {
|
||||
t.Errorf("error writing snapshot %s: %v", filename, err)
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/grafana/grafana/pkg/configprovider"
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
"github.com/grafana/grafana/pkg/infra/tracing"
|
||||
"github.com/grafana/grafana/pkg/services/org"
|
||||
@@ -110,7 +111,9 @@ func createUser(t *testing.T, db db.DB, cfg *setting.Cfg, cmd user.CreateUserCom
|
||||
cfg.AutoAssignOrg = true
|
||||
cfg.AutoAssignOrgId = 1
|
||||
|
||||
quotaService := quotaimpl.ProvideService(db, cfg)
|
||||
cfgProvider, err := configprovider.ProvideService(cfg)
|
||||
require.NoError(t, err)
|
||||
quotaService := quotaimpl.ProvideService(context.Background(), db, cfgProvider)
|
||||
orgService, err := orgimpl.ProvideService(db, cfg, quotaService)
|
||||
require.NoError(t, err)
|
||||
usrSvc, err := userimpl.ProvideService(
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/grafana/grafana/pkg/configprovider"
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
"github.com/grafana/grafana/pkg/infra/tracing"
|
||||
"github.com/grafana/grafana/pkg/services/org"
|
||||
@@ -90,7 +91,9 @@ func createUser(t *testing.T, db db.DB, cfg *setting.Cfg, cmd user.CreateUserCom
|
||||
cfg.AutoAssignOrg = true
|
||||
cfg.AutoAssignOrgId = 1
|
||||
|
||||
quotaService := quotaimpl.ProvideService(db, cfg)
|
||||
cfgProvider, err := configprovider.ProvideService(cfg)
|
||||
require.NoError(t, err)
|
||||
quotaService := quotaimpl.ProvideService(context.Background(), db, cfgProvider)
|
||||
orgService, err := orgimpl.ProvideService(db, cfg, quotaService)
|
||||
require.NoError(t, err)
|
||||
usrSvc, err := userimpl.ProvideService(
|
||||
|
||||
@@ -29,6 +29,7 @@ import (
|
||||
|
||||
"github.com/grafana/grafana/pkg/apimachinery/identity"
|
||||
"github.com/grafana/grafana/pkg/apimachinery/utils"
|
||||
"github.com/grafana/grafana/pkg/configprovider"
|
||||
"github.com/grafana/grafana/pkg/infra/localcache"
|
||||
"github.com/grafana/grafana/pkg/infra/tracing"
|
||||
"github.com/grafana/grafana/pkg/server"
|
||||
@@ -95,7 +96,9 @@ func NewK8sTestHelper(t *testing.T, opts testinfra.GrafanaOpts) *K8sTestHelper {
|
||||
Namespacer: request.GetNamespaceMapper(nil),
|
||||
}
|
||||
|
||||
quotaService := quotaimpl.ProvideService(c.env.SQLStore, c.env.Cfg)
|
||||
cfgProvider, err := configprovider.ProvideService(c.env.Cfg)
|
||||
require.NoError(c.t, err)
|
||||
quotaService := quotaimpl.ProvideService(context.Background(), c.env.SQLStore, cfgProvider)
|
||||
orgSvc, err := orgimpl.ProvideService(c.env.SQLStore, c.env.Cfg, quotaService)
|
||||
require.NoError(c.t, err)
|
||||
c.orgSvc = orgSvc
|
||||
@@ -375,8 +378,10 @@ type K8sResponse[T any] struct {
|
||||
Status *metav1.Status
|
||||
}
|
||||
|
||||
type AnyResourceResponse = K8sResponse[AnyResource]
|
||||
type AnyResourceListResponse = K8sResponse[AnyResourceList]
|
||||
type (
|
||||
AnyResourceResponse = K8sResponse[AnyResource]
|
||||
AnyResourceListResponse = K8sResponse[AnyResourceList]
|
||||
)
|
||||
|
||||
func (c *K8sTestHelper) PostResource(user User, resource string, payload AnyResource) AnyResourceResponse {
|
||||
c.t.Helper()
|
||||
@@ -799,7 +804,7 @@ func VerifyOpenAPISnapshots(t *testing.T, dir string, gv schema.GroupVersion, h
|
||||
}
|
||||
|
||||
if write {
|
||||
e2 := os.WriteFile(fpath, []byte(pretty), 0644)
|
||||
e2 := os.WriteFile(fpath, []byte(pretty), 0o644)
|
||||
if e2 != nil {
|
||||
t.Errorf("error writing file: %s", e2.Error())
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/grafana/grafana/pkg/configprovider"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore/sqlutil"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
@@ -102,7 +103,7 @@ func StartGrafanaEnv(t *testing.T, grafDir, cfgPath string) (string, *server.Tes
|
||||
|
||||
t.Log("Using test database", "type", testDB.DriverName, "host", testDB.Host, "port", testDB.Port, "user", testDB.User, "name", testDB.Database)
|
||||
|
||||
env, err := server.InitializeForTest(t, t, cfg, serverOpts, apiServerOpts)
|
||||
env, err := server.InitializeForTest(ctx, t, t, cfg, serverOpts, apiServerOpts)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.NotNil(t, env.Cfg)
|
||||
@@ -207,16 +208,16 @@ func CreateGrafDir(t *testing.T, opts GrafanaOpts) (string, string) {
|
||||
require.True(t, found, "Couldn't detect project root directory")
|
||||
|
||||
cfgDir := filepath.Join(tmpDir, "conf")
|
||||
err := os.MkdirAll(cfgDir, 0750)
|
||||
err := os.MkdirAll(cfgDir, 0o750)
|
||||
require.NoError(t, err)
|
||||
dataDir := filepath.Join(tmpDir, "data")
|
||||
// nolint:gosec
|
||||
err = os.MkdirAll(dataDir, 0750)
|
||||
err = os.MkdirAll(dataDir, 0o750)
|
||||
require.NoError(t, err)
|
||||
logsDir := filepath.Join(tmpDir, "logs")
|
||||
pluginsDir := filepath.Join(tmpDir, "plugins")
|
||||
publicDir := filepath.Join(tmpDir, "public")
|
||||
err = os.MkdirAll(publicDir, 0750)
|
||||
err = os.MkdirAll(publicDir, 0o750)
|
||||
require.NoError(t, err)
|
||||
|
||||
viewsDir := filepath.Join(publicDir, "views")
|
||||
@@ -225,7 +226,7 @@ func CreateGrafDir(t *testing.T, opts GrafanaOpts) (string, string) {
|
||||
|
||||
// add a stub manifest to the build directory
|
||||
buildDir := filepath.Join(publicDir, "build")
|
||||
err = os.MkdirAll(buildDir, 0750)
|
||||
err = os.MkdirAll(buildDir, 0o750)
|
||||
require.NoError(t, err)
|
||||
err = os.WriteFile(filepath.Join(buildDir, "assets-manifest.json"), []byte(`{
|
||||
"entrypoints": {
|
||||
@@ -255,7 +256,7 @@ func CreateGrafDir(t *testing.T, opts GrafanaOpts) (string, string) {
|
||||
"integrity": "sha256-k1g7TksMHFQhhQGE"
|
||||
}
|
||||
}
|
||||
`), 0750)
|
||||
`), 0o750)
|
||||
require.NoError(t, err)
|
||||
|
||||
emailsDir := filepath.Join(publicDir, "emails")
|
||||
@@ -263,16 +264,16 @@ func CreateGrafDir(t *testing.T, opts GrafanaOpts) (string, string) {
|
||||
require.NoError(t, err)
|
||||
provDir := filepath.Join(cfgDir, "provisioning")
|
||||
provDSDir := filepath.Join(provDir, "datasources")
|
||||
err = os.MkdirAll(provDSDir, 0750)
|
||||
err = os.MkdirAll(provDSDir, 0o750)
|
||||
require.NoError(t, err)
|
||||
provNotifiersDir := filepath.Join(provDir, "notifiers")
|
||||
err = os.MkdirAll(provNotifiersDir, 0750)
|
||||
err = os.MkdirAll(provNotifiersDir, 0o750)
|
||||
require.NoError(t, err)
|
||||
provPluginsDir := filepath.Join(provDir, "plugins")
|
||||
err = os.MkdirAll(provPluginsDir, 0750)
|
||||
err = os.MkdirAll(provPluginsDir, 0o750)
|
||||
require.NoError(t, err)
|
||||
provDashboardsDir := filepath.Join(provDir, "dashboards")
|
||||
err = os.MkdirAll(provDashboardsDir, 0750)
|
||||
err = os.MkdirAll(provDashboardsDir, 0o750)
|
||||
require.NoError(t, err)
|
||||
corePluginsDir := filepath.Join(publicDir, "app/plugins")
|
||||
err = fs.CopyRecursive(filepath.Join(rootDir, "public", "app/plugins"), corePluginsDir)
|
||||
@@ -621,7 +622,9 @@ func CreateUser(t *testing.T, store db.DB, cfg *setting.Cfg, cmd user.CreateUser
|
||||
cfg.AutoAssignOrgId = 1
|
||||
cmd.OrgID = 1
|
||||
|
||||
quotaService := quotaimpl.ProvideService(store, cfg)
|
||||
cfgProvider, err := configprovider.ProvideService(cfg)
|
||||
require.NoError(t, err)
|
||||
quotaService := quotaimpl.ProvideService(context.Background(), store, cfgProvider)
|
||||
orgService, err := orgimpl.ProvideService(store, cfg, quotaService)
|
||||
require.NoError(t, err)
|
||||
usrSvc, err := userimpl.ProvideService(
|
||||
|
||||
+4
-1
@@ -12,6 +12,7 @@ import (
|
||||
goapi "github.com/grafana/grafana-openapi-client-go/client"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/grafana/grafana/pkg/configprovider"
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
"github.com/grafana/grafana/pkg/infra/tracing"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol/resourcepermissions"
|
||||
@@ -40,7 +41,9 @@ func CreateUser(t *testing.T, db db.DB, cfg *setting.Cfg, cmd user.CreateUserCom
|
||||
cfg.AutoAssignOrg = true
|
||||
cfg.AutoAssignOrgId = 1
|
||||
|
||||
quotaService := quotaimpl.ProvideService(db, cfg)
|
||||
cfgProvider, err := configprovider.ProvideService(cfg)
|
||||
require.NoError(t, err)
|
||||
quotaService := quotaimpl.ProvideService(context.Background(), db, cfgProvider)
|
||||
orgService, err := orgimpl.ProvideService(db, cfg, quotaService)
|
||||
require.NoError(t, err)
|
||||
usrSvc, err := userimpl.ProvideService(
|
||||
|
||||
Reference in New Issue
Block a user