Dashboard Provisioning: Dont wait on indexer when nothing deleted (#102390)
* adds debug log * show dashboard uids as strings * adds debug log * don't wait when no deleted dashboards * adds test
This commit is contained in:
@@ -565,6 +565,7 @@ func (dr *DashboardServiceImpl) ValidateDashboardBeforeSave(ctx context.Context,
|
||||
func (dr *DashboardServiceImpl) waitForSearchQuery(ctx context.Context, query *dashboards.FindPersistedDashboardsQuery, maxRetries int, expectedHits int64) error {
|
||||
return retryer.Retry(func() (retryer.RetrySignal, error) {
|
||||
results, err := dr.searchDashboardsThroughK8sRaw(ctx, query)
|
||||
dr.log.Debug("waitForSearchQuery", "dashboardUIDs", strings.Join(query.DashboardUIDs, ","), "total_hits", results.TotalHits, "err", err)
|
||||
if err != nil {
|
||||
return retryer.FuncError, err
|
||||
}
|
||||
@@ -594,6 +595,7 @@ func (dr *DashboardServiceImpl) DeleteOrphanedProvisionedDashboards(ctx context.
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dr.log.Debug("Found dashboards to be deleted", "orgId", org.ID, "count", len(foundDashs))
|
||||
|
||||
// delete them
|
||||
var deletedUids []string
|
||||
@@ -603,10 +605,12 @@ func (dr *DashboardServiceImpl) DeleteOrphanedProvisionedDashboards(ctx context.
|
||||
}
|
||||
deletedUids = append(deletedUids, foundDash.DashboardUID)
|
||||
}
|
||||
// wait for deleted dashboards to be removed from the index
|
||||
err = dr.waitForSearchQuery(ctx, &dashboards.FindPersistedDashboardsQuery{OrgId: org.ID, DashboardUIDs: deletedUids}, 5, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
if len(deletedUids) > 0 {
|
||||
// wait for deleted dashboards to be removed from the index
|
||||
err = dr.waitForSearchQuery(ctx, &dashboards.FindPersistedDashboardsQuery{OrgId: org.ID, DashboardUIDs: deletedUids}, 5, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -816,6 +816,7 @@ func TestDeleteOrphanedProvisionedDashboards(t *testing.T) {
|
||||
ExpectedOrgs: []*org.OrgDTO{{ID: 1}, {ID: 2}},
|
||||
},
|
||||
publicDashboardService: fakePublicDashboardService,
|
||||
log: log.NewNopLogger(),
|
||||
}
|
||||
|
||||
t.Run("Should fallback to dashboard store if Kubernetes feature flags are not enabled", func(t *testing.T) {
|
||||
@@ -969,6 +970,7 @@ func TestDeleteOrphanedProvisionedDashboards(t *testing.T) {
|
||||
ExpectedOrgs: []*org.OrgDTO{{ID: 1}},
|
||||
},
|
||||
publicDashboardService: fakePublicDashboardService,
|
||||
log: log.NewNopLogger(),
|
||||
}
|
||||
ctx, k8sCliMock := setupK8sDashboardTests(singleOrgService)
|
||||
provisioningTimestamp := int64(1234567)
|
||||
@@ -1055,6 +1057,37 @@ func TestDeleteOrphanedProvisionedDashboards(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
k8sCliMock.AssertExpectations(t)
|
||||
})
|
||||
|
||||
t.Run("Will not wait for indexer when no dashboards were deleted", func(t *testing.T) {
|
||||
repo := "test"
|
||||
singleOrgService := &DashboardServiceImpl{
|
||||
cfg: setting.NewCfg(),
|
||||
dashboardStore: &fakeStore,
|
||||
orgService: &orgtest.FakeOrgService{
|
||||
ExpectedOrgs: []*org.OrgDTO{{ID: 1}},
|
||||
},
|
||||
publicDashboardService: fakePublicDashboardService,
|
||||
log: log.NewNopLogger(),
|
||||
}
|
||||
ctx, k8sCliMock := setupK8sDashboardTests(singleOrgService)
|
||||
|
||||
// Call to searchProvisionedDashboardsThroughK8s()
|
||||
k8sCliMock.On("GetNamespace", mock.Anything, mock.Anything).Return("default")
|
||||
k8sCliMock.On("Search", mock.Anything, int64(1), mock.MatchedBy(func(req *resource.ResourceSearchRequest) bool {
|
||||
// make sure the kind is added to the query
|
||||
return req.Options.Fields[0].Values[0] == string(utils.ManagerKindClassicFP) && // nolint:staticcheck
|
||||
req.Options.Fields[1].Values[0] == repo
|
||||
})).Return(&resource.ResourceSearchResponse{
|
||||
Results: &resource.ResourceTable{},
|
||||
TotalHits: 0,
|
||||
}, nil)
|
||||
|
||||
err := singleOrgService.DeleteOrphanedProvisionedDashboards(ctx, &dashboards.DeleteOrphanedProvisionedDashboardsCommand{
|
||||
ReaderNames: []string{"test"},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
k8sCliMock.AssertExpectations(t)
|
||||
})
|
||||
}
|
||||
|
||||
func TestUnprovisionDashboard(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user