MM-34674 Adding config telemetry for feature flags. (#17456)

* Adding config telemetry for feature flags.

* Review fixes.
Этот коммит содержится в:
Christopher Speller
2021-04-27 08:58:38 -07:00
коммит произвёл GitHub
родитель d819eb224c
Коммит 684cd93755
8 изменённых файлов: 94 добавлений и 70 удалений

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

@@ -3143,7 +3143,7 @@ type Config struct {
GuestAccountsSettings GuestAccountsSettings
ImageProxySettings ImageProxySettings
CloudSettings CloudSettings // telemetry: none
FeatureFlags *FeatureFlags `access:"*_read" json:",omitempty"` // telemetry: none
FeatureFlags *FeatureFlags `access:"*_read" json:",omitempty"`
ImportSettings ImportSettings // telemetry: none
ExportSettings ExportSettings
}

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

@@ -3,7 +3,10 @@
package model
import "reflect"
import (
"reflect"
"strconv"
)
type FeatureFlags struct {
// Exists only for unit and manual testing.
@@ -72,3 +75,26 @@ func (f *FeatureFlags) Plugins() map[string]string {
return pluginVersions
}
// ToMap returns the feature flags as a map[string]string
// Supports boolean and string feature flags.
func (f *FeatureFlags) ToMap() map[string]string {
refStructVal := reflect.ValueOf(*f)
refStructType := reflect.TypeOf(*f)
ret := make(map[string]string)
for i := 0; i < refStructVal.NumField(); i++ {
refFieldVal := refStructVal.Field(i)
if !refFieldVal.IsValid() {
continue
}
refFieldType := refStructType.Field(i)
switch refFieldType.Type.Kind() {
case reflect.Bool:
ret[refFieldType.Name] = strconv.FormatBool(refFieldVal.Bool())
default:
ret[refFieldType.Name] = refFieldVal.String()
}
}
return ret
}

54
model/feature_flags_test.go Обычный файл
Просмотреть файл

@@ -0,0 +1,54 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package model
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestFeatureFlagsToMap(t *testing.T) {
for name, tc := range map[string]struct {
Flags FeatureFlags
TestFeatureValue string
}{
"empty": {
TestFeatureValue: "",
Flags: FeatureFlags{},
},
"simple value": {
TestFeatureValue: "expectedvalue",
Flags: FeatureFlags{TestFeature: "expectedvalue"},
},
"empty value": {
TestFeatureValue: "",
Flags: FeatureFlags{TestFeature: ""},
},
} {
t.Run(name, func(t *testing.T) {
require.Equal(t, tc.TestFeatureValue, tc.Flags.ToMap()["TestFeature"])
})
}
}
func TestFeatureFlagsToMapBool(t *testing.T) {
for name, tc := range map[string]struct {
Flags FeatureFlags
TestFeatureValue string
}{
"false": {
TestFeatureValue: "false",
Flags: FeatureFlags{},
},
"true": {
TestFeatureValue: "true",
Flags: FeatureFlags{TestBoolFeature: true},
},
} {
t.Run(name, func(t *testing.T) {
require.Equal(t, tc.TestFeatureValue, tc.Flags.ToMap()["TestBoolFeature"])
})
}
}