Provisioning: Allow startup when there are dashboard provisioning failures (#92201)

* Stop returning an error if dashboard provisioning fails
* Test that Run() does not error when dashboard provisioning fails
This commit is contained in:
Arati R.
2024-08-23 11:48:42 +02:00
committed by GitHub
parent 4a124469fa
commit 927ce6c700
2 changed files with 28 additions and 1 deletions
+2 -1
View File
@@ -122,6 +122,7 @@ func newProvisioningServiceImpl(
newDashboardProvisioner dashboards.DashboardProvisionerFactory,
provisionDatasources func(context.Context, string, datasources.BaseDataSourceService, datasources.CorrelationsStore, org.Service) error,
provisionPlugins func(context.Context, string, pluginstore.Store, pluginsettings.Service, org.Service) error,
searchService searchV2.SearchService,
) *ProvisioningServiceImpl {
return &ProvisioningServiceImpl{
log: log.New("provisioning"),
@@ -129,6 +130,7 @@ func newProvisioningServiceImpl(
provisionDatasources: provisionDatasources,
provisionPlugins: provisionPlugins,
Cfg: setting.NewCfg(),
searchService: searchService,
}
}
@@ -185,7 +187,6 @@ func (ps *ProvisioningServiceImpl) Run(ctx context.Context) error {
err := ps.ProvisionDashboards(ctx)
if err != nil {
ps.log.Error("Failed to provision dashboard", "error", err)
return err
}
if ps.dashboardProvisioner.HasDashboardSources() {
ps.searchService.TriggerReIndex()
@@ -3,6 +3,7 @@ package provisioning
import (
"context"
"errors"
"fmt"
"testing"
"time"
@@ -14,6 +15,7 @@ import (
"github.com/grafana/grafana/pkg/services/org"
"github.com/grafana/grafana/pkg/services/provisioning/dashboards"
"github.com/grafana/grafana/pkg/services/provisioning/utils"
"github.com/grafana/grafana/pkg/services/searchV2"
)
func TestProvisioningServiceImpl(t *testing.T) {
@@ -66,6 +68,27 @@ func TestProvisioningServiceImpl(t *testing.T) {
// Cancelling the root context and stopping the service
serviceTest.cancel()
})
t.Run("Should not return run error when dashboard provisioning fails", func(t *testing.T) {
serviceTest := setup(t)
provisioningErr := errors.New("Test error")
serviceTest.mock.ProvisionFunc = func(ctx context.Context) error {
return provisioningErr
}
err := serviceTest.service.ProvisionDashboards(context.Background())
assert.NotNil(t, err)
serviceTest.startService()
serviceTest.waitForPollChanges()
assert.Equal(t, 1, len(serviceTest.mock.Calls.PollChanges), "PollChanges should have been called")
// Cancelling the root context and stopping the service
serviceTest.cancel()
serviceTest.waitForStop()
fmt.Println("serviceTest.serviceError", serviceTest.serviceError)
assert.Equal(t, context.Canceled, serviceTest.serviceError)
})
}
type serviceTestStruct struct {
@@ -95,12 +118,15 @@ func setup(t *testing.T) *serviceTestStruct {
pollChangesChannel <- ctx
}
searchStub := searchV2.NewStubSearchService()
serviceTest.service = newProvisioningServiceImpl(
func(context.Context, string, dashboardstore.DashboardProvisioningService, org.Service, utils.DashboardStore, folder.Service) (dashboards.DashboardProvisioner, error) {
return serviceTest.mock, nil
},
nil,
nil,
searchStub,
)
err := serviceTest.service.setDashboardProvisioner()
require.NoError(t, err)