fix: update search request for existing provisioned dashboards in modes 3+ (#114412)
Fix search for existing provisioned dashboards in modes 3+ The search query was not requesting the dashboard's "legacy ID". As a result, the provisioning process would not find existing provisioned dashboards, making copies of these dashboards every time there was a change in the provisioned dashboard's definition.
This commit is contained in:
@@ -2009,7 +2009,14 @@ func (dr *DashboardServiceImpl) searchDashboardsThroughK8sRaw(ctx context.Contex
|
||||
request.Limit = query.Limit
|
||||
request.Page = query.Page
|
||||
request.Offset = (query.Page - 1) * query.Limit // only relevant when running in modes 3+
|
||||
request.Fields = dashboardsearch.IncludeFields
|
||||
request.Fields = append(
|
||||
dashboardsearch.IncludeFields,
|
||||
// Include the dashboard legacy ID in the results, as it is needed when
|
||||
// determining whether a provisioned dashboard exists or not, see
|
||||
// `(*DashboardServiceImpl).searchProvisionedDashboardsThroughK8s`.
|
||||
resource.SEARCH_FIELD_LEGACY_ID,
|
||||
resource.SEARCH_FIELD_LABELS+"."+resource.SEARCH_FIELD_LEGACY_ID,
|
||||
)
|
||||
|
||||
namespace := dr.k8sclient.GetNamespace(query.OrgId)
|
||||
var err error
|
||||
|
||||
@@ -2016,6 +2016,26 @@ func TestSearchDashboardsThroughK8sRaw(t *testing.T) {
|
||||
_, err := service.searchDashboardsThroughK8s(ctx, query)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
t.Run("search will request legacy dashboard ID", func(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
k8sCliMock := new(client.MockK8sHandler)
|
||||
service := &DashboardServiceImpl{k8sclient: k8sCliMock}
|
||||
query := &dashboards.FindPersistedDashboardsQuery{
|
||||
ManagedBy: utils.ManagerKindClassicFP, //nolint:staticcheck
|
||||
OrgId: 1,
|
||||
}
|
||||
k8sCliMock.On("GetNamespace", mock.Anything, mock.Anything).Return("default")
|
||||
k8sCliMock.On("Search", mock.Anything, mock.Anything, mock.MatchedBy(func(req *resourcepb.ResourceSearchRequest) bool {
|
||||
return slices.Contains(req.Fields, "grafana.app/deprecatedInternalID") &&
|
||||
slices.Contains(req.Fields, "labels.grafana.app/deprecatedInternalID")
|
||||
})).Return(&resourcepb.ResourceSearchResponse{
|
||||
Results: &resourcepb.ResourceTable{},
|
||||
TotalHits: 0,
|
||||
}, nil)
|
||||
_, err := service.searchDashboardsThroughK8s(ctx, query)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
}
|
||||
|
||||
func TestSearchProvisionedDashboardsThroughK8sRaw(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user