Skip to content

Commit

Permalink
fix for etcd-io#19066 Print warnings when deprecated options are conf…
Browse files Browse the repository at this point in the history
…igured in config file

Signed-off-by: mansoora <[email protected]>
  • Loading branch information
mansoor17syed committed Jan 10, 2025
1 parent 31f1bb9 commit 4151dd7
Showing 1 changed file with 95 additions and 0 deletions.
95 changes: 95 additions & 0 deletions server/etcdmain/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -653,3 +653,98 @@ func validateClusteringFlags(t *testing.T, cfg *config) {
t.Errorf("advertise-client-urls = %v, want %v", cfg.ec.AdvertiseClientUrls, wcfg.ec.AdvertiseClientUrls)
}
}

func TestConfigFileDeprecatedOptions(t *testing.T) {
type configStruct struct {
SnapshotCount uint64 `json:"snapshot-count,omitempty"`
MaxSnapFiles uint `json:"max-snapshots,omitempty"`
V2Deprecation string `json:"v2-deprecation,omitempty"`
ExperimentalCompactHashCheckEnabled bool `json:"experimental-compact-hash-check-enabled,omitempty"`
ExperimentalCompactHashCheckTime time.Duration `json:"experimental-compact-hash-check-time,omitempty"`
ExperimentalWarningUnaryRequestDuration time.Duration `json:"experimental-warning-unary-request-duration,omitempty"`
}

testCases := []struct {
name string
configFileYAML configStruct
expectedWarnings []string
}{
{
name: "no deprecated options",
configFileYAML: configStruct{},
expectedWarnings: nil,
},
{
name: "deprecated experimental options",
configFileYAML: configStruct{
ExperimentalCompactHashCheckEnabled: true,
ExperimentalCompactHashCheckTime: 2 * time.Minute,
ExperimentalWarningUnaryRequestDuration: time.Second,
},
expectedWarnings: []string{
"experimental-compact-hash-check-enabled is deprecated in v3.6 and will be decommissioned in v3.7. Use '--feature-gates=CompactHashCheck=true' instead",
"experimental-compact-hash-check-time is deprecated in v3.6 and will be decommissioned in v3.7. Use --compact-hash-check-time instead",
"experimental-warning-unary-request-duration is deprecated, and will be decommissioned in v3.7. Use warning-unary-request-duration instead",
},
},
{
name: "deprecated snapshot options",
configFileYAML: configStruct{
SnapshotCount: 10000,
MaxSnapFiles: 5,
},
expectedWarnings: []string{
"snapshot-count is deprecated in v3.6 and will be decommissioned in v3.7",
"max-snapshots is deprecated in v3.6 and will be decommissioned in v3.7",
},
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
b, err := yaml.Marshal(&tc.configFileYAML)
if err != nil {
t.Fatal(err)
}

tmpfile := mustCreateCfgFile(t, b)
defer os.Remove(tmpfile.Name())

cfg := newConfig()
err = cfg.parse([]string{fmt.Sprintf("--config-file=%s", tmpfile.Name())})
if err != nil {
t.Fatal(err)
}

// Check if the expected flags were marked as deprecated
for flagName := range cfg.ec.FlagsExplicitlySet {
if msg, ok := deprecatedFlags[flagName]; ok {
found := false
for _, expected := range tc.expectedWarnings {
if msg == expected {
found = true
break
}
}
if !found {
t.Errorf("unexpected deprecated flag warning for %q: %q", flagName, msg)
}
}
}

// Check if all expected warnings were present
for _, expected := range tc.expectedWarnings {
found := false
for flagName := range cfg.ec.FlagsExplicitlySet {
if msg, ok := deprecatedFlags[flagName]; ok && msg == expected {
found = true
break
}
}
if !found {
t.Errorf("missing expected warning: %q", expected)
}
}
})
}
}

0 comments on commit 4151dd7

Please sign in to comment.