MM-28859 Add feature flag managment system using split.io and remove viper. (#15954)
* Add feature flag managment system using split.io and remove viper. * Fixing tests. * Attempt to fix postgres tests. * Fix watch filepath for advanced logging. * Review fixes. * Some error wrapping. * Remove unessisary store interface. * Desanitize SplitKey * Simplify. * Review feedback. * Rename split mlog adatper to split logger. * fsInner * Style. * Restore oldcfg test. * Downgrading non-actionable feature flag errors to warnings. Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
8bb772638c
Коммит
1aadd36644
@@ -4,9 +4,7 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
@@ -14,9 +12,8 @@ import (
|
||||
)
|
||||
|
||||
// MemoryStore implements the Store interface. It is meant primarily for testing.
|
||||
// Not to be used directly. Only to be used as a backing store for config.Store
|
||||
type MemoryStore struct {
|
||||
commonStore
|
||||
|
||||
allowEnvironmentOverrides bool
|
||||
validate bool
|
||||
files map[string][]byte
|
||||
@@ -56,24 +53,12 @@ func NewMemoryStoreWithOptions(options *MemoryStoreOptions) (*MemoryStore, error
|
||||
savedConfig: savedConfig,
|
||||
}
|
||||
|
||||
ms.commonStore.config = &model.Config{}
|
||||
ms.commonStore.config.SetDefaults()
|
||||
|
||||
if err := ms.Load(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ms, nil
|
||||
}
|
||||
|
||||
// Set replaces the current configuration in its entirety.
|
||||
func (ms *MemoryStore) Set(newCfg *model.Config) (*model.Config, error) {
|
||||
validate := ms.commonStore.validate
|
||||
if !ms.validate {
|
||||
validate = nil
|
||||
}
|
||||
|
||||
return ms.commonStore.set(newCfg, ms.allowEnvironmentOverrides, validate, ms.persist)
|
||||
func (ms *MemoryStore) Set(newCfg *model.Config) error {
|
||||
return ms.persist(newCfg)
|
||||
}
|
||||
|
||||
// persist copies the active config to the saved config.
|
||||
@@ -84,28 +69,18 @@ func (ms *MemoryStore) persist(cfg *model.Config) error {
|
||||
}
|
||||
|
||||
// Load applies environment overrides to the default config as if a re-load had occurred.
|
||||
func (ms *MemoryStore) Load() (err error) {
|
||||
var cfgBytes []byte
|
||||
cfgBytes, err = marshalConfig(ms.savedConfig)
|
||||
func (ms *MemoryStore) Load() ([]byte, error) {
|
||||
cfgBytes, err := marshalConfig(ms.savedConfig)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to serialize config")
|
||||
return nil, errors.Wrap(err, "failed to serialize config")
|
||||
}
|
||||
|
||||
f := ioutil.NopCloser(bytes.NewReader(cfgBytes))
|
||||
return cfgBytes, nil
|
||||
|
||||
validate := ms.commonStore.validate
|
||||
if !ms.validate {
|
||||
validate = nil
|
||||
}
|
||||
|
||||
return ms.commonStore.load(f, false, validate, ms.persist)
|
||||
}
|
||||
|
||||
// GetFile fetches the contents of a previously persisted configuration file.
|
||||
func (ms *MemoryStore) GetFile(name string) ([]byte, error) {
|
||||
ms.configLock.RLock()
|
||||
defer ms.configLock.RUnlock()
|
||||
|
||||
data, ok := ms.files[name]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("file %s not stored", name)
|
||||
@@ -116,9 +91,6 @@ func (ms *MemoryStore) GetFile(name string) ([]byte, error) {
|
||||
|
||||
// SetFile sets or replaces the contents of a configuration file.
|
||||
func (ms *MemoryStore) SetFile(name string, data []byte) error {
|
||||
ms.configLock.Lock()
|
||||
defer ms.configLock.Unlock()
|
||||
|
||||
ms.files[name] = data
|
||||
|
||||
return nil
|
||||
@@ -126,18 +98,12 @@ func (ms *MemoryStore) SetFile(name string, data []byte) error {
|
||||
|
||||
// HasFile returns true if the given file was previously persisted.
|
||||
func (ms *MemoryStore) HasFile(name string) (bool, error) {
|
||||
ms.configLock.RLock()
|
||||
defer ms.configLock.RUnlock()
|
||||
|
||||
_, ok := ms.files[name]
|
||||
return ok, nil
|
||||
}
|
||||
|
||||
// RemoveFile removes a previously persisted configuration file.
|
||||
func (ms *MemoryStore) RemoveFile(name string) error {
|
||||
ms.configLock.Lock()
|
||||
defer ms.configLock.Unlock()
|
||||
|
||||
delete(ms.files, name)
|
||||
|
||||
return nil
|
||||
@@ -152,3 +118,8 @@ func (ms *MemoryStore) String() string {
|
||||
func (ms *MemoryStore) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Watch nothing on memory store
|
||||
func (ms *MemoryStore) Watch(_ func()) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user