grafana/pkg/setting/setting_unified_storage.go
maicon 377079d8b3
UniStore: Add config to enable periodic DualWriter DataSyncer (#93555)
Signed-off-by: Maicon Costa <maiconscosta@gmail.com>
2024-09-24 22:03:15 +03:00

39 lines
1.2 KiB
Go

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)
// parse dualWriter periodic data syncer config
dualWriterPeriodicDataSyncJobEnabled := section.Key("dualWriterPeriodicDataSyncJobEnabled").MustBool(false)
storageConfig[resourceName] = UnifiedStorageConfig{
DualWriterMode: rest.DualWriterMode(dualWriterMode),
DualWriterPeriodicDataSyncJobEnabled: dualWriterPeriodicDataSyncJobEnabled,
}
}
cfg.UnifiedStorage = storageConfig
}