From d0d707895333ddbfbfe4208f8fc8bf65bf0e86e6 Mon Sep 17 00:00:00 2001 From: Mariell Hoversholm Date: Thu, 27 Mar 2025 15:46:09 +0100 Subject: [PATCH] App Platform: Remove mutable globals (#102962) * App Platform: Remove mutable globals * chore: clarify why this exists * fix: support multi-tenant mode * refactor: call builder providers directly * CI: Force re-build --- pkg/api/dashboard_test.go | 3 +- pkg/api/folder_bench_test.go | 3 +- .../ossaccesscontrol/testutil/testutil.go | 3 +- .../accesscontrol/accesscontrol_test.go | 3 +- .../annotationsimpl/annotations_test.go | 5 +- pkg/services/apiserver/builder/helper_test.go | 7 +- pkg/services/apiserver/builder/scheme.go | 32 +++++++ pkg/services/apiserver/restconfig.go | 86 ++++++++++++++++++ pkg/services/apiserver/service.go | 88 ++++--------------- pkg/services/apiserver/wireset.go | 5 +- pkg/services/authz/rbac.go | 3 +- .../database/database_folder_test.go | 3 +- .../dashboards/database/database_test.go | 5 +- .../dashboard_service_integration_test.go | 5 ++ pkg/services/folder/folderimpl/folder.go | 5 +- pkg/services/folder/folderimpl/folder_test.go | 4 +- .../libraryelements/libraryelements_test.go | 9 +- .../librarypanels/librarypanels_test.go | 5 +- .../ngalert/api/api_provisioning_test.go | 3 +- .../ngalert/provisioning/alert_rules_test.go | 3 +- pkg/services/ngalert/testutil/testutil.go | 3 +- .../dashboards/file_reader_test.go | 3 +- .../provisioning/dashboards/validator_test.go | 3 +- .../publicdashboards/service/service_test.go | 3 +- pkg/services/quota/quotaimpl/quota_test.go | 3 +- .../sqlstore/permissions/dashboard_test.go | 3 +- .../permissions/dashboards_bench_test.go | 3 +- .../federated/federatedtests/stats_test.go | 3 +- pkg/tests/apis/provisioning/helper_test.go | 3 - 29 files changed, 199 insertions(+), 108 deletions(-) create mode 100644 pkg/services/apiserver/builder/scheme.go create mode 100644 pkg/services/apiserver/restconfig.go diff --git a/pkg/api/dashboard_test.go b/pkg/api/dashboard_test.go index c32c3d1835c..3909a70c561 100644 --- a/pkg/api/dashboard_test.go +++ b/pkg/api/dashboard_test.go @@ -34,6 +34,7 @@ import ( "github.com/grafana/grafana/pkg/services/accesscontrol/actest" accesscontrolmock "github.com/grafana/grafana/pkg/services/accesscontrol/mock" "github.com/grafana/grafana/pkg/services/annotations/annotationstest" + "github.com/grafana/grafana/pkg/services/apiserver" "github.com/grafana/grafana/pkg/services/apiserver/client" contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model" "github.com/grafana/grafana/pkg/services/dashboards" @@ -941,7 +942,7 @@ func getDashboardShouldReturn200WithConfig(t *testing.T, sc *scenarioContext, pr folderSvc := folderimpl.ProvideService( fStore, ac, bus.ProvideBus(tracing.InitializeTracerForTest()), dashboardStore, folderStore, nil, db, features, supportbundlestest.NewFakeBundleService(), nil, cfg, nil, tracing.InitializeTracerForTest(), nil, - dualwrite.ProvideTestService(), sort.ProvideService()) + dualwrite.ProvideTestService(), sort.ProvideService(), apiserver.WithoutRestConfig) if dashboardService == nil { dashboardService, err = service.ProvideDashboardServiceImpl( cfg, dashboardStore, folderStore, features, folderPermissions, diff --git a/pkg/api/folder_bench_test.go b/pkg/api/folder_bench_test.go index 03a9ab1cf63..222eaa6735a 100644 --- a/pkg/api/folder_bench_test.go +++ b/pkg/api/folder_bench_test.go @@ -29,6 +29,7 @@ import ( "github.com/grafana/grafana/pkg/services/accesscontrol/ossaccesscontrol" "github.com/grafana/grafana/pkg/services/accesscontrol/permreg" "github.com/grafana/grafana/pkg/services/accesscontrol/resourcepermissions" + "github.com/grafana/grafana/pkg/services/apiserver" "github.com/grafana/grafana/pkg/services/apiserver/client" "github.com/grafana/grafana/pkg/services/contexthandler/ctxkey" contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model" @@ -466,7 +467,7 @@ func setupServer(b testing.TB, sc benchScenario, features featuremgmt.FeatureTog fStore := folderimpl.ProvideStore(sc.db) folderServiceWithFlagOn := folderimpl.ProvideService( fStore, ac, bus.ProvideBus(tracing.InitializeTracerForTest()), dashStore, folderStore, - nil, sc.db, features, supportbundlestest.NewFakeBundleService(), nil, cfg, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), sort.ProvideService()) + nil, sc.db, features, supportbundlestest.NewFakeBundleService(), nil, cfg, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), sort.ProvideService(), apiserver.WithoutRestConfig) acSvc := acimpl.ProvideOSSService( sc.cfg, acdb.ProvideService(sc.db), actionSets, localcache.ProvideService(), features, tracing.InitializeTracerForTest(), sc.db, permreg.ProvidePermissionRegistry(), nil, diff --git a/pkg/services/accesscontrol/ossaccesscontrol/testutil/testutil.go b/pkg/services/accesscontrol/ossaccesscontrol/testutil/testutil.go index b16046e2dc1..abfce0c4b9c 100644 --- a/pkg/services/accesscontrol/ossaccesscontrol/testutil/testutil.go +++ b/pkg/services/accesscontrol/ossaccesscontrol/testutil/testutil.go @@ -10,6 +10,7 @@ import ( "github.com/grafana/grafana/pkg/services/accesscontrol/ossaccesscontrol" "github.com/grafana/grafana/pkg/services/accesscontrol/permreg" "github.com/grafana/grafana/pkg/services/accesscontrol/resourcepermissions" + "github.com/grafana/grafana/pkg/services/apiserver" "github.com/grafana/grafana/pkg/services/dashboards/database" "github.com/grafana/grafana/pkg/services/featuremgmt" "github.com/grafana/grafana/pkg/services/folder/folderimpl" @@ -49,7 +50,7 @@ func ProvideFolderPermissions( folderStore := folderimpl.ProvideDashboardFolderStore(sqlStore) fService := folderimpl.ProvideService( fStore, ac, bus.ProvideBus(tracing.InitializeTracerForTest()), dashboardStore, folderStore, - nil, sqlStore, features, supportbundlestest.NewFakeBundleService(), nil, cfg, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), sort.ProvideService()) + nil, sqlStore, features, supportbundlestest.NewFakeBundleService(), nil, cfg, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), sort.ProvideService(), apiserver.WithoutRestConfig) acSvc := acimpl.ProvideOSSService( cfg, acdb.ProvideService(sqlStore), actionSets, localcache.ProvideService(), diff --git a/pkg/services/annotations/accesscontrol/accesscontrol_test.go b/pkg/services/annotations/accesscontrol/accesscontrol_test.go index c92e1b9546b..0ee98bda98d 100644 --- a/pkg/services/annotations/accesscontrol/accesscontrol_test.go +++ b/pkg/services/annotations/accesscontrol/accesscontrol_test.go @@ -18,6 +18,7 @@ import ( accesscontrolmock "github.com/grafana/grafana/pkg/services/accesscontrol/mock" "github.com/grafana/grafana/pkg/services/annotations" "github.com/grafana/grafana/pkg/services/annotations/testutil" + "github.com/grafana/grafana/pkg/services/apiserver" "github.com/grafana/grafana/pkg/services/apiserver/client" "github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/dashboards/database" @@ -50,7 +51,7 @@ func TestIntegrationAuthorize(t *testing.T) { ac := actest.FakeAccessControl{ExpectedEvaluate: true} folderSvc := folderimpl.ProvideService( fStore, ac, bus.ProvideBus(tracing.InitializeTracerForTest()), dashStore, folderStore, - nil, sql, featuremgmt.WithFeatures(), supportbundlestest.NewFakeBundleService(), nil, cfg, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), sort.ProvideService()) + nil, sql, featuremgmt.WithFeatures(), supportbundlestest.NewFakeBundleService(), nil, cfg, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), sort.ProvideService(), apiserver.WithoutRestConfig) dashSvc, err := dashboardsservice.ProvideDashboardServiceImpl(cfg, dashStore, folderStore, featuremgmt.WithFeatures(), accesscontrolmock.NewMockedPermissionsService(), ac, folderSvc, fStore, nil, client.MockTestRestConfig{}, nil, quotatest.New(false, nil), nil, nil, nil, dualwrite.ProvideTestService(), sort.ProvideService(), serverlock.ProvideService(sql, tracing.InitializeTracerForTest()), diff --git a/pkg/services/annotations/annotationsimpl/annotations_test.go b/pkg/services/annotations/annotationsimpl/annotations_test.go index 8e169e88401..32bc3f51ca3 100644 --- a/pkg/services/annotations/annotationsimpl/annotations_test.go +++ b/pkg/services/annotations/annotationsimpl/annotations_test.go @@ -21,6 +21,7 @@ import ( accesscontrolmock "github.com/grafana/grafana/pkg/services/accesscontrol/mock" "github.com/grafana/grafana/pkg/services/annotations" "github.com/grafana/grafana/pkg/services/annotations/testutil" + "github.com/grafana/grafana/pkg/services/apiserver" "github.com/grafana/grafana/pkg/services/apiserver/client" "github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/dashboards/database" @@ -63,7 +64,7 @@ func TestIntegrationAnnotationListingWithRBAC(t *testing.T) { ac := actest.FakeAccessControl{ExpectedEvaluate: true} folderSvc := folderimpl.ProvideService( fStore, ac, bus.ProvideBus(tracing.InitializeTracerForTest()), dashStore, folderStore, - nil, sql, featuremgmt.WithFeatures(), supportbundlestest.NewFakeBundleService(), nil, cfg, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), sort.ProvideService()) + nil, sql, featuremgmt.WithFeatures(), supportbundlestest.NewFakeBundleService(), nil, cfg, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), sort.ProvideService(), apiserver.WithoutRestConfig) dashSvc, err := dashboardsservice.ProvideDashboardServiceImpl(cfg, dashStore, folderStore, featuremgmt.WithFeatures(), accesscontrolmock.NewMockedPermissionsService(), ac, folderSvc, fStore, nil, client.MockTestRestConfig{}, nil, quotatest.New(false, nil), nil, nil, nil, dualwrite.ProvideTestService(), sort.ProvideService(), serverlock.ProvideService(sql, tracing.InitializeTracerForTest()), @@ -248,7 +249,7 @@ func TestIntegrationAnnotationListingWithInheritedRBAC(t *testing.T) { folderStore := folderimpl.ProvideDashboardFolderStore(sql) folderSvc := folderimpl.ProvideService( fStore, ac, bus.ProvideBus(tracing.InitializeTracerForTest()), dashStore, folderStore, - nil, sql, features, supportbundlestest.NewFakeBundleService(), nil, cfg, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), sort.ProvideService()) + nil, sql, features, supportbundlestest.NewFakeBundleService(), nil, cfg, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), sort.ProvideService(), apiserver.WithoutRestConfig) dashSvc, err := dashboardsservice.ProvideDashboardServiceImpl(cfg, dashStore, folderStore, features, accesscontrolmock.NewMockedPermissionsService(), ac, folderSvc, fStore, nil, client.MockTestRestConfig{}, nil, quotatest.New(false, nil), nil, nil, nil, dualwrite.ProvideTestService(), sort.ProvideService(), serverlock.ProvideService(sql, tracing.InitializeTracerForTest()), diff --git a/pkg/services/apiserver/builder/helper_test.go b/pkg/services/apiserver/builder/helper_test.go index f3414b47579..880cf219abd 100644 --- a/pkg/services/apiserver/builder/helper_test.go +++ b/pkg/services/apiserver/builder/helper_test.go @@ -11,7 +11,6 @@ import ( "k8s.io/apiserver/pkg/server" "k8s.io/kube-openapi/pkg/common" - "github.com/grafana/grafana/pkg/services/apiserver" "github.com/grafana/grafana/pkg/services/apiserver/builder" ) @@ -60,7 +59,11 @@ func TestAddPostStartHooks(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - config := server.NewRecommendedConfig(apiserver.Codecs) + t.Parallel() + + scheme := builder.ProvideScheme() + codecs := builder.ProvideCodecFactory(scheme) + config := server.NewRecommendedConfig(codecs) err := builder.AddPostStartHooks(config, tt.builders) if tt.wantErr { require.Error(t, err) diff --git a/pkg/services/apiserver/builder/scheme.go b/pkg/services/apiserver/builder/scheme.go new file mode 100644 index 00000000000..0942e1757ca --- /dev/null +++ b/pkg/services/apiserver/builder/scheme.go @@ -0,0 +1,32 @@ +package builder + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/apimachinery/pkg/runtime/serializer" +) + +func ProvideScheme() *runtime.Scheme { + unversionedVersion := schema.GroupVersion{Group: "", Version: "v1"} + unversionedTypes := []runtime.Object{ + &metav1.Status{}, + &metav1.WatchEvent{}, + &metav1.APIVersions{}, + &metav1.APIGroupList{}, + &metav1.APIGroup{}, + &metav1.APIResourceList{}, + &metav1.PartialObjectMetadata{}, + &metav1.PartialObjectMetadataList{}, + } + + scheme := runtime.NewScheme() + // we need to add the options to empty v1 + metav1.AddToGroupVersion(scheme, schema.GroupVersion{Group: "", Version: "v1"}) + scheme.AddUnversionedTypes(unversionedVersion, unversionedTypes...) + return scheme +} + +func ProvideCodecFactory(scheme *runtime.Scheme) serializer.CodecFactory { + return serializer.NewCodecFactory(scheme) +} diff --git a/pkg/services/apiserver/restconfig.go b/pkg/services/apiserver/restconfig.go new file mode 100644 index 00000000000..ee822e1917e --- /dev/null +++ b/pkg/services/apiserver/restconfig.go @@ -0,0 +1,86 @@ +package apiserver + +import ( + "context" + "errors" + "net/http" + + contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model" + clientrest "k8s.io/client-go/rest" +) + +type RestConfigProvider interface { + GetRestConfig(context.Context) (*clientrest.Config, error) +} + +type RestConfigProviderFunc func(context.Context) (*clientrest.Config, error) + +func (f RestConfigProviderFunc) GetRestConfig(ctx context.Context) (*clientrest.Config, error) { + return f(ctx) +} + +// WithoutRestConfig is a RestConfigProvider that always returns an error. +// This is intended for use in unit tests where the rest config is not needed. +var WithoutRestConfig = RestConfigProviderFunc(func(context.Context) (*clientrest.Config, error) { + return nil, errors.New("rest config will not be available (unit test?)") +}) + +type DirectRestConfigProvider interface { + // GetDirectRestConfig returns a k8s client configuration that will use the same + // logged in user as the current request context. This is useful when + // creating clients that map legacy API handlers to k8s backed services + GetDirectRestConfig(c *contextmodel.ReqContext) *clientrest.Config + + // This can be used to rewrite incoming requests to path now supported under /apis + DirectlyServeHTTP(w http.ResponseWriter, r *http.Request) +} + +func ProvideEventualRestConfigProvider() *eventualRestConfigProvider { + return &eventualRestConfigProvider{ + ready: make(chan struct{}), + } +} + +var ( + _ RestConfigProvider = (*eventualRestConfigProvider)(nil) + _ DirectRestConfigProvider = (*eventualRestConfigProvider)(nil) +) + +// eventualRestConfigProvider is a RestConfigProvider that will not return a rest config until the ready channel is closed. +// This exists to alleviate a circular dependency between the apiserver.server's dependencies and their dependencies wanting a rest config. +// Importantly, this is handled by wire as opposed to a mutable global. +type eventualRestConfigProvider struct { + // When this channel is closed, we can start returning the rest config. + ready chan struct{} + cfg interface { + RestConfigProvider + DirectRestConfigProvider + } +} + +func (e *eventualRestConfigProvider) GetRestConfig(ctx context.Context) (*clientrest.Config, error) { + select { + case <-e.ready: + return e.cfg.GetRestConfig(ctx) + case <-ctx.Done(): + return nil, ctx.Err() + } +} + +func (e *eventualRestConfigProvider) GetDirectRestConfig(c *contextmodel.ReqContext) *clientrest.Config { + select { + case <-e.ready: + return e.cfg.GetDirectRestConfig(c) + case <-c.Req.Context().Done(): + return nil + } +} + +func (e *eventualRestConfigProvider) DirectlyServeHTTP(w http.ResponseWriter, r *http.Request) { + select { + case <-e.ready: + e.cfg.DirectlyServeHTTP(w, r) + case <-r.Context().Done(): + // Do nothing: the request has been cancelled. + } +} diff --git a/pkg/services/apiserver/service.go b/pkg/services/apiserver/service.go index f7c2be03cbc..b2b417e14be 100644 --- a/pkg/services/apiserver/service.go +++ b/pkg/services/apiserver/service.go @@ -7,7 +7,6 @@ import ( "path" "github.com/prometheus/client_golang/prometheus" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/serializer" @@ -58,80 +57,23 @@ var ( _ RestConfigProvider = (*service)(nil) _ registry.BackgroundService = (*service)(nil) _ registry.CanBeDisabled = (*service)(nil) - - Scheme = runtime.NewScheme() - Codecs = serializer.NewCodecFactory(Scheme) - - unversionedVersion = schema.GroupVersion{Group: "", Version: "v1"} - unversionedTypes = []runtime.Object{ - &metav1.Status{}, - &metav1.WatchEvent{}, - &metav1.APIVersions{}, - &metav1.APIGroupList{}, - &metav1.APIGroup{}, - &metav1.APIResourceList{}, - &metav1.PartialObjectMetadata{}, - &metav1.PartialObjectMetadataList{}, - } - - // internal provider of the package level client Config - restConfig RestConfigProvider - ready = make(chan struct{}) ) const MaxRequestBodyBytes = 16 * 1024 * 1024 // 16MB - determined by the size of `mediumtext` on mysql, which is used to save dashboard data -func init() { - // we need to add the options to empty v1 - metav1.AddToGroupVersion(Scheme, schema.GroupVersion{Group: "", Version: "v1"}) - Scheme.AddUnversionedTypes(unversionedVersion, unversionedTypes...) -} - -// ClearRestConfig clears the package level restConfig. -// This is intended to be used in tests only. -// -// TODO: Refactor such that there is no global state. -func ClearRestConfig() { - restConfig = nil - ready = make(chan struct{}) -} - -// GetRestConfig return a client Config mounted at package level -// This resolves circular dependency issues between apiserver, authz, -// and Folder Service. -// The client Config gets initialized during the first call to -// ProvideService. -// Any call to GetRestConfig will block until we have a restConfig available -func GetRestConfig(ctx context.Context) (*clientrest.Config, error) { - <-ready - return restConfig.GetRestConfig(ctx) -} - type Service interface { services.NamedService registry.BackgroundService registry.CanBeDisabled } -type RestConfigProvider interface { - GetRestConfig(context.Context) (*clientrest.Config, error) -} - -type DirectRestConfigProvider interface { - // GetDirectRestConfig returns a k8s client configuration that will use the same - // logged in user as the current request context. This is useful when - // creating clients that map legacy API handlers to k8s backed services - GetDirectRestConfig(c *contextmodel.ReqContext) *clientrest.Config - - // This can be used to rewrite incoming requests to path now supported under /apis - DirectlyServeHTTP(w http.ResponseWriter, r *http.Request) -} - type service struct { services.NamedService options *grafanaapiserveroptions.Options restConfig *clientrest.Config + scheme *runtime.Scheme + codecs serializer.CodecFactory cfg *setting.Cfg features featuremgmt.FeatureToggles @@ -177,8 +119,13 @@ func ProvideService( storageStatus dualwrite.Service, unified resource.ResourceClient, buildHandlerChainFuncFromBuilders builder.BuildHandlerChainFuncFromBuilders, + eventualRestConfigProvider *eventualRestConfigProvider, ) (*service, error) { + scheme := builder.ProvideScheme() + codecs := builder.ProvideCodecFactory(scheme) s := &service{ + scheme: scheme, + codecs: codecs, log: log.New(modules.GrafanaAPIServer), cfg: cfg, features: features, @@ -244,11 +191,8 @@ func ProvideService( s.rr.Group("/openapi", proxyHandler) s.rr.Group("/version", proxyHandler) - // only set the package level restConfig once - if restConfig == nil { - restConfig = s - close(ready) - } + eventualRestConfigProvider.cfg = s + close(eventualRestConfigProvider.ready) return s, nil } @@ -293,10 +237,10 @@ func (s *service) start(ctx context.Context) error { if len(gvs) == 0 { return fmt.Errorf("no group versions found for builder %T", b) } - if err := b.InstallSchema(Scheme); err != nil { + if err := b.InstallSchema(s.scheme); err != nil { return err } - pvs := Scheme.PrioritizedVersionsForGroup(gvs[0].Group) + pvs := s.scheme.PrioritizedVersionsForGroup(gvs[0].Group) for j, gv := range pvs { if s.features.IsEnabledGlobally(featuremgmt.FlagKubernetesAggregator) { @@ -313,7 +257,7 @@ func (s *service) start(ctx context.Context) error { } } - o := grafanaapiserveroptions.NewOptions(Codecs.LegacyCodec(groupVersions...)) + o := grafanaapiserveroptions.NewOptions(s.codecs.LegacyCodec(groupVersions...)) err := applyGrafanaConfig(s.cfg, s.features, o) if err != nil { return err @@ -332,7 +276,7 @@ func (s *service) start(ctx context.Context) error { } } - serverConfig := genericapiserver.NewRecommendedConfig(Codecs) + serverConfig := genericapiserver.NewRecommendedConfig(s.codecs) if err := o.ApplyTo(serverConfig); err != nil { return err } @@ -365,7 +309,7 @@ func (s *service) start(ctx context.Context) error { // Add OpenAPI specs for each group+version err = builder.SetupConfig( - Scheme, + s.scheme, serverConfig, builders, s.cfg.BuildStamp, @@ -378,7 +322,7 @@ func (s *service) start(ctx context.Context) error { return err } - notFoundHandler := notfoundhandler.New(Codecs, genericapifilters.NoMuxAndDiscoveryIncompleteKey) + notFoundHandler := notfoundhandler.New(s.codecs, genericapifilters.NoMuxAndDiscoveryIncompleteKey) // Create the server server, err := serverConfig.Complete().New("grafana-apiserver", genericapiserver.NewEmptyDelegateWithCustomHandler(notFoundHandler)) @@ -387,7 +331,7 @@ func (s *service) start(ctx context.Context) error { } // Install the API group+version - err = builder.InstallAPIs(Scheme, Codecs, server, serverConfig.RESTOptionsGetter, builders, o.StorageOptions, + err = builder.InstallAPIs(s.scheme, s.codecs, server, serverConfig.RESTOptionsGetter, builders, o.StorageOptions, // Required for the dual writer initialization s.metrics, request.GetNamespaceMapper(s.cfg), kvstore.WithNamespace(s.kvStore, 0, "storage.dualwriting"), s.serverLockService, diff --git a/pkg/services/apiserver/wireset.go b/pkg/services/apiserver/wireset.go index f7163f1ad6f..98200b20ce5 100644 --- a/pkg/services/apiserver/wireset.go +++ b/pkg/services/apiserver/wireset.go @@ -7,9 +7,10 @@ import ( ) var WireSet = wire.NewSet( + ProvideEventualRestConfigProvider, + wire.Bind(new(RestConfigProvider), new(*eventualRestConfigProvider)), + wire.Bind(new(DirectRestConfigProvider), new(*eventualRestConfigProvider)), ProvideService, - wire.Bind(new(RestConfigProvider), new(*service)), wire.Bind(new(Service), new(*service)), - wire.Bind(new(DirectRestConfigProvider), new(*service)), wire.Bind(new(builder.APIRegistrar), new(*service)), ) diff --git a/pkg/services/authz/rbac.go b/pkg/services/authz/rbac.go index 6275c50cd25..4703630d126 100644 --- a/pkg/services/authz/rbac.go +++ b/pkg/services/authz/rbac.go @@ -46,6 +46,7 @@ func ProvideAuthZClient( reg prometheus.Registerer, db db.DB, acService accesscontrol.Service, + restConfig apiserver.RestConfigProvider, ) (authlib.AccessClient, error) { authCfg, err := readAuthzClientSettings(cfg) if err != nil { @@ -68,7 +69,7 @@ func ProvideAuthZClient( // When running in-proc we get a injection cycle between // authz client, resource client and apiserver so we need to use // package level function to get rest config - store.NewAPIFolderStore(tracer, apiserver.GetRestConfig), + store.NewAPIFolderStore(tracer, restConfig.GetRestConfig), legacy.NewLegacySQLStores(sql), store.NewUnionPermissionStore( store.NewStaticPermissionStore(acService), diff --git a/pkg/services/dashboards/database/database_folder_test.go b/pkg/services/dashboards/database/database_folder_test.go index 4b5d602ecbf..ec52d14989a 100644 --- a/pkg/services/dashboards/database/database_folder_test.go +++ b/pkg/services/dashboards/database/database_folder_test.go @@ -17,6 +17,7 @@ import ( "github.com/grafana/grafana/pkg/services/accesscontrol" "github.com/grafana/grafana/pkg/services/accesscontrol/actest" "github.com/grafana/grafana/pkg/services/accesscontrol/mock" + "github.com/grafana/grafana/pkg/services/apiserver" "github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/featuremgmt" "github.com/grafana/grafana/pkg/services/folder" @@ -304,7 +305,7 @@ func TestIntegrationDashboardInheritedFolderRBAC(t *testing.T) { folderStore := folderimpl.ProvideStore(sqlStore) folderSvc := folderimpl.ProvideService( folderStore, mock.New(), bus.ProvideBus(tracer), dashboardWriteStore, folderimpl.ProvideDashboardFolderStore(sqlStore), - nil, sqlStore, features, supportbundlestest.NewFakeBundleService(), nil, cfg, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), sort.ProvideService()) + nil, sqlStore, features, supportbundlestest.NewFakeBundleService(), nil, cfg, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), sort.ProvideService(), apiserver.WithoutRestConfig) parentUID := "" for i := 0; ; i++ { diff --git a/pkg/services/dashboards/database/database_test.go b/pkg/services/dashboards/database/database_test.go index 2074bff0ccb..7d30eca738c 100644 --- a/pkg/services/dashboards/database/database_test.go +++ b/pkg/services/dashboards/database/database_test.go @@ -16,6 +16,7 @@ import ( "github.com/grafana/grafana/pkg/infra/db" "github.com/grafana/grafana/pkg/infra/tracing" "github.com/grafana/grafana/pkg/services/accesscontrol/acimpl" + "github.com/grafana/grafana/pkg/services/apiserver" "github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/featuremgmt" "github.com/grafana/grafana/pkg/services/folder" @@ -964,7 +965,7 @@ func TestIntegrationFindDashboardsByTitle(t *testing.T) { fStore := folderimpl.ProvideStore(sqlStore) folderServiceWithFlagOn := folderimpl.ProvideService( fStore, ac, bus.ProvideBus(tracing.InitializeTracerForTest()), dashboardStore, folderStore, - nil, sqlStore, features, supportbundlestest.NewFakeBundleService(), nil, cfg, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), sort.ProvideService()) + nil, sqlStore, features, supportbundlestest.NewFakeBundleService(), nil, cfg, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), sort.ProvideService(), apiserver.WithoutRestConfig) user := &user.SignedInUser{ OrgID: 1, @@ -1084,7 +1085,7 @@ func TestIntegrationFindDashboardsByFolder(t *testing.T) { folderServiceWithFlagOn := folderimpl.ProvideService( fStore, ac, bus.ProvideBus(tracing.InitializeTracerForTest()), dashboardStore, folderStore, - nil, sqlStore, features, supportbundlestest.NewFakeBundleService(), nil, cfg, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), sort.ProvideService()) + nil, sqlStore, features, supportbundlestest.NewFakeBundleService(), nil, cfg, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), sort.ProvideService(), apiserver.WithoutRestConfig) user := &user.SignedInUser{ OrgID: 1, diff --git a/pkg/services/dashboards/service/dashboard_service_integration_test.go b/pkg/services/dashboards/service/dashboard_service_integration_test.go index 7887e628110..eb116482bdb 100644 --- a/pkg/services/dashboards/service/dashboard_service_integration_test.go +++ b/pkg/services/dashboards/service/dashboard_service_integration_test.go @@ -18,6 +18,7 @@ import ( "github.com/grafana/grafana/pkg/services/accesscontrol/acimpl" "github.com/grafana/grafana/pkg/services/accesscontrol/actest" accesscontrolmock "github.com/grafana/grafana/pkg/services/accesscontrol/mock" + "github.com/grafana/grafana/pkg/services/apiserver" "github.com/grafana/grafana/pkg/services/apiserver/client" "github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/dashboards/database" @@ -797,6 +798,7 @@ func permissionScenario(t *testing.T, desc string, fn permissionScenarioFunc) { nil, dualwrite.ProvideTestService(), sort.ProvideService(), + apiserver.WithoutRestConfig, ) dashboardPermissions := accesscontrolmock.NewMockedPermissionsService() dashboardService, err := ProvideDashboardServiceImpl( @@ -890,6 +892,7 @@ func callSaveWithResult(t *testing.T, cmd dashboards.SaveDashboardCommand, sqlSt nil, dualwrite.ProvideTestService(), sort.ProvideService(), + apiserver.WithoutRestConfig, ) dashboardPermissions := accesscontrolmock.NewMockedPermissionsService() dashboardPermissions.On("SetPermissions", @@ -966,6 +969,7 @@ func saveTestDashboard(t *testing.T, title string, orgID int64, folderUID string nil, dualwrite.ProvideTestService(), sort.ProvideService(), + apiserver.WithoutRestConfig, ) service, err := ProvideDashboardServiceImpl( cfg, dashboardStore, folderStore, @@ -1046,6 +1050,7 @@ func saveTestFolder(t *testing.T, title string, orgID int64, sqlStore db.DB) *da nil, dualwrite.ProvideTestService(), sort.ProvideService(), + apiserver.WithoutRestConfig, ) folderPermissions.On("SetPermissions", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return([]accesscontrol.ResourcePermission{}, nil) service, err := ProvideDashboardServiceImpl( diff --git a/pkg/services/folder/folderimpl/folder.go b/pkg/services/folder/folderimpl/folder.go index 3e80157a0cc..05cc142cf74 100644 --- a/pkg/services/folder/folderimpl/folder.go +++ b/pkg/services/folder/folderimpl/folder.go @@ -91,6 +91,7 @@ func ProvideService( resourceClient resource.ResourceClient, dual dualwrite.Service, sorter sort.Service, + restConfig apiserver.RestConfigProvider, ) *Service { srv := &Service{ log: slog.Default().With("logger", "folder-service"), @@ -118,7 +119,7 @@ func ProvideService( dual, request.GetNamespaceMapper(cfg), v0alpha1.FolderResourceInfo.GroupVersionResource(), - apiserver.GetRestConfig, + restConfig.GetRestConfig, dashboardStore, userService, resourceClient, @@ -136,7 +137,7 @@ func ProvideService( dual, request.GetNamespaceMapper(cfg), dashboardalpha1.DashboardResourceInfo.GroupVersionResource(), - apiserver.GetRestConfig, + restConfig.GetRestConfig, dashboardStore, userService, resourceClient, diff --git a/pkg/services/folder/folderimpl/folder_test.go b/pkg/services/folder/folderimpl/folder_test.go index fcb88a922cf..03512d54116 100644 --- a/pkg/services/folder/folderimpl/folder_test.go +++ b/pkg/services/folder/folderimpl/folder_test.go @@ -29,6 +29,7 @@ import ( "github.com/grafana/grafana/pkg/services/accesscontrol/acimpl" "github.com/grafana/grafana/pkg/services/accesscontrol/actest" acmock "github.com/grafana/grafana/pkg/services/accesscontrol/mock" + "github.com/grafana/grafana/pkg/services/apiserver" "github.com/grafana/grafana/pkg/services/apiserver/client" "github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/dashboards/dashboardaccess" @@ -71,7 +72,8 @@ func TestIntegrationProvideFolderService(t *testing.T) { store := ProvideStore(db) ProvideService( store, ac, bus.ProvideBus(tracing.InitializeTracerForTest()), - nil, nil, nil, db, featuremgmt.WithFeatures(), supportbundlestest.NewFakeBundleService(), nil, cfg, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), sort.ProvideService()) + nil, nil, nil, db, featuremgmt.WithFeatures(), supportbundlestest.NewFakeBundleService(), nil, cfg, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), sort.ProvideService(), + apiserver.WithoutRestConfig) require.Len(t, ac.Calls.RegisterAttributeScopeResolver, 2) }) diff --git a/pkg/services/libraryelements/libraryelements_test.go b/pkg/services/libraryelements/libraryelements_test.go index 8eec5685b14..3b7b4d96204 100644 --- a/pkg/services/libraryelements/libraryelements_test.go +++ b/pkg/services/libraryelements/libraryelements_test.go @@ -27,6 +27,7 @@ import ( "github.com/grafana/grafana/pkg/services/accesscontrol/acimpl" "github.com/grafana/grafana/pkg/services/accesscontrol/actest" acmock "github.com/grafana/grafana/pkg/services/accesscontrol/mock" + "github.com/grafana/grafana/pkg/services/apiserver" "github.com/grafana/grafana/pkg/services/apiserver/client" contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model" "github.com/grafana/grafana/pkg/services/dashboards" @@ -351,7 +352,7 @@ func createDashboard(t *testing.T, sqlStore db.DB, user user.SignedInUser, dash fStore := folderimpl.ProvideStore(sqlStore) folderSvc := folderimpl.ProvideService( fStore, ac, bus.ProvideBus(tracing.InitializeTracerForTest()), dashboardStore, folderStore, - nil, sqlStore, features, supportbundlestest.NewFakeBundleService(), nil, cfg, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), sort.ProvideService()) + nil, sqlStore, features, supportbundlestest.NewFakeBundleService(), nil, cfg, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), sort.ProvideService(), apiserver.WithoutRestConfig) _, err = folderSvc.Create(context.Background(), &folder.CreateFolderCommand{UID: folderUID, SignedInUser: &user, Title: folderUID + "-title"}) require.NoError(t, err) service, err := dashboardservice.ProvideDashboardServiceImpl( @@ -393,7 +394,7 @@ func createFolder(t *testing.T, sc scenarioContext, title string, folderSvc fold store := folderimpl.ProvideStore(sc.sqlStore) folderSvc = folderimpl.ProvideService( store, ac, bus.ProvideBus(tracing.InitializeTracerForTest()), dashboardStore, folderStore, - nil, sc.sqlStore, features, supportbundlestest.NewFakeBundleService(), nil, cfg, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), sort.ProvideService()) + nil, sc.sqlStore, features, supportbundlestest.NewFakeBundleService(), nil, cfg, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), sort.ProvideService(), apiserver.WithoutRestConfig) t.Logf("Creating folder with title %q and UID uid_for_%s", title, title) } ctx := identity.WithRequester(context.Background(), &sc.user) @@ -457,7 +458,7 @@ func scenarioWithPanel(t *testing.T, desc string, fn func(t *testing.T, sc scena fStore := folderimpl.ProvideStore(sqlStore) folderSvc := folderimpl.ProvideService( fStore, ac, bus.ProvideBus(tracing.InitializeTracerForTest()), dashboardStore, folderStore, - nil, sqlStore, features, supportbundlestest.NewFakeBundleService(), nil, cfg, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), sort.ProvideService()) + nil, sqlStore, features, supportbundlestest.NewFakeBundleService(), nil, cfg, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), sort.ProvideService(), apiserver.WithoutRestConfig) dashboardService, svcErr := dashboardservice.ProvideDashboardServiceImpl( cfg, dashboardStore, folderStore, features, folderPermissions, ac, @@ -528,7 +529,7 @@ func testScenario(t *testing.T, desc string, fn func(t *testing.T, sc scenarioCo publicDash.On("DeleteByDashboardUIDs", mock.Anything, mock.Anything, mock.Anything).Return(nil) folderSvc := folderimpl.ProvideService( fStore, ac, bus.ProvideBus(tracing.InitializeTracerForTest()), dashboardStore, folderStore, - nil, sqlStore, features, supportbundlestest.NewFakeBundleService(), publicDash, cfg, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), sort.ProvideService()) + nil, sqlStore, features, supportbundlestest.NewFakeBundleService(), publicDash, cfg, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), sort.ProvideService(), apiserver.WithoutRestConfig) alertStore, err := ngstore.ProvideDBStore(cfg, features, sqlStore, &foldertest.FakeService{}, &dashboards.FakeDashboardService{}, ac, bus.ProvideBus(tracing.InitializeTracerForTest())) require.NoError(t, err) err = folderSvc.RegisterService(alertStore) diff --git a/pkg/services/librarypanels/librarypanels_test.go b/pkg/services/librarypanels/librarypanels_test.go index 930ec705e64..4a111d204a8 100644 --- a/pkg/services/librarypanels/librarypanels_test.go +++ b/pkg/services/librarypanels/librarypanels_test.go @@ -24,6 +24,7 @@ import ( "github.com/grafana/grafana/pkg/services/accesscontrol" "github.com/grafana/grafana/pkg/services/accesscontrol/actest" acmock "github.com/grafana/grafana/pkg/services/accesscontrol/mock" + "github.com/grafana/grafana/pkg/services/apiserver" "github.com/grafana/grafana/pkg/services/apiserver/client" "github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/dashboards/database" @@ -763,7 +764,7 @@ func createFolder(t *testing.T, sc scenarioContext, title string) *folder.Folder fStore := folderimpl.ProvideStore(sc.sqlStore) s := folderimpl.ProvideService( fStore, ac, bus.ProvideBus(tracing.InitializeTracerForTest()), dashboardStore, folderStore, - nil, sc.sqlStore, features, supportbundlestest.NewFakeBundleService(), nil, cfg, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), sort.ProvideService()) + nil, sc.sqlStore, features, supportbundlestest.NewFakeBundleService(), nil, cfg, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), sort.ProvideService(), apiserver.WithoutRestConfig) t.Logf("Creating folder with title and UID %q", title) ctx := identity.WithRequester(context.Background(), sc.user) @@ -852,7 +853,7 @@ func testScenario(t *testing.T, desc string, fn func(t *testing.T, sc scenarioCo folderService := folderimpl.ProvideService( fStore, ac, bus.ProvideBus(tracing.InitializeTracerForTest()), dashboardStore, folderStore, - nil, sqlStore, features, supportbundlestest.NewFakeBundleService(), nil, cfg, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), sort.ProvideService()) + nil, sqlStore, features, supportbundlestest.NewFakeBundleService(), nil, cfg, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), sort.ProvideService(), apiserver.WithoutRestConfig) elementService := libraryelements.ProvideService(cfg, sqlStore, routing.NewRouteRegister(), folderService, features, ac, dashService) service := LibraryPanelService{ diff --git a/pkg/services/ngalert/api/api_provisioning_test.go b/pkg/services/ngalert/api/api_provisioning_test.go index 8eac2559e21..c2126264017 100644 --- a/pkg/services/ngalert/api/api_provisioning_test.go +++ b/pkg/services/ngalert/api/api_provisioning_test.go @@ -27,6 +27,7 @@ import ( "github.com/grafana/grafana/pkg/infra/tracing" "github.com/grafana/grafana/pkg/services/accesscontrol" "github.com/grafana/grafana/pkg/services/accesscontrol/actest" + "github.com/grafana/grafana/pkg/services/apiserver" contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model" "github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/dashboards/database" @@ -2000,7 +2001,7 @@ func createTestEnv(t *testing.T, testConfig string) testEnvironment { fStore := folderimpl.ProvideStore(sqlStore) folderService := folderimpl.ProvideService( fStore, actest.FakeAccessControl{ExpectedEvaluate: true}, bus.ProvideBus(tracing.InitializeTracerForTest()), dashboardStore, folderStore, - nil, sqlStore, featuremgmt.WithFeatures(), supportbundlestest.NewFakeBundleService(), nil, cfg, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), sort.ProvideService()) + nil, sqlStore, featuremgmt.WithFeatures(), supportbundlestest.NewFakeBundleService(), nil, cfg, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), sort.ProvideService(), apiserver.WithoutRestConfig) store := store.DBstore{ Logger: log, SQLStore: sqlStore, diff --git a/pkg/services/ngalert/provisioning/alert_rules_test.go b/pkg/services/ngalert/provisioning/alert_rules_test.go index bb9360c8350..39518d3a9d7 100644 --- a/pkg/services/ngalert/provisioning/alert_rules_test.go +++ b/pkg/services/ngalert/provisioning/alert_rules_test.go @@ -17,6 +17,7 @@ import ( "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/bus" "github.com/grafana/grafana/pkg/expr" + "github.com/grafana/grafana/pkg/services/apiserver" "github.com/grafana/grafana/pkg/services/ngalert/accesscontrol" "github.com/grafana/grafana/pkg/services/ngalert/tests/fakes" "github.com/grafana/grafana/pkg/services/search/sort" @@ -1993,7 +1994,7 @@ func TestProvisiongWithFullpath(t *testing.T) { fStore := folderimpl.ProvideStore(sqlStore) folderService := folderimpl.ProvideService( fStore, ac, inProcBus, dashboardStore, folderStore, - nil, sqlStore, features, supportbundlestest.NewFakeBundleService(), nil, cfg, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), sort.ProvideService()) + nil, sqlStore, features, supportbundlestest.NewFakeBundleService(), nil, cfg, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), sort.ProvideService(), apiserver.WithoutRestConfig) ruleService := createAlertRuleService(t, folderService) var orgID int64 = 1 diff --git a/pkg/services/ngalert/testutil/testutil.go b/pkg/services/ngalert/testutil/testutil.go index daa61da93d3..e59a676126c 100644 --- a/pkg/services/ngalert/testutil/testutil.go +++ b/pkg/services/ngalert/testutil/testutil.go @@ -13,6 +13,7 @@ import ( "github.com/grafana/grafana/pkg/infra/tracing" "github.com/grafana/grafana/pkg/services/accesscontrol" acmock "github.com/grafana/grafana/pkg/services/accesscontrol/mock" + "github.com/grafana/grafana/pkg/services/apiserver" "github.com/grafana/grafana/pkg/services/apiserver/client" "github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/dashboards/database" @@ -36,7 +37,7 @@ func SetupFolderService(tb testing.TB, cfg *setting.Cfg, db db.DB, dashboardStor tb.Helper() fStore := folderimpl.ProvideStore(db) return folderimpl.ProvideService(fStore, ac, bus, dashboardStore, folderStore, nil, db, - features, supportbundlestest.NewFakeBundleService(), nil, cfg, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), sort.ProvideService()) + features, supportbundlestest.NewFakeBundleService(), nil, cfg, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), sort.ProvideService(), apiserver.WithoutRestConfig) } func SetupDashboardService(tb testing.TB, sqlStore db.DB, fs *folderimpl.DashboardFolderStoreImpl, cfg *setting.Cfg) (*dashboardservice.DashboardServiceImpl, dashboards.Store) { diff --git a/pkg/services/provisioning/dashboards/file_reader_test.go b/pkg/services/provisioning/dashboards/file_reader_test.go index d9e962e160c..22e822a138c 100644 --- a/pkg/services/provisioning/dashboards/file_reader_test.go +++ b/pkg/services/provisioning/dashboards/file_reader_test.go @@ -18,6 +18,7 @@ import ( "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/tracing" "github.com/grafana/grafana/pkg/services/accesscontrol/actest" + "github.com/grafana/grafana/pkg/services/apiserver" "github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/dashboards/database" "github.com/grafana/grafana/pkg/services/featuremgmt" @@ -133,7 +134,7 @@ func TestDashboardFileReader(t *testing.T) { folderStore := folderimpl.ProvideDashboardFolderStore(sql) folderSvc := folderimpl.ProvideService(fStore, actest.FakeAccessControl{}, bus.ProvideBus(tracing.InitializeTracerForTest()), dashStore, folderStore, nil, sql, featuremgmt.WithFeatures(), - supportbundlestest.NewFakeBundleService(), nil, cfgT, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), sort.ProvideService()) + supportbundlestest.NewFakeBundleService(), nil, cfgT, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), sort.ProvideService(), apiserver.WithoutRestConfig) t.Run("Reading dashboards from disk", func(t *testing.T) { t.Run("Can read default dashboard", func(t *testing.T) { diff --git a/pkg/services/provisioning/dashboards/validator_test.go b/pkg/services/provisioning/dashboards/validator_test.go index 29d9ab4aefd..b2819a3c4f4 100644 --- a/pkg/services/provisioning/dashboards/validator_test.go +++ b/pkg/services/provisioning/dashboards/validator_test.go @@ -14,6 +14,7 @@ import ( "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/tracing" "github.com/grafana/grafana/pkg/services/accesscontrol/actest" + "github.com/grafana/grafana/pkg/services/apiserver" "github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/dashboards/database" "github.com/grafana/grafana/pkg/services/featuremgmt" @@ -52,7 +53,7 @@ func TestDuplicatesValidator(t *testing.T) { folderStore := folderimpl.ProvideDashboardFolderStore(sql) folderSvc := folderimpl.ProvideService(fStore, actest.FakeAccessControl{}, bus.ProvideBus(tracing.InitializeTracerForTest()), dashStore, folderStore, nil, sql, featuremgmt.WithFeatures(), - supportbundlestest.NewFakeBundleService(), nil, cfgT, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), grafanasort.ProvideService()) + supportbundlestest.NewFakeBundleService(), nil, cfgT, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), grafanasort.ProvideService(), apiserver.WithoutRestConfig) t.Run("Duplicates validator should collect info about duplicate UIDs and titles within folders", func(t *testing.T) { const folderName = "duplicates-validator-folder" diff --git a/pkg/services/publicdashboards/service/service_test.go b/pkg/services/publicdashboards/service/service_test.go index e8ea78749a6..ac3db3d394c 100644 --- a/pkg/services/publicdashboards/service/service_test.go +++ b/pkg/services/publicdashboards/service/service_test.go @@ -25,6 +25,7 @@ import ( "github.com/grafana/grafana/pkg/services/accesscontrol" "github.com/grafana/grafana/pkg/services/accesscontrol/actest" acmock "github.com/grafana/grafana/pkg/services/accesscontrol/mock" + "github.com/grafana/grafana/pkg/services/apiserver" "github.com/grafana/grafana/pkg/services/apiserver/client" "github.com/grafana/grafana/pkg/services/dashboards" dashboardsDB "github.com/grafana/grafana/pkg/services/dashboards/database" @@ -1400,7 +1401,7 @@ func TestPublicDashboardServiceImpl_ListPublicDashboards(t *testing.T) { folderStore := folderimpl.ProvideDashboardFolderStore(testDB) folderSvc := folderimpl.ProvideService( fStore, ac, bus.ProvideBus(tracing.InitializeTracerForTest()), dashStore, folderStore, - nil, testDB, features, supportbundlestest.NewFakeBundleService(), nil, cfg, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), sort.ProvideService()) + nil, testDB, features, supportbundlestest.NewFakeBundleService(), nil, cfg, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), sort.ProvideService(), apiserver.WithoutRestConfig) dashboardService, err := dashsvc.ProvideDashboardServiceImpl(cfg, dashStore, folderStore, featuremgmt.WithFeatures(), folderPermissions, ac, folderSvc, fStore, nil, client.MockTestRestConfig{}, nil, quotatest.New(false, nil), nil, nil, nil, dualwrite.ProvideTestService(), sort.ProvideService(), serverlock.ProvideService(testDB, tracing.InitializeTracerForTest()), diff --git a/pkg/services/quota/quotaimpl/quota_test.go b/pkg/services/quota/quotaimpl/quota_test.go index c8cc6d5dfde..c55946c2352 100644 --- a/pkg/services/quota/quotaimpl/quota_test.go +++ b/pkg/services/quota/quotaimpl/quota_test.go @@ -22,6 +22,7 @@ import ( "github.com/grafana/grafana/pkg/services/annotations/annotationstest" "github.com/grafana/grafana/pkg/services/apikey" "github.com/grafana/grafana/pkg/services/apikey/apikeyimpl" + "github.com/grafana/grafana/pkg/services/apiserver" "github.com/grafana/grafana/pkg/services/apiserver/client" "github.com/grafana/grafana/pkg/services/auth" "github.com/grafana/grafana/pkg/services/auth/authimpl" @@ -499,7 +500,7 @@ func setupEnv(t *testing.T, sqlStore db.DB, cfg *setting.Cfg, b bus.Bus, quotaSe ac := acimpl.ProvideAccessControl(featuremgmt.WithFeatures()) folderSvc := folderimpl.ProvideService( fStore, acmock.New(), bus.ProvideBus(tracing.InitializeTracerForTest()), dashStore, folderStore, - nil, sqlStore, featuremgmt.WithFeatures(), supportbundlestest.NewFakeBundleService(), nil, cfg, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), sort.ProvideService()) + nil, sqlStore, featuremgmt.WithFeatures(), supportbundlestest.NewFakeBundleService(), nil, cfg, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), sort.ProvideService(), apiserver.WithoutRestConfig) dashService, err := dashService.ProvideDashboardServiceImpl(cfg, dashStore, folderStore, featuremgmt.WithFeatures(), acmock.NewMockedPermissionsService(), ac, folderSvc, fStore, nil, client.MockTestRestConfig{}, nil, quotaService, nil, nil, nil, dualwrite.ProvideTestService(), sort.ProvideService(), serverlock.ProvideService(sqlStore, tracing.InitializeTracerForTest()), diff --git a/pkg/services/sqlstore/permissions/dashboard_test.go b/pkg/services/sqlstore/permissions/dashboard_test.go index f26e923228f..d59281baa95 100644 --- a/pkg/services/sqlstore/permissions/dashboard_test.go +++ b/pkg/services/sqlstore/permissions/dashboard_test.go @@ -16,6 +16,7 @@ import ( "github.com/grafana/grafana/pkg/infra/tracing" "github.com/grafana/grafana/pkg/services/accesscontrol" "github.com/grafana/grafana/pkg/services/accesscontrol/actest" + "github.com/grafana/grafana/pkg/services/apiserver" "github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/dashboards/dashboardaccess" "github.com/grafana/grafana/pkg/services/dashboards/database" @@ -839,7 +840,7 @@ func setupNestedTest(t *testing.T, usr *user.SignedInUser, perms []accesscontrol fStore := folderimpl.ProvideStore(db) folderSvc := folderimpl.ProvideService( fStore, actest.FakeAccessControl{ExpectedEvaluate: true}, bus.ProvideBus(tracing.InitializeTracerForTest()), dashStore, folderimpl.ProvideDashboardFolderStore(db), - nil, db, features, supportbundlestest.NewFakeBundleService(), nil, cfg, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), sort.ProvideService()) + nil, db, features, supportbundlestest.NewFakeBundleService(), nil, cfg, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), sort.ProvideService(), apiserver.WithoutRestConfig) // create parent folder parent, err := folderSvc.Create(context.Background(), &folder.CreateFolderCommand{ diff --git a/pkg/services/sqlstore/permissions/dashboards_bench_test.go b/pkg/services/sqlstore/permissions/dashboards_bench_test.go index b396bb955fb..baca210ea8c 100644 --- a/pkg/services/sqlstore/permissions/dashboards_bench_test.go +++ b/pkg/services/sqlstore/permissions/dashboards_bench_test.go @@ -16,6 +16,7 @@ import ( "github.com/grafana/grafana/pkg/infra/tracing" "github.com/grafana/grafana/pkg/services/accesscontrol" "github.com/grafana/grafana/pkg/services/accesscontrol/mock" + "github.com/grafana/grafana/pkg/services/apiserver" "github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/dashboards/dashboardaccess" "github.com/grafana/grafana/pkg/services/dashboards/database" @@ -83,7 +84,7 @@ func setupBenchMark(b *testing.B, usr user.SignedInUser, features featuremgmt.Fe fStore := folderimpl.ProvideStore(store) folderSvc := folderimpl.ProvideService( fStore, mock.New(), bus.ProvideBus(tracing.InitializeTracerForTest()), dashboardWriteStore, folderimpl.ProvideDashboardFolderStore(store), - nil, store, features, supportbundlestest.NewFakeBundleService(), nil, cfg, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), sort.ProvideService()) + nil, store, features, supportbundlestest.NewFakeBundleService(), nil, cfg, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), sort.ProvideService(), apiserver.WithoutRestConfig) origNewGuardian := guardian.New guardian.MockDashboardGuardian(&guardian.FakeDashboardGuardian{CanViewValue: true, CanSaveValue: true}) diff --git a/pkg/storage/unified/federated/federatedtests/stats_test.go b/pkg/storage/unified/federated/federatedtests/stats_test.go index 3abb8464efa..5a8a6fd86e6 100644 --- a/pkg/storage/unified/federated/federatedtests/stats_test.go +++ b/pkg/storage/unified/federated/federatedtests/stats_test.go @@ -15,6 +15,7 @@ import ( "github.com/grafana/grafana/pkg/infra/db" "github.com/grafana/grafana/pkg/infra/tracing" "github.com/grafana/grafana/pkg/services/accesscontrol/actest" + "github.com/grafana/grafana/pkg/services/apiserver" "github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/dashboards/database" "github.com/grafana/grafana/pkg/services/featuremgmt" @@ -54,7 +55,7 @@ func TestDirectSQLStats(t *testing.T) { fStore := folderimpl.ProvideStore(db) folderSvc := folderimpl.ProvideService( fStore, actest.FakeAccessControl{ExpectedEvaluate: true}, bus.ProvideBus(tracing.InitializeTracerForTest()), dashStore, folderimpl.ProvideDashboardFolderStore(db), - nil, db, featuremgmt.WithFeatures(), supportbundlestest.NewFakeBundleService(), nil, cfg, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), sort.ProvideService()) + nil, db, featuremgmt.WithFeatures(), supportbundlestest.NewFakeBundleService(), nil, cfg, nil, tracing.InitializeTracerForTest(), nil, dualwrite.ProvideTestService(), sort.ProvideService(), apiserver.WithoutRestConfig) // create parent folder diff --git a/pkg/tests/apis/provisioning/helper_test.go b/pkg/tests/apis/provisioning/helper_test.go index 8100407fc29..aeeaa4550c1 100644 --- a/pkg/tests/apis/provisioning/helper_test.go +++ b/pkg/tests/apis/provisioning/helper_test.go @@ -28,7 +28,6 @@ import ( provisioning "github.com/grafana/grafana/pkg/apis/provisioning/v0alpha1" grafanarest "github.com/grafana/grafana/pkg/apiserver/rest" "github.com/grafana/grafana/pkg/registry/apis/provisioning/jobs" - "github.com/grafana/grafana/pkg/services/apiserver" "github.com/grafana/grafana/pkg/services/featuremgmt" "github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/tests/apis" @@ -189,8 +188,6 @@ func withLogs(opts *testinfra.GrafanaOpts) { } func runGrafana(t *testing.T, options ...grafanaOption) *provisioningTestHelper { - apiserver.ClearRestConfig() - provisioningPath := t.TempDir() opts := testinfra.GrafanaOpts{ AppModeProduction: false, // required for experimental APIs