Skip to content

Commit

Permalink
Align NewConfig with AddFlags defaults
Browse files Browse the repository at this point in the history
Signed-off-by: Marek Siarkowicz <[email protected]>
  • Loading branch information
serathius committed Jan 30, 2025
1 parent dd60559 commit 663dfc9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 32 deletions.
54 changes: 35 additions & 19 deletions server/embed/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,18 @@ const (
DefaultGRPCKeepAliveTimeout = 20 * time.Second
DefaultDowngradeCheckTime = 5 * time.Second
DefaultAutoCompactionMode = "periodic"
DefaultAutoCompactionRetention = "0"
DefaultAuthToken = "simple"
DefaultCompactHashCheckTime = time.Minute
DefaultLoggingFormat = "json"

DefaultDiscoveryDialTimeout = 2 * time.Second
DefaultDiscoveryRequestTimeOut = 5 * time.Second
DefaultDiscoveryKeepAliveTime = 2 * time.Second
DefaultDiscoveryKeepAliveTimeOut = 6 * time.Second
DefaultDiscoveryDialTimeout = 2 * time.Second
DefaultDiscoveryRequestTimeOut = 5 * time.Second
DefaultDiscoveryKeepAliveTime = 2 * time.Second
DefaultDiscoveryKeepAliveTimeOut = 6 * time.Second
DefaultDiscoveryInsecureTransport = true
DefaultSelfSignedCertValidity = 1
DefaultTLSMinVersion = string(tlsutil.TLSVersion12)

DefaultListenPeerURLs = "http://localhost:2380"
DefaultListenClientURLs = "http://localhost:2379"
Expand All @@ -96,10 +101,12 @@ const (
// Compress = false // compress the rotated log in gzip format
DefaultLogRotationConfig = `{"maxsize": 100, "maxage": 0, "maxbackups": 0, "localtime": false, "compress": false}`

// ExperimentalDistributedTracingAddress is the default collector address.
ExperimentalDistributedTracingAddress = "localhost:4317"
// ExperimentalDistributedTracingServiceName is the default etcd service name.
ExperimentalDistributedTracingServiceName = "etcd"
// DefaultExperimentalDistributedTracingAddress is the default collector address.
DefaultExperimentalDistributedTracingAddress = "localhost:4317"
// DefaultExperimentalDistributedTracingServiceName is the default etcd service name.
DefaultExperimentalDistributedTracingServiceName = "etcd"

DefaultExperimentalTxnModeWriteWithSharedBuffer = true

// DefaultStrictReconfigCheck is the default value for "--strict-reconfig-check" flag.
// It's enabled by default.
Expand Down Expand Up @@ -595,15 +602,18 @@ func NewConfig() *Config {
CORS: map[string]struct{}{"*": {}},
HostWhitelist: map[string]struct{}{"*": {}},

AuthToken: DefaultAuthToken,
BcryptCost: uint(bcrypt.DefaultCost),
AuthTokenTTL: 300,
AuthToken: DefaultAuthToken,
BcryptCost: uint(bcrypt.DefaultCost),
AuthTokenTTL: 300,
SelfSignedCertValidity: DefaultSelfSignedCertValidity,
TlsMinVersion: DefaultTLSMinVersion,

PreVote: true,

loggerMu: new(sync.RWMutex),
logger: nil,
Logger: "zap",
LogFormat: DefaultLoggingFormat,
LogOutputs: []string{DefaultLogOutput},
LogLevel: logutil.DefaultLogLevel,
EnableLogRotation: false,
Expand All @@ -615,7 +625,10 @@ func NewConfig() *Config {
ExperimentalStopGRPCServiceOnDefrag: false,
MaxLearners: membership.DefaultMaxLearners,
// TODO: delete in v3.7
ExperimentalMaxLearners: membership.DefaultMaxLearners,
ExperimentalMaxLearners: membership.DefaultMaxLearners,
ExperimentalTxnModeWriteWithSharedBuffer: DefaultExperimentalTxnModeWriteWithSharedBuffer,
ExperimentalDistributedTracingAddress: DefaultExperimentalDistributedTracingAddress,
ExperimentalDistributedTracingServiceName: DefaultExperimentalDistributedTracingServiceName,

CompactHashCheckTime: DefaultCompactHashCheckTime,
// TODO: delete in v3.7
Expand All @@ -630,14 +643,17 @@ func NewConfig() *Config {
KeepAliveTime: DefaultDiscoveryKeepAliveTime,
KeepAliveTimeout: DefaultDiscoveryKeepAliveTimeOut,

Secure: &clientv3.SecureConfig{},
Auth: &clientv3.AuthConfig{},
Secure: &clientv3.SecureConfig{
InsecureTransport: true,
},
Auth: &clientv3.AuthConfig{},
},
},

AutoCompactionMode: DefaultAutoCompactionMode,
ServerFeatureGate: features.NewDefaultServerFeatureGate(DefaultName, nil),
FlagsExplicitlySet: map[string]bool{},
AutoCompactionMode: DefaultAutoCompactionMode,
AutoCompactionRetention: DefaultAutoCompactionRetention,
ServerFeatureGate: features.NewDefaultServerFeatureGate(DefaultName, nil),
FlagsExplicitlySet: map[string]bool{},
}
cfg.InitialCluster = cfg.InitialClusterFromName(cfg.Name)
return cfg
Expand Down Expand Up @@ -785,8 +801,8 @@ func (cfg *Config) AddFlags(fs *flag.FlagSet) {

// experimental distributed tracing
fs.BoolVar(&cfg.ExperimentalEnableDistributedTracing, "experimental-enable-distributed-tracing", false, "Enable experimental distributed tracing using OpenTelemetry Tracing.")
fs.StringVar(&cfg.ExperimentalDistributedTracingAddress, "experimental-distributed-tracing-address", ExperimentalDistributedTracingAddress, "Address for distributed tracing used for OpenTelemetry Tracing (if enabled with experimental-enable-distributed-tracing flag).")
fs.StringVar(&cfg.ExperimentalDistributedTracingServiceName, "experimental-distributed-tracing-service-name", ExperimentalDistributedTracingServiceName, "Configures service name for distributed tracing to be used to define service name for OpenTelemetry Tracing (if enabled with experimental-enable-distributed-tracing flag). 'etcd' is the default service name. Use the same service name for all instances of etcd.")
fs.StringVar(&cfg.ExperimentalDistributedTracingAddress, "experimental-distributed-tracing-address", DefaultExperimentalDistributedTracingAddress, "Address for distributed tracing used for OpenTelemetry Tracing (if enabled with experimental-enable-distributed-tracing flag).")
fs.StringVar(&cfg.ExperimentalDistributedTracingServiceName, "experimental-distributed-tracing-service-name", DefaultExperimentalDistributedTracingServiceName, "Configures service name for distributed tracing to be used to define service name for OpenTelemetry Tracing (if enabled with experimental-enable-distributed-tracing flag). 'etcd' is the default service name. Use the same service name for all instances of etcd.")
fs.StringVar(&cfg.ExperimentalDistributedTracingServiceInstanceID, "experimental-distributed-tracing-instance-id", "", "Configures service instance ID for distributed tracing to be used to define service instance ID key for OpenTelemetry Tracing (if enabled with experimental-enable-distributed-tracing flag). There is no default value set. This ID must be unique per etcd instance.")
fs.IntVar(&cfg.ExperimentalDistributedTracingSamplingRatePerMillion, "experimental-distributed-tracing-sampling-rate", 0, "Number of samples to collect per million spans for OpenTelemetry Tracing (if enabled with experimental-enable-distributed-tracing flag).")

Expand Down
14 changes: 1 addition & 13 deletions server/embed/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
"sigs.k8s.io/yaml"

"go.etcd.io/etcd/client/pkg/v3/srv"
"go.etcd.io/etcd/client/pkg/v3/tlsutil"
"go.etcd.io/etcd/client/pkg/v3/transport"
"go.etcd.io/etcd/client/pkg/v3/types"
"go.etcd.io/etcd/pkg/v3/featuregate"
Expand Down Expand Up @@ -1051,19 +1050,8 @@ func TestMatchNewConfigAddFlags(t *testing.T) {
fs := flag.NewFlagSet("etcd", flag.ContinueOnError)
cfg.AddFlags(fs)
require.NoError(t, fs.Parse(nil))

newConfig := NewConfig()
// TODO: Remove the following assigments when both match.
newConfig.SelfSignedCertValidity = 1
newConfig.TlsMinVersion = string(tlsutil.TLSVersion12)
newConfig.DiscoveryCfg.Secure.InsecureTransport = true
newConfig.AutoCompactionRetention = "0"
newConfig.ExperimentalDistributedTracingAddress = "localhost:4317"
newConfig.ExperimentalDistributedTracingServiceName = "etcd"
newConfig.LogFormat = "json"
newConfig.ExperimentalTxnModeWriteWithSharedBuffer = true
// TODO: Reduce number of unexported fields set in config
if diff := cmp.Diff(newConfig, cfg, cmpopts.IgnoreUnexported(transport.TLSInfo{}, Config{}), cmp.Comparer(func(a, b featuregate.FeatureGate) bool {
if diff := cmp.Diff(NewConfig(), cfg, cmpopts.IgnoreUnexported(transport.TLSInfo{}, Config{}), cmp.Comparer(func(a, b featuregate.FeatureGate) bool {
return a.String() == b.String()
})); diff != "" {
t.Errorf("Diff: %s", diff)
Expand Down

0 comments on commit 663dfc9

Please sign in to comment.