Skip to content

Commit 927ce6c

Browse files
authored
Provisioning: Allow startup when there are dashboard provisioning failures (grafana#92201)
* Stop returning an error if dashboard provisioning fails * Test that Run() does not error when dashboard provisioning fails
1 parent 4a12446 commit 927ce6c

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

pkg/services/provisioning/provisioning.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,15 @@ func newProvisioningServiceImpl(
122122
newDashboardProvisioner dashboards.DashboardProvisionerFactory,
123123
provisionDatasources func(context.Context, string, datasources.BaseDataSourceService, datasources.CorrelationsStore, org.Service) error,
124124
provisionPlugins func(context.Context, string, pluginstore.Store, pluginsettings.Service, org.Service) error,
125+
searchService searchV2.SearchService,
125126
) *ProvisioningServiceImpl {
126127
return &ProvisioningServiceImpl{
127128
log: log.New("provisioning"),
128129
newDashboardProvisioner: newDashboardProvisioner,
129130
provisionDatasources: provisionDatasources,
130131
provisionPlugins: provisionPlugins,
131132
Cfg: setting.NewCfg(),
133+
searchService: searchService,
132134
}
133135
}
134136

@@ -185,7 +187,6 @@ func (ps *ProvisioningServiceImpl) Run(ctx context.Context) error {
185187
err := ps.ProvisionDashboards(ctx)
186188
if err != nil {
187189
ps.log.Error("Failed to provision dashboard", "error", err)
188-
return err
189190
}
190191
if ps.dashboardProvisioner.HasDashboardSources() {
191192
ps.searchService.TriggerReIndex()

pkg/services/provisioning/provisioning_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package provisioning
33
import (
44
"context"
55
"errors"
6+
"fmt"
67
"testing"
78
"time"
89

@@ -14,6 +15,7 @@ import (
1415
"github.com/grafana/grafana/pkg/services/org"
1516
"github.com/grafana/grafana/pkg/services/provisioning/dashboards"
1617
"github.com/grafana/grafana/pkg/services/provisioning/utils"
18+
"github.com/grafana/grafana/pkg/services/searchV2"
1719
)
1820

1921
func TestProvisioningServiceImpl(t *testing.T) {
@@ -66,6 +68,27 @@ func TestProvisioningServiceImpl(t *testing.T) {
6668
// Cancelling the root context and stopping the service
6769
serviceTest.cancel()
6870
})
71+
72+
t.Run("Should not return run error when dashboard provisioning fails", func(t *testing.T) {
73+
serviceTest := setup(t)
74+
provisioningErr := errors.New("Test error")
75+
serviceTest.mock.ProvisionFunc = func(ctx context.Context) error {
76+
return provisioningErr
77+
}
78+
err := serviceTest.service.ProvisionDashboards(context.Background())
79+
assert.NotNil(t, err)
80+
serviceTest.startService()
81+
82+
serviceTest.waitForPollChanges()
83+
assert.Equal(t, 1, len(serviceTest.mock.Calls.PollChanges), "PollChanges should have been called")
84+
85+
// Cancelling the root context and stopping the service
86+
serviceTest.cancel()
87+
serviceTest.waitForStop()
88+
89+
fmt.Println("serviceTest.serviceError", serviceTest.serviceError)
90+
assert.Equal(t, context.Canceled, serviceTest.serviceError)
91+
})
6992
}
7093

7194
type serviceTestStruct struct {
@@ -95,12 +118,15 @@ func setup(t *testing.T) *serviceTestStruct {
95118
pollChangesChannel <- ctx
96119
}
97120

121+
searchStub := searchV2.NewStubSearchService()
122+
98123
serviceTest.service = newProvisioningServiceImpl(
99124
func(context.Context, string, dashboardstore.DashboardProvisioningService, org.Service, utils.DashboardStore, folder.Service) (dashboards.DashboardProvisioner, error) {
100125
return serviceTest.mock, nil
101126
},
102127
nil,
103128
nil,
129+
searchStub,
104130
)
105131
err := serviceTest.service.setDashboardProvisioner()
106132
require.NoError(t, err)

0 commit comments

Comments
 (0)