Dashboard Provisioning: Fix re-provisioning on each run (#105979)
Dashboard Provisioning: Fix reprovisioning on startup
This commit is contained in:
@@ -101,7 +101,7 @@ func (fr *FileReader) walkDisk(ctx context.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
provisionedDashboardRefs, err := getProvisionedDashboardsByPath(ctx, fr.dashboardProvisioningService, fr.Cfg.Name)
|
||||
provisionedDashboardRefs, err := fr.getProvisionedDashboardsByPath(ctx, fr.dashboardProvisioningService, fr.Cfg.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -326,7 +326,7 @@ func (fr *FileReader) saveDashboard(ctx context.Context, path string, folderID i
|
||||
return provisioningMetadata, nil
|
||||
}
|
||||
|
||||
func getProvisionedDashboardsByPath(ctx context.Context, service dashboards.DashboardProvisioningService, name string) (
|
||||
func (fr *FileReader) getProvisionedDashboardsByPath(ctx context.Context, service dashboards.DashboardProvisioningService, name string) (
|
||||
map[string]*dashboards.DashboardProvisioning, error) {
|
||||
arr, err := service.GetProvisionedDashboardData(ctx, name)
|
||||
if err != nil {
|
||||
@@ -335,6 +335,13 @@ func getProvisionedDashboardsByPath(ctx context.Context, service dashboards.Dash
|
||||
|
||||
byPath := map[string]*dashboards.DashboardProvisioning{}
|
||||
for _, pd := range arr {
|
||||
// as a part of the migration of dashboards to unified storage, the dashboard provisiong data will be stored as
|
||||
// an annotation on the dashboard. in modes 0-2, that will only return the relative path. however, we will be comparing
|
||||
// that to the data stored in the dashboard_provisioning table, so we need to change it into the resolved path
|
||||
if !strings.HasPrefix(pd.ExternalID, fr.resolvedPath()) {
|
||||
pd.ExternalID = fr.resolvedPath() + "/" + pd.ExternalID
|
||||
}
|
||||
|
||||
byPath[pd.ExternalID] = pd
|
||||
}
|
||||
|
||||
|
||||
@@ -456,6 +456,27 @@ func TestDashboardFileReader(t *testing.T) {
|
||||
})
|
||||
})
|
||||
|
||||
t.Run("Should resolve relative ExternalID paths to absolute paths", func(t *testing.T) {
|
||||
setup()
|
||||
cfg.Options["path"] = defaultDashboards
|
||||
provisionedDashboard := []*dashboards.DashboardProvisioning{
|
||||
{
|
||||
Name: configName,
|
||||
ExternalID: "dashboard1.json",
|
||||
},
|
||||
}
|
||||
|
||||
fakeService.On("GetProvisionedDashboardData", mock.Anything, configName).Return(provisionedDashboard, nil).Once()
|
||||
reader, err := NewDashboardFileReader(cfg, logger, nil, fakeStore, folderSvc)
|
||||
reader.dashboardProvisioningService = fakeService
|
||||
require.NoError(t, err)
|
||||
resolvedPath := reader.resolvedPath()
|
||||
dashboards, err := reader.getProvisionedDashboardsByPath(context.Background(), fakeService, configName)
|
||||
require.NoError(t, err)
|
||||
expectedPath := filepath.Join(resolvedPath, "dashboard1.json")
|
||||
require.Equal(t, expectedPath, dashboards[expectedPath].ExternalID)
|
||||
})
|
||||
|
||||
t.Run("Given missing dashboard file", func(t *testing.T) {
|
||||
absPath1, err := filepath.Abs(unprovision + "/dashboard1.json")
|
||||
require.NoError(t, err)
|
||||
|
||||
Reference in New Issue
Block a user