MM-34674 Adding config telemetry for feature flags. (#17456)
* Adding config telemetry for feature flags. * Review fixes.
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
d819eb224c
Коммит
684cd93755
@@ -353,7 +353,7 @@ func GenerateLimitedClientConfig(c *model.Config, telemetryID string, license *m
|
||||
}
|
||||
}
|
||||
|
||||
for key, value := range featureFlagsToMap(c.FeatureFlags) {
|
||||
for key, value := range c.FeatureFlags.ToMap() {
|
||||
props["FeatureFlag"+key] = value
|
||||
}
|
||||
|
||||
|
||||
@@ -100,29 +100,6 @@ func featureFlagsFromMap(featuresMap map[string]string, baseFeatureFlags model.F
|
||||
return baseFeatureFlags
|
||||
}
|
||||
|
||||
// featureFlagsToMap returns the feature flags as a map[string]string
|
||||
// Supports boolean and string feature flags.
|
||||
func featureFlagsToMap(featureFlags *model.FeatureFlags) map[string]string {
|
||||
refStructVal := reflect.ValueOf(*featureFlags)
|
||||
refStructType := reflect.TypeOf(*featureFlags)
|
||||
ret := make(map[string]string)
|
||||
for i := 0; i < refStructVal.NumField(); i++ {
|
||||
refFieldVal := refStructVal.Field(i)
|
||||
refFieldType := refStructType.Field(i)
|
||||
if !refFieldVal.IsValid() {
|
||||
continue
|
||||
}
|
||||
switch refFieldType.Type.Kind() {
|
||||
case reflect.Bool:
|
||||
ret[refFieldType.Name] = strconv.FormatBool(refFieldVal.Bool())
|
||||
default:
|
||||
ret[refFieldType.Name] = refFieldVal.String()
|
||||
}
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
func getStructFields(s interface{}) []string {
|
||||
structType := reflect.TypeOf(s)
|
||||
fieldNames := make([]string, 0, structType.NumField())
|
||||
|
||||
@@ -109,47 +109,3 @@ func TestFeatureFlagsFromMap(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestFeatureFlagsToMap(t *testing.T) {
|
||||
for name, tc := range map[string]struct {
|
||||
Flags model.FeatureFlags
|
||||
TestFeatureValue string
|
||||
}{
|
||||
"empty": {
|
||||
TestFeatureValue: "",
|
||||
Flags: model.FeatureFlags{},
|
||||
},
|
||||
"simple value": {
|
||||
TestFeatureValue: "expectedvalue",
|
||||
Flags: model.FeatureFlags{TestFeature: "expectedvalue"},
|
||||
},
|
||||
"empty value": {
|
||||
TestFeatureValue: "",
|
||||
Flags: model.FeatureFlags{TestFeature: ""},
|
||||
},
|
||||
} {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
require.Equal(t, tc.TestFeatureValue, featureFlagsToMap(&tc.Flags)["TestFeature"])
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestFeatureFlagsToMapBool(t *testing.T) {
|
||||
for name, tc := range map[string]struct {
|
||||
Flags model.FeatureFlags
|
||||
TestFeatureValue string
|
||||
}{
|
||||
"false": {
|
||||
TestFeatureValue: "false",
|
||||
Flags: model.FeatureFlags{},
|
||||
},
|
||||
"true": {
|
||||
TestFeatureValue: "true",
|
||||
Flags: model.FeatureFlags{TestBoolFeature: true},
|
||||
},
|
||||
} {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
require.Equal(t, tc.TestFeatureValue, featureFlagsToMap(&tc.Flags)["TestBoolFeature"])
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user