MM28858 Basic framework for use of feature flags. Enviroment variable overrides. (#15544)

* Basic framework for use of feature flags. Enviroment variable overrides.

* Use Apperr instead of error number increments.

* Undo random viper change.

* Update model/config_test.go

Co-authored-by: Jesse Hallam <jesse.hallam@gmail.com>

Co-authored-by: Jesse Hallam <jesse.hallam@gmail.com>
Этот коммит содержится в:
Christopher Speller
2020-09-29 21:41:22 -07:00
коммит произвёл GitHub
родитель 61f08d397c
Коммит e974b7b9be
11 изменённых файлов: 130 добавлений и 129 удалений

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

@@ -79,6 +79,11 @@ func getSystemPing(c *Context, w http.ResponseWriter, r *http.Request) {
s["IosLatestVersion"] = reqs.IosLatestVersion
s["IosMinVersion"] = reqs.IosMinVersion
testflag := c.App.Config().FeatureFlags.TestFeature
if testflag != "off" {
s["TestFeatureFlag"] = testflag
}
actualGoroutines := runtime.NumGoroutine()
if *c.App.Config().ServiceSettings.GoroutineHealthThreshold > 0 && actualGoroutines >= *c.App.Config().ServiceSettings.GoroutineHealthThreshold {
mlog.Warn("The number of running goroutines is over the health threshold", mlog.Int("goroutines", actualGoroutines), mlog.Int("health_threshold", *c.App.Config().ServiceSettings.GoroutineHealthThreshold))

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

@@ -14,6 +14,7 @@ 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"
@@ -64,6 +65,36 @@ func TestGetPing(t *testing.T) {
})
})
t.Run("ping feature flag test", func(t *testing.T) {
resp, appErr := th.Client.DoApiGet(th.Client.GetSystemRoute()+"/ping", "")
require.Nil(t, appErr)
require.Equal(t, http.StatusOK, resp.StatusCode)
respBytes, err := ioutil.ReadAll(resp.Body)
require.Nil(t, err)
respString := string(respBytes)
require.NotContains(t, respString, "TestFeatureFlag")
// Run the enviroment variable override code to test
os.Setenv("MM_FEATUREFLAGS_TESTFEATURE", "testvalue")
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 })
resp, appErr = th.Client.DoApiGet(th.Client.GetSystemRoute()+"/ping", "")
require.Nil(t, appErr)
require.Equal(t, http.StatusOK, resp.StatusCode)
respBytes, err = ioutil.ReadAll(resp.Body)
require.Nil(t, err)
respString = string(respBytes)
require.Contains(t, respString, "testvalue")
th.App.UpdateConfig(func(cfg *model.Config) { *cfg = *oldConfig })
})
}
func TestGetAudits(t *testing.T) {