* chore: uncomment unified migration * chore: adapt and fix tests * chore: dynamically bump max conns if needed during migration * chore: copilot suggestions * chore: pass ctx in RegisterMigration * chore: make playlists opt-out and dashboards opt-in * chore: adjust dashboard test * chore: disable enable log in test * chore: address review comments - do not use pointer config - add migration registry * chore: more consistent naming * chore: fix playlist discovery test
100 lines
3.1 KiB
Go
100 lines
3.1 KiB
Go
package setting
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/grafana/grafana/pkg/apiserver/rest"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestCfg_setUnifiedStorageConfig(t *testing.T) {
|
|
t.Run("read unified_storage configs", func(t *testing.T) {
|
|
cfg := NewCfg()
|
|
err := cfg.Load(CommandLineArgs{HomePath: "../../", Config: "../../conf/defaults.ini"})
|
|
assert.NoError(t, err)
|
|
|
|
setSectionKey := func(sectionName, key, value string) {
|
|
section := cfg.Raw.Section(sectionName) // Gets existing or creates new
|
|
_, err := section.NewKey(key, value)
|
|
assert.NoError(t, err)
|
|
}
|
|
|
|
setMigratedResourceKey := func(key, value string) {
|
|
for migratedResource := range MigratedUnifiedResources {
|
|
setSectionKey("unified_storage."+migratedResource, key, value)
|
|
}
|
|
}
|
|
|
|
validateMigratedResources := func(optIn bool) {
|
|
for migratedResource, enabled := range MigratedUnifiedResources {
|
|
resourceCfg, exists := cfg.UnifiedStorage[migratedResource]
|
|
|
|
isEnabled := enabled
|
|
if optIn {
|
|
isEnabled = true
|
|
}
|
|
|
|
if !isEnabled {
|
|
if exists {
|
|
assert.Equal(t, rest.DualWriterMode(1), resourceCfg.DualWriterMode, migratedResource)
|
|
}
|
|
continue
|
|
}
|
|
assert.Equal(t, exists, true, migratedResource)
|
|
|
|
assert.Equal(t, UnifiedStorageConfig{
|
|
DualWriterMode: 5,
|
|
DualWriterMigrationDataSyncDisabled: true,
|
|
EnableMigration: isEnabled,
|
|
}, resourceCfg, migratedResource)
|
|
}
|
|
}
|
|
|
|
setMigratedResourceKey("dualWriterMode", "1") // migrated resources enabled by default will change to 5 in setUnifiedStorageConfig
|
|
|
|
setSectionKey("unified_storage.resource.not_migrated.grafana.app", "dualWriterMode", "2")
|
|
setSectionKey("unified_storage.resource.not_migrated.grafana.app", "dualWriterPeriodicDataSyncJobEnabled", "true")
|
|
setSectionKey("unified_storage.resource.not_migrated.grafana.app", "dataSyncerRecordsLimit", "1001")
|
|
setSectionKey("unified_storage.resource.not_migrated.grafana.app", "dataSyncerInterval", "10m")
|
|
|
|
// Add unified_storage section for index settings
|
|
setSectionKey("unified_storage", "index_min_count", "5")
|
|
|
|
cfg.setUnifiedStorageConfig()
|
|
|
|
value, exists := cfg.UnifiedStorage["resource.not_migrated.grafana.app"]
|
|
|
|
assert.Equal(t, exists, true)
|
|
assert.Equal(t, value, UnifiedStorageConfig{
|
|
DualWriterMode: 2,
|
|
DualWriterPeriodicDataSyncJobEnabled: true,
|
|
DataSyncerRecordsLimit: 1001,
|
|
DataSyncerInterval: time.Minute * 10,
|
|
})
|
|
|
|
validateMigratedResources(false)
|
|
|
|
setMigratedResourceKey("enableMigration", "true") // will be changed to 5 in setUnifiedStorageConfig
|
|
|
|
cfg.setUnifiedStorageConfig()
|
|
|
|
validateMigratedResources(true)
|
|
|
|
// Test that index settings are correctly parsed
|
|
assert.Equal(t, 5, cfg.IndexMinCount)
|
|
})
|
|
|
|
t.Run("read unified_storage configs with defaults", func(t *testing.T) {
|
|
cfg := NewCfg()
|
|
err := cfg.Load(CommandLineArgs{HomePath: "../../", Config: "../../conf/defaults.ini"})
|
|
assert.NoError(t, err)
|
|
|
|
// Don't add any custom index settings, test defaults
|
|
cfg.setUnifiedStorageConfig()
|
|
|
|
// Test that default index settings are applied
|
|
assert.Equal(t, 1, cfg.IndexMinCount)
|
|
})
|
|
}
|