Provisioning: Fix admin reloading of dashboard configuration (#92462)
* Set dashboard provisioner before provisioning dashboards * Test provisioner instantiation during dashboard provisioning
This commit is contained in:
@@ -235,13 +235,18 @@ func (ps *ProvisioningServiceImpl) ProvisionPlugins(ctx context.Context) error {
|
||||
}
|
||||
|
||||
func (ps *ProvisioningServiceImpl) ProvisionDashboards(ctx context.Context) error {
|
||||
err := ps.setDashboardProvisioner()
|
||||
if err != nil {
|
||||
return fmt.Errorf("%v: %w", "Failed to create provisioner", err)
|
||||
}
|
||||
|
||||
ps.mutex.Lock()
|
||||
defer ps.mutex.Unlock()
|
||||
|
||||
ps.cancelPolling()
|
||||
ps.dashboardProvisioner.CleanUpOrphanedDashboards(ctx)
|
||||
|
||||
err := ps.dashboardProvisioner.Provision(ctx)
|
||||
err = ps.dashboardProvisioner.Provision(ctx)
|
||||
if err != nil {
|
||||
// If we fail to provision with the new provisioner, the mutex will unlock and the polling will restart with the
|
||||
// old provisioner as we did not switch them yet.
|
||||
|
||||
@@ -108,6 +108,19 @@ func TestProvisioningServiceImpl(t *testing.T) {
|
||||
|
||||
assert.True(t, errors.Is(serviceTest.serviceError, provisioningErr))
|
||||
})
|
||||
t.Run("Should set dashboard provisioner when provisioning dashboards", func(t *testing.T) {
|
||||
// The first dashboard provisioner instantiation takes place when
|
||||
// setDashboardProvisioner() is called in setup(t).
|
||||
serviceTest := setup(t)
|
||||
// The second dashboard provisioner instantiation takes place when
|
||||
// Run(ctx) is executed.
|
||||
serviceTest.startService()
|
||||
|
||||
serviceTest.cancel()
|
||||
serviceTest.waitForStop()
|
||||
|
||||
assert.Equal(t, 2, serviceTest.dashboardProvisionerInstantiations)
|
||||
})
|
||||
}
|
||||
|
||||
type serviceTestStruct struct {
|
||||
@@ -121,6 +134,8 @@ type serviceTestStruct struct {
|
||||
startService func()
|
||||
cancel func()
|
||||
|
||||
dashboardProvisionerInstantiations int
|
||||
|
||||
mock *dashboards.ProvisionerMock
|
||||
service *ProvisioningServiceImpl
|
||||
}
|
||||
@@ -141,6 +156,7 @@ func setup(t *testing.T) *serviceTestStruct {
|
||||
|
||||
service, err := newProvisioningServiceImpl(
|
||||
func(context.Context, string, dashboardstore.DashboardProvisioningService, org.Service, utils.DashboardStore, folder.Service) (dashboards.DashboardProvisioner, error) {
|
||||
serviceTest.dashboardProvisionerInstantiations++
|
||||
return serviceTest.mock, nil
|
||||
},
|
||||
nil,
|
||||
|
||||
Reference in New Issue
Block a user