mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Bug Fix: Respect data source version when provisioning (#77428)
This commit is contained in:
parent
b13395afbc
commit
82a7e1229a
@ -157,6 +157,8 @@ datasources:
|
|||||||
password:
|
password:
|
||||||
# <string> Sets the basic authorization password.
|
# <string> Sets the basic authorization password.
|
||||||
basicAuthPassword:
|
basicAuthPassword:
|
||||||
|
# <int> Sets the version. Used to compare versions when
|
||||||
|
# updating. Ignored when creating a new data source.
|
||||||
version: 1
|
version: 1
|
||||||
# <bool> Allows users to edit data sources from the
|
# <bool> Allows users to edit data sources from the
|
||||||
# Grafana UI.
|
# Grafana UI.
|
||||||
|
@ -80,10 +80,14 @@ func (dc *DatasourceProvisioner) provisionDataSources(ctx context.Context, cfg *
|
|||||||
updateCmd := createUpdateCommand(ds, dataSource.ID)
|
updateCmd := createUpdateCommand(ds, dataSource.ID)
|
||||||
dc.log.Debug("updating datasource from configuration", "name", updateCmd.Name, "uid", updateCmd.UID)
|
dc.log.Debug("updating datasource from configuration", "name", updateCmd.Name, "uid", updateCmd.UID)
|
||||||
if _, err := dc.store.UpdateDataSource(ctx, updateCmd); err != nil {
|
if _, err := dc.store.UpdateDataSource(ctx, updateCmd); err != nil {
|
||||||
|
if errors.Is(err, datasources.ErrDataSourceUpdatingOldVersion) {
|
||||||
|
dc.log.Debug("ignoring old version of datasource", "name", updateCmd.Name, "uid", updateCmd.UID)
|
||||||
|
} else {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -243,6 +243,7 @@ func createUpdateCommand(ds *upsertDataSourceFromConfig, id int64) *datasources.
|
|||||||
|
|
||||||
return &datasources.UpdateDataSourceCommand{
|
return &datasources.UpdateDataSourceCommand{
|
||||||
ID: id,
|
ID: id,
|
||||||
|
Version: ds.Version,
|
||||||
UID: ds.UID,
|
UID: ds.UID,
|
||||||
OrgID: ds.OrgID,
|
OrgID: ds.OrgID,
|
||||||
Name: ds.Name,
|
Name: ds.Name,
|
||||||
|
@ -13,3 +13,11 @@ func TestUIDFromNames(t *testing.T) {
|
|||||||
require.Equal(t, safeUIDFromName("AAA"), "PCB1AD2119D8FAFB6")
|
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)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user