Skip to content

Commit

Permalink
migrate to use warning-apply-duration flag
Browse files Browse the repository at this point in the history
Signed-off-by: Gang Li <[email protected]>
  • Loading branch information
gangli113 committed Jan 23, 2025
1 parent b16b8dc commit 9683109
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 6 deletions.
16 changes: 11 additions & 5 deletions server/embed/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ var (
"experimental-corrupt-check-time": "corrupt-check-time",
"experimental-compaction-batch-limit": "compaction-batch-limit",
"experimental-watch-progress-notify-interval": "watch-progress-notify-interval",
"experimental-warning-apply-duration": "warning-apply-duration",
}
)

Expand Down Expand Up @@ -403,7 +404,10 @@ type Config struct {
WatchProgressNotifyInterval time.Duration `json:"watch-progress-notify-interval"`
// ExperimentalWarningApplyDuration is the time duration after which a warning is generated if applying request
// takes more time than this value.
// Deprecated in v3.6 and will be decommissioned in v3.7.
// TODO: Delete in v3.7
ExperimentalWarningApplyDuration time.Duration `json:"experimental-warning-apply-duration"`
WarningApplyDuration time.Duration `json:"warning-apply-duration"`
// ExperimentalBootstrapDefragThresholdMegabytes is the minimum number of megabytes needed to be freed for etcd server to
// consider running defrag during bootstrap. Needs to be set to non-zero value to take effect.
ExperimentalBootstrapDefragThresholdMegabytes uint `json:"experimental-bootstrap-defrag-threshold-megabytes"`
Expand Down Expand Up @@ -551,10 +555,10 @@ func NewConfig() *Config {
SnapshotCount: etcdserver.DefaultSnapshotCount,
SnapshotCatchUpEntries: etcdserver.DefaultSnapshotCatchUpEntries,

MaxTxnOps: DefaultMaxTxnOps,
MaxRequestBytes: DefaultMaxRequestBytes,
MaxConcurrentStreams: DefaultMaxConcurrentStreams,
ExperimentalWarningApplyDuration: DefaultWarningApplyDuration,
MaxTxnOps: DefaultMaxTxnOps,
MaxRequestBytes: DefaultMaxRequestBytes,
MaxConcurrentStreams: DefaultMaxConcurrentStreams,
WarningApplyDuration: DefaultWarningApplyDuration,

GRPCKeepAliveMinTime: DefaultGRPCKeepAliveMinTime,
GRPCKeepAliveInterval: DefaultGRPCKeepAliveInterval,
Expand Down Expand Up @@ -806,7 +810,9 @@ func (cfg *Config) AddFlags(fs *flag.FlagSet) {
fs.DurationVar(&cfg.ExperimentalWatchProgressNotifyInterval, "experimental-watch-progress-notify-interval", cfg.ExperimentalWatchProgressNotifyInterval, "Duration of periodic watch progress notifications. Deprecated in v3.6 and will be decommissioned in v3.7. Use --watch-progress-notify-interval instead.")
fs.DurationVar(&cfg.WatchProgressNotifyInterval, "watch-progress-notify-interval", cfg.WatchProgressNotifyInterval, "Duration of periodic watch progress notifications.")
fs.DurationVar(&cfg.ExperimentalDowngradeCheckTime, "experimental-downgrade-check-time", cfg.ExperimentalDowngradeCheckTime, "Duration of time between two downgrade status checks.")
fs.DurationVar(&cfg.ExperimentalWarningApplyDuration, "experimental-warning-apply-duration", cfg.ExperimentalWarningApplyDuration, "Time duration after which a warning is generated if request takes more time.")
// TODO: delete in v3.7
fs.DurationVar(&cfg.ExperimentalWarningApplyDuration, "experimental-warning-apply-duration", cfg.ExperimentalWarningApplyDuration, "Time duration after which a warning is generated if request takes more time.Deprecated in v3.6 and will be decommissioned in v3.7. Use --warning-watch-progress-duration instead.")
fs.DurationVar(&cfg.WarningApplyDuration, "warning-apply-duration", cfg.WarningApplyDuration, "Time duration after which a warning is generated if watch progress takes more time.")
fs.DurationVar(&cfg.WarningUnaryRequestDuration, "warning-unary-request-duration", cfg.WarningUnaryRequestDuration, "Time duration after which a warning is generated if a unary request takes more time.")
fs.DurationVar(&cfg.ExperimentalWarningUnaryRequestDuration, "experimental-warning-unary-request-duration", cfg.ExperimentalWarningUnaryRequestDuration, "Time duration after which a warning is generated if a unary request takes more time. It's deprecated, and will be decommissioned in v3.7. Use --warning-unary-request-duration instead.")
fs.BoolVar(&cfg.ExperimentalMemoryMlock, "experimental-memory-mlock", cfg.ExperimentalMemoryMlock, "Enable to enforce etcd pages (in particular bbolt) to stay in RAM.")
Expand Down
2 changes: 1 addition & 1 deletion server/embed/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func StartEtcd(inCfg *Config) (e *Etcd, err error) {
CompactionSleepInterval: cfg.ExperimentalCompactionSleepInterval,
WatchProgressNotifyInterval: cfg.WatchProgressNotifyInterval,
DowngradeCheckTime: cfg.ExperimentalDowngradeCheckTime,
WarningApplyDuration: cfg.ExperimentalWarningApplyDuration,
WarningApplyDuration: cfg.WarningApplyDuration,
WarningUnaryRequestDuration: cfg.WarningUnaryRequestDuration,
ExperimentalMemoryMlock: cfg.ExperimentalMemoryMlock,
ExperimentalBootstrapDefragThresholdMegabytes: cfg.ExperimentalBootstrapDefragThresholdMegabytes,
Expand Down
5 changes: 5 additions & 0 deletions server/etcdmain/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ var (
"experimental-corrupt-check-time": "--experimental-corrupt-check-time is deprecated in v3.6 and will be decommissioned in v3.7. Use '--corrupt-check-time' instead.",
"experimental-compaction-batch-limit": "--experimental-compaction-batch-limit is deprecated in v3.6 and will be decommissioned in v3.7. Use '--compaction-batch-limit' instead.",
"experimental-watch-progress-notify-interval": "--experimental-watch-progress-notify-interval is deprecated in v3.6 and will be decommissioned in v3.7. Use '--watch-progress-notify-interval' instead.",
"experimental-warning-apply-duration": "--experimental-warning-apply-duration is deprecated in v3.6 and will be decommissioned in v3.7. Use '--warning-apply-duration' instead.",
}
)

Expand Down Expand Up @@ -189,6 +190,10 @@ func (cfg *config) parse(arguments []string) error {
cfg.ec.WatchProgressNotifyInterval = cfg.ec.ExperimentalWatchProgressNotifyInterval
}

if cfg.ec.FlagsExplicitlySet["experimental-warning-apply-duration"] {
cfg.ec.WarningApplyDuration = cfg.ec.ExperimentalWarningApplyDuration
}

// `V2Deprecation` (--v2-deprecation) is deprecated and scheduled for removal in v3.8. The default value is enforced, ignoring user input.
cfg.ec.V2Deprecation = cconfig.V2DeprDefault

Expand Down
79 changes: 79 additions & 0 deletions server/etcdmain/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,82 @@ func TestWatchProgressNotifyInterval(t *testing.T) {
}
}

// TestWarningApplyDuration tests the migration from
// --experimental-warning-apply-duration to --warning-apply-duration
// TODO: delete in v3.7
func TestWarningApplyDuration(t *testing.T) {
testCases := []struct {
name string
warningApplyDuration string
experimentalWarningApplyDuration string
expectErr bool
expectedWarningApplyDuration time.Duration
}{
{
name: "cannot set both experimental flag and non experimental flag",
warningApplyDuration: "2m",
experimentalWarningApplyDuration: "3m",
expectErr: true,
},
{
name: "can set experimental flag",
experimentalWarningApplyDuration: "3m",
expectedWarningApplyDuration: 3 * time.Minute,
},
{
name: "can set non experimental flag",
warningApplyDuration: "2m",
expectedWarningApplyDuration: 2 * time.Minute,
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
cmdLineArgs := []string{}
yc := struct {
ExperimentalWarningApplyDuration time.Duration `json:"experimental-warning-apply-duration,omitempty"`
WarningApplyDuration time.Duration `json:"warning-apply-duration,omitempty"`
}{}

if tc.warningApplyDuration != "" {
cmdLineArgs = append(cmdLineArgs, fmt.Sprintf("--warning-apply-duration=%s", tc.warningApplyDuration))
warningApplyDuration, err := time.ParseDuration(tc.warningApplyDuration)
if err != nil {
t.Fatal(err)
}
yc.WarningApplyDuration = warningApplyDuration
}

if tc.experimentalWarningApplyDuration != "" {
cmdLineArgs = append(cmdLineArgs, fmt.Sprintf("--experimental-warning-apply-duration=%s", tc.experimentalWarningApplyDuration))
experimentalWarningApplyDuration, err := time.ParseDuration(tc.experimentalWarningApplyDuration)
if err != nil {
t.Fatal(err)
}
yc.ExperimentalWarningApplyDuration = experimentalWarningApplyDuration
}

cfgFromCmdLine, errFromCmdLine, cfgFromFile, errFromFile := generateCfgsFromFileAndCmdLine(t, yc, cmdLineArgs)

if tc.expectErr {
if errFromCmdLine == nil || errFromFile == nil {
t.Fatal("expect parse error")
}
return
}
if errFromCmdLine != nil || errFromFile != nil {
t.Fatal("error parsing config")
}

if cfgFromCmdLine.ec.WarningApplyDuration != tc.expectedWarningApplyDuration {
t.Errorf("expected WarningApplyDuration=%v, got %v", tc.expectedWarningApplyDuration, cfgFromCmdLine.ec.WarningApplyDuration)
}
if cfgFromFile.ec.WarningApplyDuration != tc.expectedWarningApplyDuration {
t.Errorf("expected WarningApplyDuration=%v, got %v", tc.expectedWarningApplyDuration, cfgFromFile.ec.WarningApplyDuration)
}
})
}
}

// TODO delete in v3.7
func generateCfgsFromFileAndCmdLine(t *testing.T, yc any, cmdLineArgs []string) (*config, error, *config, error) {
b, err := yaml.Marshal(&yc)
Expand Down Expand Up @@ -862,6 +938,7 @@ func TestConfigFileDeprecatedOptions(t *testing.T) {
ExperimentalCorruptCheckTime time.Duration `json:"experimental-corrupt-check-time,omitempty"`
ExperimentalCompactionBatchLimit int `json:"experimental-compaction-batch-limit,omitempty"`
ExperimentalWatchProgressNotifyInterval time.Duration `json:"experimental-watch-progress-notify-interval,omitempty"`
ExperimentalWarningApplyDuration time.Duration `json:"experimental-warning-apply-duration,omitempty"`
}

testCases := []struct {
Expand All @@ -883,13 +960,15 @@ func TestConfigFileDeprecatedOptions(t *testing.T) {
ExperimentalCorruptCheckTime: time.Minute,
ExperimentalCompactionBatchLimit: 1,
ExperimentalWatchProgressNotifyInterval: 3 * time.Minute,
ExperimentalWarningApplyDuration: 3 * time.Minute,
},
expectedFlags: map[string]struct{}{
"experimental-compact-hash-check-enabled": {},
"experimental-compact-hash-check-time": {},
"experimental-corrupt-check-time": {},
"experimental-compaction-batch-limit": {},
"experimental-watch-progress-notify-interval": {},
"experimental-warning-apply-duration": {},
},
},
{
Expand Down
2 changes: 2 additions & 0 deletions server/etcdmain/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@ Experimental feature:
--watch-progress-notify-interval '10m'
Duration of periodical watch progress notification.
--experimental-warning-apply-duration '100ms'
Warning is generated if requests take more than this duration. Deprecated in v3.6 and will be decommissioned in v3.7. Use 'warning-apply-duration' instead.
--warning-apply-duration '100ms'
Warning is generated if requests take more than this duration.
--experimental-txn-mode-write-with-shared-buffer 'true'. Deprecated in v3.6 and will be decommissioned in v3.7. Use '--feature-gates=TxnModeWriteWithSharedBuffer=true' instead.
Enable the write transaction to use a shared buffer in its readonly check operations.
Expand Down

0 comments on commit 9683109

Please sign in to comment.