Provisioning: Ensure that enterprise provisioning runs [10.1.x] (#76686)
revert https://github.com/grafana/grafana/pull/72608 (cherry picked from commit bb3e422365d95aa44a468bc71adfffa423bec65e)
This commit is contained in:
@@ -11,18 +11,14 @@ const (
|
||||
GrafanaAPIServer string = "grafana-apiserver"
|
||||
// HTTPServer is the HTTP server for Grafana
|
||||
HTTPServer string = "http-server"
|
||||
// Provisioning sets up Grafana with preconfigured datasources, dashboards, etc.
|
||||
Provisioning string = "provisioning"
|
||||
// SecretMigrator handles legacy secrets migrations
|
||||
SecretMigrator string = "secret-migrator"
|
||||
)
|
||||
|
||||
// dependencyMap defines Module Targets => Dependencies
|
||||
var dependencyMap = map[string][]string{
|
||||
BackgroundServices: {Provisioning, HTTPServer},
|
||||
BackgroundServices: {HTTPServer},
|
||||
CertGenerator: {},
|
||||
GrafanaAPIServer: {CertGenerator},
|
||||
Provisioning: {SecretMigrator},
|
||||
|
||||
All: {BackgroundServices},
|
||||
All: {BackgroundServices},
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/modules"
|
||||
"github.com/grafana/grafana/pkg/server/backgroundsvcs"
|
||||
grafanaapiserver "github.com/grafana/grafana/pkg/services/grafana-apiserver"
|
||||
"github.com/grafana/grafana/pkg/services/provisioning"
|
||||
"github.com/grafana/grafana/pkg/services/secrets/kvstore/migrations"
|
||||
)
|
||||
|
||||
@@ -26,7 +25,6 @@ func ProvideRegistry(
|
||||
backgroundServiceRunner *backgroundsvcs.BackgroundServiceRunner,
|
||||
certGenerator certgenerator.ServiceInterface,
|
||||
httpServer *api.HTTPServer,
|
||||
provisioningService *provisioning.ProvisioningServiceImpl,
|
||||
secretsMigrator *migrations.SecretMigrationProviderImpl,
|
||||
) *registry {
|
||||
return newRegistry(
|
||||
@@ -36,7 +34,6 @@ func ProvideRegistry(
|
||||
backgroundServiceRunner,
|
||||
certGenerator,
|
||||
httpServer,
|
||||
provisioningService,
|
||||
secretsMigrator,
|
||||
)
|
||||
}
|
||||
|
||||
+24
-17
@@ -19,6 +19,7 @@ import (
|
||||
moduleRegistry "github.com/grafana/grafana/pkg/modules/registry"
|
||||
"github.com/grafana/grafana/pkg/registry"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
"github.com/grafana/grafana/pkg/services/provisioning"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
)
|
||||
|
||||
@@ -33,13 +34,13 @@ type Options struct {
|
||||
}
|
||||
|
||||
// New returns a new instance of Server.
|
||||
func New(opts Options, cfg *setting.Cfg, httpServer *api.HTTPServer, roleRegistry accesscontrol.RoleRegistry,
|
||||
func New(opts Options, cfg *setting.Cfg, httpServer *api.HTTPServer, roleRegistry accesscontrol.RoleRegistry, provisioningService provisioning.ProvisioningService,
|
||||
usageStatsProvidersRegistry registry.UsageStatsProvidersRegistry, statsCollectorService *statscollector.Service,
|
||||
moduleService modules.Engine,
|
||||
_ moduleRegistry.Registry, // imported to invoke initialization via Wire
|
||||
) (*Server, error) {
|
||||
statsCollectorService.RegisterProviders(usageStatsProvidersRegistry.GetServices())
|
||||
s, err := newServer(opts, cfg, httpServer, roleRegistry, moduleService)
|
||||
s, err := newServer(opts, cfg, httpServer, roleRegistry, provisioningService, moduleService)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -52,18 +53,19 @@ func New(opts Options, cfg *setting.Cfg, httpServer *api.HTTPServer, roleRegistr
|
||||
}
|
||||
|
||||
func newServer(opts Options, cfg *setting.Cfg, httpServer *api.HTTPServer, roleRegistry accesscontrol.RoleRegistry,
|
||||
moduleService modules.Engine) (*Server, error) {
|
||||
provisioningService provisioning.ProvisioningService, moduleService modules.Engine) (*Server, error) {
|
||||
return &Server{
|
||||
HTTPServer: httpServer,
|
||||
roleRegistry: roleRegistry,
|
||||
shutdownFinished: make(chan struct{}),
|
||||
log: log.New("server"),
|
||||
cfg: cfg,
|
||||
pidFile: opts.PidFile,
|
||||
version: opts.Version,
|
||||
commit: opts.Commit,
|
||||
buildBranch: opts.BuildBranch,
|
||||
moduleService: moduleService,
|
||||
HTTPServer: httpServer,
|
||||
provisioningService: provisioningService,
|
||||
roleRegistry: roleRegistry,
|
||||
shutdownFinished: make(chan struct{}),
|
||||
log: log.New("server"),
|
||||
cfg: cfg,
|
||||
pidFile: opts.PidFile,
|
||||
version: opts.Version,
|
||||
commit: opts.Commit,
|
||||
buildBranch: opts.BuildBranch,
|
||||
moduleService: moduleService,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -81,9 +83,10 @@ type Server struct {
|
||||
commit string
|
||||
buildBranch string
|
||||
|
||||
HTTPServer *api.HTTPServer
|
||||
roleRegistry accesscontrol.RoleRegistry
|
||||
moduleService modules.Engine
|
||||
HTTPServer *api.HTTPServer
|
||||
roleRegistry accesscontrol.RoleRegistry
|
||||
provisioningService provisioning.ProvisioningService
|
||||
moduleService modules.Engine
|
||||
}
|
||||
|
||||
// init initializes the server and its services.
|
||||
@@ -109,7 +112,11 @@ func (s *Server) init(ctx context.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
return s.roleRegistry.RegisterFixedRoles(ctx)
|
||||
if err := s.roleRegistry.RegisterFixedRoles(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return s.provisioningService.RunInitProvisioners(ctx)
|
||||
}
|
||||
|
||||
// AwaitHealthy waits for the server to become healthy.
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
|
||||
func testServer(t *testing.T, m *modules.MockModuleEngine) *Server {
|
||||
t.Helper()
|
||||
s, err := newServer(Options{}, setting.NewCfg(), nil, &acimpl.Service{}, m)
|
||||
s, err := newServer(Options{}, setting.NewCfg(), nil, &acimpl.Service{}, nil, m)
|
||||
require.NoError(t, err)
|
||||
// Required to skip configuration initialization that causes
|
||||
// DI errors in this test.
|
||||
|
||||
@@ -6,12 +6,10 @@ import (
|
||||
"path/filepath"
|
||||
"sync"
|
||||
|
||||
"github.com/grafana/dskit/services"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/modules"
|
||||
plugifaces "github.com/grafana/grafana/pkg/plugins"
|
||||
"github.com/grafana/grafana/pkg/registry"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
"github.com/grafana/grafana/pkg/services/alerting"
|
||||
"github.com/grafana/grafana/pkg/services/correlations"
|
||||
@@ -79,13 +77,11 @@ func ProvideService(
|
||||
orgService: orgService,
|
||||
}
|
||||
|
||||
ps.BasicService = services.NewBasicService(ps.RunInitProvisioners, ps.Run, nil).WithName(modules.Provisioning)
|
||||
|
||||
return ps, nil
|
||||
}
|
||||
|
||||
type ProvisioningService interface {
|
||||
services.NamedService
|
||||
registry.BackgroundService
|
||||
ProvisionDatasources(ctx context.Context) error
|
||||
ProvisionPlugins(ctx context.Context) error
|
||||
ProvisionNotifications(ctx context.Context) error
|
||||
@@ -106,7 +102,6 @@ func NewProvisioningServiceImpl() *ProvisioningServiceImpl {
|
||||
provisionDatasources: datasources.Provision,
|
||||
provisionPlugins: plugins.Provision,
|
||||
}
|
||||
ps.BasicService = services.NewBasicService(ps.RunInitProvisioners, ps.Run, nil).WithName(modules.Provisioning)
|
||||
return ps
|
||||
}
|
||||
|
||||
@@ -124,13 +119,10 @@ func newProvisioningServiceImpl(
|
||||
provisionDatasources: provisionDatasources,
|
||||
provisionPlugins: provisionPlugins,
|
||||
}
|
||||
ps.BasicService = services.NewBasicService(ps.RunInitProvisioners, ps.Run, nil).WithName(modules.Provisioning)
|
||||
return ps
|
||||
}
|
||||
|
||||
type ProvisioningServiceImpl struct {
|
||||
*services.BasicService
|
||||
|
||||
Cfg *setting.Cfg
|
||||
SQLStore db.DB
|
||||
orgService org.Service
|
||||
@@ -208,10 +200,8 @@ func (ps *ProvisioningServiceImpl) Run(ctx context.Context) error {
|
||||
continue
|
||||
case <-ctx.Done():
|
||||
// Root server context was cancelled so cancel polling and leave.
|
||||
ps.mutex.Lock()
|
||||
ps.cancelPolling()
|
||||
ps.mutex.Unlock()
|
||||
return nil
|
||||
return ctx.Err()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,6 @@ package provisioning
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/grafana/dskit/services"
|
||||
|
||||
"github.com/grafana/grafana/pkg/modules"
|
||||
)
|
||||
|
||||
type Calls struct {
|
||||
@@ -21,7 +17,6 @@ type Calls struct {
|
||||
}
|
||||
|
||||
type ProvisioningServiceMock struct {
|
||||
*services.BasicService
|
||||
Calls *Calls
|
||||
RunInitProvisionersFunc func(ctx context.Context) error
|
||||
ProvisionDatasourcesFunc func(ctx context.Context) error
|
||||
@@ -37,7 +32,6 @@ func NewProvisioningServiceMock(ctx context.Context) *ProvisioningServiceMock {
|
||||
s := &ProvisioningServiceMock{
|
||||
Calls: &Calls{},
|
||||
}
|
||||
s.BasicService = services.NewBasicService(s.RunInitProvisioners, s.Run, nil).WithName(modules.Provisioning)
|
||||
return s
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ func TestProvisioningServiceImpl(t *testing.T) {
|
||||
serviceTest.waitForStop()
|
||||
|
||||
assert.False(t, serviceTest.serviceRunning, "Service should not be running")
|
||||
assert.Nil(t, serviceTest.serviceError, "Service should not return canceled error")
|
||||
assert.Equal(t, context.Canceled, serviceTest.serviceError, "Service should have returned canceled error")
|
||||
})
|
||||
|
||||
t.Run("Failed reloading does not stop polling with old provisioned", func(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user