Skip to content

Commit

Permalink
Merge pull request etcd-io#16465 from riendeau/validate-help-flags
Browse files Browse the repository at this point in the history
Unit test for CLI flags and add missing flags
  • Loading branch information
ahrtr authored Aug 23, 2023
2 parents e44afcf + 63e614f commit bcdf055
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
2 changes: 1 addition & 1 deletion server/etcdmain/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func newConfig() *config {
fs.IntVar(&cfg.ec.ExperimentalCompactionBatchLimit, "experimental-compaction-batch-limit", cfg.ec.ExperimentalCompactionBatchLimit, "Sets the maximum revisions deleted in each compaction batch.")
fs.DurationVar(&cfg.ec.ExperimentalCompactionSleepInterval, "experimental-compaction-sleep-interval", cfg.ec.ExperimentalCompactionSleepInterval, "Sets the sleep interval between each compaction batch.")
fs.DurationVar(&cfg.ec.ExperimentalWatchProgressNotifyInterval, "experimental-watch-progress-notify-interval", cfg.ec.ExperimentalWatchProgressNotifyInterval, "Duration of periodic watch progress notifications.")
fs.DurationVar(&cfg.ec.ExperimentalDowngradeCheckTime, "experimental-downgrade-check-time", cfg.ec.ExperimentalDowngradeCheckTime, "Duration of time between two downgrade status check.")
fs.DurationVar(&cfg.ec.ExperimentalDowngradeCheckTime, "experimental-downgrade-check-time", cfg.ec.ExperimentalDowngradeCheckTime, "Duration of time between two downgrade status checks.")
fs.DurationVar(&cfg.ec.ExperimentalWarningApplyDuration, "experimental-warning-apply-duration", cfg.ec.ExperimentalWarningApplyDuration, "Time duration after which a warning is generated if request takes more time.")
fs.DurationVar(&cfg.ec.WarningUnaryRequestDuration, "warning-unary-request-duration", cfg.ec.WarningUnaryRequestDuration, "Time duration after which a warning is generated if a unary request takes more time.")
fs.DurationVar(&cfg.ec.ExperimentalWarningUnaryRequestDuration, "experimental-warning-unary-request-duration", cfg.ec.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.")
Expand Down
17 changes: 17 additions & 0 deletions server/etcdmain/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package etcdmain

import (
"flag"
"fmt"
"net/url"
"os"
Expand All @@ -24,6 +25,7 @@ import (

"sigs.k8s.io/yaml"

"go.etcd.io/etcd/pkg/v3/flags"
"go.etcd.io/etcd/server/v3/embed"
)

Expand Down Expand Up @@ -378,6 +380,21 @@ func TestConfigFileElectionTimeout(t *testing.T) {
}
}

func TestFlagsPresentInHelp(t *testing.T) {
cfg := newConfig()
cfg.cf.flagSet.VisitAll(func(f *flag.Flag) {
if _, ok := f.Value.(*flags.IgnoredFlag); ok {
// Ignored flags do not need to be in the help
return
}

flagText := fmt.Sprintf("--%s", f.Name)
if !strings.Contains(flagsline, flagText) && !strings.Contains(usageline, flagText) {
t.Errorf("Neither flagsline nor usageline in help.go contains flag named %s", flagText)
}
})
}

func mustCreateCfgFile(t *testing.T, b []byte) *os.File {
tmpfile, err := os.CreateTemp("", "servercfg")
if err != nil {
Expand Down
27 changes: 26 additions & 1 deletion server/etcdmain/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

cconfig "go.etcd.io/etcd/server/v3/config"
"go.etcd.io/etcd/server/v3/embed"
"go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp"
)

var (
Expand Down Expand Up @@ -95,7 +96,13 @@ Member:
--socket-reuse-port 'false'
Enable to set socket option SO_REUSEPORT on listeners allowing rebinding of a port already in use.
--socket-reuse-address 'false'
Enable to set socket option SO_REUSEADDR on listeners allowing binding to an address in TIME_WAIT state.
Enable to set socket option SO_REUSEADDR on listeners allowing binding to an address in TIME_WAIT state.
--enable-grpc-gateway
Enable GRPC gateway.
--raft-read-timeout '` + rafthttp.DefaultConnReadTimeout.String() + `'
Read timeout set on each rafthttp connection
--raft-write-timeout '` + rafthttp.DefaultConnWriteTimeout.String() + `'
Write timeout set on each rafthttp connection
Clustering:
--initial-advertise-peer-urls 'http://localhost:2380'
Expand Down Expand Up @@ -170,6 +177,10 @@ Security:
Path to the client server TLS key file.
--client-cert-auth 'false'
Enable client cert authentication.
--client-cert-file ''
Path to an explicit peer client TLS cert file otherwise cert file will be used when client auth is required.
--client-key-file ''
Path to an explicit peer client TLS key file otherwise key file will be used when client auth is required.
--client-crl-file ''
Path to the client certificate revocation list file.
--client-cert-allowed-hostname ''
Expand All @@ -184,6 +195,10 @@ Security:
Path to the peer server TLS key file.
--peer-client-cert-auth 'false'
Enable peer client cert authentication.
--peer-client-cert-file ''
Path to an explicit peer client TLS cert file otherwise peer cert file will be used when client auth is required.
--peer-client-key-file ''
Path to an explicit peer client TLS key file otherwise peer key file will be used when client auth is required.
--peer-trusted-ca-file ''
Path to the peer server TLS trusted CA file.
--peer-cert-allowed-cn ''
Expand Down Expand Up @@ -282,6 +297,16 @@ Experimental feature:
Set the maximum time duration to wait for the cluster to be ready.
--experimental-snapshot-catch-up-entries '5000'
Number of entries for a slow follower to catch up after compacting the raft storage entries.
--experimental-compaction-sleep-interval
Sets the sleep interval between each compaction batch.
--experimental-downgrade-check-time
Duration of time between two downgrade status checks.
--experimental-enable-lease-checkpoint-persist 'false'
Enable persisting remainingTTL to prevent indefinite auto-renewal of long lived leases. Always enabled in v3.6. Should be used to ensure smooth upgrade from v3.5 clusters with this feature enabled. Requires experimental-enable-lease-checkpoint to be enabled.
--experimental-memory-mlock
Enable to enforce etcd pages (in particular bbolt) to stay in RAM.
--experimental-snapshot-catchup-entries
Number of entries for a slow follower to catch up after compacting the raft storage entries.
Unsafe feature:
--force-new-cluster 'false'
Expand Down

0 comments on commit bcdf055

Please sign in to comment.