Bug Fix: Respect data source version when provisioning (#77428)

This commit is contained in:
Andres Martinez Gotor 2023-11-02 11:27:17 +01:00 committed by GitHub
parent b13395afbc
commit 82a7e1229a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 1 deletions

View File

@ -157,6 +157,8 @@ datasources:
password:
# <string> Sets the basic authorization password.
basicAuthPassword:
# <int> Sets the version. Used to compare versions when
# updating. Ignored when creating a new data source.
version: 1
# <bool> Allows users to edit data sources from the
# Grafana UI.

View File

@ -80,7 +80,11 @@ func (dc *DatasourceProvisioner) provisionDataSources(ctx context.Context, cfg *
updateCmd := createUpdateCommand(ds, dataSource.ID)
dc.log.Debug("updating datasource from configuration", "name", updateCmd.Name, "uid", updateCmd.UID)
if _, err := dc.store.UpdateDataSource(ctx, updateCmd); err != nil {
return err
if errors.Is(err, datasources.ErrDataSourceUpdatingOldVersion) {
dc.log.Debug("ignoring old version of datasource", "name", updateCmd.Name, "uid", updateCmd.UID)
} else {
return err
}
}
}
}

View File

@ -243,6 +243,7 @@ func createUpdateCommand(ds *upsertDataSourceFromConfig, id int64) *datasources.
return &datasources.UpdateDataSourceCommand{
ID: id,
Version: ds.Version,
UID: ds.UID,
OrgID: ds.OrgID,
Name: ds.Name,

View File

@ -13,3 +13,11 @@ func TestUIDFromNames(t *testing.T) {
require.Equal(t, safeUIDFromName("AAA"), "PCB1AD2119D8FAFB6")
})
}
func TestCreateUpdateCommand(t *testing.T) {
t.Run("includes the version in the command", func(t *testing.T) {
ds := &upsertDataSourceFromConfig{OrgID: 1, Version: 1, Name: "test"}
cmd := createUpdateCommand(ds, 1)
require.Equal(t, 1, cmd.Version)
})
}