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

pull/77547/head
Andres Martinez Gotor 2 years ago committed by GitHub
parent b13395afbc
commit 82a7e1229a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      docs/sources/administration/provisioning/index.md
  2. 6
      pkg/services/provisioning/datasources/datasources.go
  3. 1
      pkg/services/provisioning/datasources/types.go
  4. 8
      pkg/services/provisioning/datasources/types_test.go

@ -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.

@ -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
}
}
}
}

@ -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,

@ -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)
})
}

Loading…
Cancel
Save