FeatureFlags: fix setting flags to false in startup (#80836)

This commit is contained in:
Ryan McKinley 2024-01-18 10:03:45 -08:00 committed by GitHub
parent 9e08c88a1c
commit 96fe605d95
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 1 deletions

View File

@ -102,7 +102,8 @@ func (fm *FeatureManager) update() {
// Update the registry
track := 0.0
if flag.Expression == "true" || (fm.startup[flag.Name]) {
startup, ok := fm.startup[flag.Name]
if startup || (!ok && flag.Expression == "true") {
track = 1
enabled[flag.Name] = true
}

View File

@ -75,4 +75,25 @@ func TestFeatureManager(t *testing.T) {
require.Equal(t, "second", flag.Description)
require.Equal(t, "http://something", flag.DocsURL)
})
t.Run("check startup false flags", func(t *testing.T) {
ft := FeatureManager{
flags: map[string]*FeatureFlag{},
startup: map[string]bool{
"a": true,
"b": false, // but default true
},
}
ft.registerFlags(FeatureFlag{
Name: "a",
}, FeatureFlag{
Name: "b",
Expression: "true",
}, FeatureFlag{
Name: "c",
})
require.True(t, ft.IsEnabledGlobally("a"))
require.False(t, ft.IsEnabledGlobally("b"))
require.False(t, ft.IsEnabledGlobally("c"))
})
}