Skip to content

Commit dd39d69

Browse files
committed
Update feature gate logging to include default on
After the 5.7 release, when AutoUserSchemaCreate was graduated to default on/true, we discovered that our current system (and the underlying featuregate implementation) treats features explicitly turned on by the user differently than features turned on by default. This PR updates that logging to make clear that the features are those specifically requested by the user (kept as a string to help debugging) and revises the 'ShowGates' function to include those set through defaults. Issues: [PGO-1824]
1 parent 446c9c7 commit dd39d69

File tree

4 files changed

+34
-9
lines changed

4 files changed

+34
-9
lines changed

cmd/postgres-operator/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ func main() {
134134

135135
features := feature.NewGate()
136136
assertNoError(features.Set(os.Getenv("PGO_FEATURE_GATES")))
137-
log.Info("feature gates enabled", "PGO_FEATURE_GATES", features.String())
137+
// This logs just the feature gates as set by the user
138+
log.Info("feature gates enabled during deployment", "PGO_FEATURE_GATES", features.String())
138139

139140
cfg, err := runtime.GetConfig()
140141
assertNoError(err)

internal/feature/features.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ package feature
4242

4343
import (
4444
"context"
45+
"fmt"
46+
"sort"
47+
"strings"
4548

4649
"k8s.io/component-base/featuregate"
4750
)
@@ -52,6 +55,7 @@ type Feature = featuregate.Feature
5255
type Gate interface {
5356
Enabled(Feature) bool
5457
String() string
58+
GetAll() map[Feature]featuregate.FeatureSpec
5559
}
5660

5761
// MutableGate contains features that can be enabled or disabled.
@@ -122,11 +126,23 @@ func NewContext(ctx context.Context, gate Gate) context.Context {
122126
return context.WithValue(ctx, contextKey{}, gate)
123127
}
124128

129+
// ShowGates returns all the gates that are on by default
130+
// (if not turned off by the user) or were explicitly set
131+
// on by the user.
125132
func ShowGates(ctx context.Context) string {
126-
featuresEnabled := ""
133+
featuresEnabled := []string{}
127134
gate, ok := ctx.Value(contextKey{}).(Gate)
128135
if ok {
129-
featuresEnabled = gate.String()
136+
specs := gate.GetAll()
137+
for feature := range specs {
138+
// `gate.Enabled` first checks if the feature is enabled;
139+
// then (if not explicitly set by the user),
140+
// it checks if the feature is on/true by default
141+
if gate.Enabled(feature) {
142+
featuresEnabled = append(featuresEnabled, fmt.Sprintf("%s=true", feature))
143+
}
144+
}
130145
}
131-
return featuresEnabled
146+
sort.Strings(featuresEnabled)
147+
return strings.Join(featuresEnabled, ",")
132148
}

internal/feature/features_test.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,21 @@ func TestContext(t *testing.T) {
5353
t.Parallel()
5454
gate := NewGate()
5555
ctx := NewContext(context.Background(), gate)
56-
assert.Equal(t, ShowGates(ctx), "")
56+
57+
// ShowGates returns all fields that are turned on, whether explicitly
58+
// by the user or implicitly due to feature default.
59+
// Currently, the only feature defaulting to true is `AutoCreateUserSchema`.
60+
assert.Equal(t, ShowGates(ctx), "AutoCreateUserSchema=true")
5761

5862
assert.NilError(t, gate.Set("TablespaceVolumes=true"))
5963
assert.Assert(t, true == Enabled(ctx, TablespaceVolumes))
60-
assert.Equal(t, ShowGates(ctx), "TablespaceVolumes=true")
64+
assert.Equal(t, ShowGates(ctx), "AutoCreateUserSchema=true,TablespaceVolumes=true")
6165

62-
assert.NilError(t, gate.SetFromMap(map[string]bool{TablespaceVolumes: false}))
66+
assert.NilError(t, gate.SetFromMap(map[string]bool{
67+
TablespaceVolumes: false,
68+
AutoCreateUserSchema: false,
69+
}))
6370
assert.Assert(t, false == Enabled(ctx, TablespaceVolumes))
64-
assert.Equal(t, ShowGates(ctx), "TablespaceVolumes=false")
71+
assert.Assert(t, false == Enabled(ctx, AutoCreateUserSchema))
72+
assert.Equal(t, ShowGates(ctx), "")
6573
}

internal/upgradecheck/http_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func TestCheckForUpgrades(t *testing.T) {
6969
assert.Equal(t, data.RegistrationToken, "speakFriend")
7070
assert.Equal(t, data.BridgeClustersTotal, 2)
7171
assert.Equal(t, data.PGOClustersTotal, 2)
72-
assert.Equal(t, data.FeatureGatesEnabled, "TablespaceVolumes=true")
72+
assert.Equal(t, data.FeatureGatesEnabled, "AutoCreateUserSchema=true,TablespaceVolumes=true")
7373
}
7474

7575
t.Run("success", func(t *testing.T) {

0 commit comments

Comments
 (0)