mirror of https://github.com/grafana/grafana
Use dw dynamic config (#91882)
* Remove kubernetesPlaylists feature_toggle * Remove unified_storage_mode * Remove double import * Read from config instead from feature_toggle * cover scenario for when unified storage is not defined * Be temporarily retro compatible with previous feature toggle * Properly read unified_storage section * [WIP] Read new format of config * Fix test * Fix other tests * Generate feature flags file * Use <group>.<resource> schema * Use <group>.resource format on the FE as well * Hide UniStore config from Frontend Signed-off-by: Maicon Costa <maiconscosta@gmail.com> * unwanted changes * Use feature toggles in the FE. Enforce FTs are present before enabling dual writing Co-authored-by: Ryan McKinley <ryantxu@users.noreply.github.com> * use kubernetes playlists feature toggle on the FE * Remove unwanted code * Remove configs from the FE * Remove commented code * Add more explicit example --------- Signed-off-by: Maicon Costa <maiconscosta@gmail.com> Co-authored-by: Maicon Costa <maiconscosta@gmail.com>pull/92744/head
parent
f8765087b5
commit
2e451b2ed7
@ -0,0 +1,64 @@ |
||||
package options |
||||
|
||||
import ( |
||||
"testing" |
||||
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt" |
||||
"github.com/grafana/grafana/pkg/setting" |
||||
"github.com/stretchr/testify/assert" |
||||
) |
||||
|
||||
func TestStorageOptions_CheckFeatureToggle(t *testing.T) { |
||||
tests := []struct { |
||||
name string |
||||
StorageType StorageType |
||||
UnifiedStorageConfig map[string]setting.UnifiedStorageConfig |
||||
features any |
||||
wantErr bool |
||||
}{ |
||||
{ |
||||
name: "with legacy storage", |
||||
StorageType: StorageTypeLegacy, |
||||
UnifiedStorageConfig: map[string]setting.UnifiedStorageConfig{"playlists.playlist.grafana.app": {DualWriterMode: 2}}, |
||||
features: featuremgmt.WithFeatures(), |
||||
}, |
||||
{ |
||||
name: "with unified storage and without config for resource", |
||||
StorageType: StorageTypeUnified, |
||||
UnifiedStorageConfig: map[string]setting.UnifiedStorageConfig{}, |
||||
features: featuremgmt.WithFeatures(), |
||||
}, |
||||
{ |
||||
name: "with unified storage, mode > 1 and with toggle for resource", |
||||
StorageType: StorageTypeUnified, |
||||
UnifiedStorageConfig: map[string]setting.UnifiedStorageConfig{"playlists.playlist.grafana.app": {DualWriterMode: 2}}, |
||||
features: featuremgmt.WithFeatures(featuremgmt.FlagKubernetesPlaylists), |
||||
}, |
||||
{ |
||||
name: "with unified storage, mode > 1 and without toggle for resource", |
||||
StorageType: StorageTypeUnified, |
||||
UnifiedStorageConfig: map[string]setting.UnifiedStorageConfig{"playlists.playlist.grafana.app": {DualWriterMode: 2}}, |
||||
features: featuremgmt.WithFeatures(), |
||||
wantErr: true, |
||||
}, |
||||
{ |
||||
name: "with unified storage and mode = 1", |
||||
StorageType: StorageTypeUnified, |
||||
UnifiedStorageConfig: map[string]setting.UnifiedStorageConfig{"playlists.playlist.grafana.app": {DualWriterMode: 1}}, |
||||
features: featuremgmt.WithFeatures(), |
||||
}, |
||||
} |
||||
for _, tt := range tests { |
||||
t.Run(tt.name, func(t *testing.T) { |
||||
o := &StorageOptions{ |
||||
StorageType: tt.StorageType, |
||||
UnifiedStorageConfig: tt.UnifiedStorageConfig, |
||||
} |
||||
err := o.EnforceFeatureToggleAfterMode1(tt.features.(featuremgmt.FeatureToggles)) |
||||
if tt.wantErr { |
||||
return |
||||
} |
||||
assert.NoError(t, err) |
||||
}) |
||||
} |
||||
} |
||||
@ -0,0 +1,31 @@ |
||||
package setting |
||||
|
||||
import ( |
||||
"strings" |
||||
|
||||
"github.com/grafana/grafana/pkg/apiserver/rest" |
||||
) |
||||
|
||||
// read storage configs from ini file. They look like:
|
||||
// [unified_storage.<group>.<resource>]
|
||||
// <field> = <value>
|
||||
// e.g.
|
||||
// [unified_storage.playlists.playlist.grafana.app]
|
||||
// dualWriterMode = 2
|
||||
func (cfg *Cfg) setUnifiedStorageConfig() { |
||||
storageConfig := make(map[string]UnifiedStorageConfig) |
||||
sections := cfg.Raw.Sections() |
||||
for _, section := range sections { |
||||
sectionName := section.Name() |
||||
if !strings.HasPrefix(sectionName, "unified_storage.") { |
||||
continue |
||||
} |
||||
// the resource name is the part after the first dot
|
||||
resourceName := strings.SplitAfterN(sectionName, ".", 2)[1] |
||||
|
||||
// parse dualWriter modes from the section
|
||||
dualWriterMode := section.Key("dualWriterMode").MustInt(0) |
||||
storageConfig[resourceName] = UnifiedStorageConfig{DualWriterMode: rest.DualWriterMode(dualWriterMode)} |
||||
} |
||||
cfg.UnifiedStorage = storageConfig |
||||
} |
||||
@ -0,0 +1,28 @@ |
||||
package setting |
||||
|
||||
import ( |
||||
"testing" |
||||
|
||||
"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) |
||||
|
||||
s, err := cfg.Raw.NewSection("unified_storage.playlists.playlist.grafana.app") |
||||
assert.NoError(t, err) |
||||
|
||||
_, err = s.NewKey("dualWriterMode", "2") |
||||
assert.NoError(t, err) |
||||
|
||||
cfg.setUnifiedStorageConfig() |
||||
|
||||
value, exists := cfg.UnifiedStorage["playlists.playlist.grafana.app"] |
||||
|
||||
assert.Equal(t, exists, true) |
||||
assert.Equal(t, value, UnifiedStorageConfig{DualWriterMode: 2}) |
||||
}) |
||||
} |
||||
Loading…
Reference in new issue