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>
Этот коммит содержится в:
Christopher Speller
2020-10-29 15:54:39 -07:00
коммит произвёл GitHub
родитель 8bb772638c
Коммит 1aadd36644
423 изменённых файлов: 37646 добавлений и 20257 удалений

Просмотреть файл

@@ -38,7 +38,7 @@ import (
type TestHelper struct {
App *app.App
Server *app.Server
ConfigStore config.Store
ConfigStore *config.Store
Client *model.Client4
BasicUser *model.User
@@ -79,20 +79,26 @@ func setupTestHelper(dbStore store.Store, searchEngine *searchengine.Broker, ent
panic("failed to initialize memory store: " + err.Error())
}
config := memoryStore.Get()
*config.PluginSettings.Directory = filepath.Join(tempWorkspace, "plugins")
*config.PluginSettings.ClientDirectory = filepath.Join(tempWorkspace, "webapp")
config.ServiceSettings.EnableLocalMode = model.NewBool(true)
*config.ServiceSettings.LocalModeSocketLocation = filepath.Join(tempWorkspace, "mattermost_local.sock")
*config.AnnouncementSettings.AdminNoticesEnabled = false
*config.AnnouncementSettings.UserNoticesEnabled = false
memoryConfig := &model.Config{}
memoryConfig.SetDefaults()
*memoryConfig.PluginSettings.Directory = filepath.Join(tempWorkspace, "plugins")
*memoryConfig.PluginSettings.ClientDirectory = filepath.Join(tempWorkspace, "webapp")
memoryConfig.ServiceSettings.EnableLocalMode = model.NewBool(true)
*memoryConfig.ServiceSettings.LocalModeSocketLocation = filepath.Join(tempWorkspace, "mattermost_local.sock")
*memoryConfig.AnnouncementSettings.AdminNoticesEnabled = false
*memoryConfig.AnnouncementSettings.UserNoticesEnabled = false
if updateConfig != nil {
updateConfig(config)
updateConfig(memoryConfig)
}
memoryStore.Set(memoryConfig)
configStore, err := config.NewStoreFromBacking(memoryStore)
if err != nil {
panic(err)
}
memoryStore.Set(config)
var options []app.Option
options = append(options, app.ConfigStore(memoryStore))
options = append(options, app.ConfigStore(configStore))
options = append(options, app.StoreOverride(dbStore))
s, err := app.NewServer(options...)
@@ -107,7 +113,7 @@ func setupTestHelper(dbStore store.Store, searchEngine *searchengine.Broker, ent
th := &TestHelper{
App: app.New(app.ServerConnector(s)),
Server: s,
ConfigStore: memoryStore,
ConfigStore: configStore,
IncludeCacheLayer: includeCache,
}
@@ -168,7 +174,7 @@ func setupTestHelper(dbStore store.Store, searchEngine *searchengine.Broker, ent
th.Client.SetBoolString(true, trueString)
th.Client.SetBoolString(false, falseString)
th.LocalClient = th.CreateLocalClient(*config.ServiceSettings.LocalModeSocketLocation)
th.LocalClient = th.CreateLocalClient(*memoryConfig.ServiceSettings.LocalModeSocketLocation)
if th.tempWorkspace == "" {
th.tempWorkspace = tempWorkspace

Просмотреть файл

@@ -14,7 +14,6 @@ import (
"testing"
"time"
"github.com/mattermost/mattermost-server/v5/config"
"github.com/mattermost/mattermost-server/v5/mlog"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/stretchr/testify/assert"
@@ -68,6 +67,7 @@ func TestGetPing(t *testing.T) {
}, "with server status")
th.TestForAllClients(t, func(t *testing.T, client *model.Client4) {
th.App.ReloadConfig()
resp, appErr := client.DoApiGet(client.GetSystemRoute()+"/ping", "")
require.Nil(t, appErr)
require.Equal(t, http.StatusOK, resp.StatusCode)
@@ -77,15 +77,9 @@ func TestGetPing(t *testing.T) {
require.NotContains(t, respString, "TestFeatureFlag")
// Run the enviroment variable override code to test
os.Setenv("MM_FEATUREFLAGS_TESTFEATURE", "testvalue")
os.Setenv("MM_FEATUREFLAGS_TESTFEATURE", "testvalueunique")
defer os.Unsetenv("MM_FEATUREFLAGS_TESTFEATURE")
memoryStore, err := config.NewMemoryStore()
require.Nil(t, err)
retrievedConfig := memoryStore.Get()
// replace config with generated config
oldConfig := th.App.Config().Clone()
th.App.UpdateConfig(func(cfg *model.Config) { *cfg = *retrievedConfig })
th.App.ReloadConfig()
resp, appErr = client.DoApiGet(client.GetSystemRoute()+"/ping", "")
require.Nil(t, appErr)
@@ -94,7 +88,6 @@ func TestGetPing(t *testing.T) {
require.Nil(t, err)
respString = string(respBytes)
require.Contains(t, respString, "testvalue")
th.App.UpdateConfig(func(cfg *model.Config) { *cfg = *oldConfig })
}, "ping feature flag test")
}