Skip to content

Commit

Permalink
[dbnode] Default HostID and Discovery config for minimal config (#2876)
Browse files Browse the repository at this point in the history
  • Loading branch information
robskillington committed Nov 12, 2020
1 parent 251dc3d commit a0a96a7
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 39 deletions.
46 changes: 37 additions & 9 deletions src/cmd/services/m3dbnode/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,16 @@ var (
SamplingRate: 1.0,
ExtendedMetrics: &defaultMetricsExtendedMetricsType,
}
defaultListenAddress = "0.0.0.0:9000"
defaultClusterListenAddress = "0.0.0.0:9001"
defaultHTTPNodeListenAddress = "0.0.0.0:9002"
defaultHTTPClusterListenAddress = "0.0.0.0:9003"
defaultDebugListenAddress = "0.0.0.0:9004"
defaultListenAddress = "0.0.0.0:9000"
defaultClusterListenAddress = "0.0.0.0:9001"
defaultHTTPNodeListenAddress = "0.0.0.0:9002"
defaultHTTPClusterListenAddress = "0.0.0.0:9003"
defaultDebugListenAddress = "0.0.0.0:9004"
defaultHostIDValue = "m3db_local"
defaultHostID = hostid.Configuration{
Resolver: hostid.ConfigResolver,
Value: &defaultHostIDValue,
}
defaultGCPercentage = 100
defaultWriteNewSeriesAsync = true
defaultWriteNewSeriesBackoffDuration = 2 * time.Millisecond
Expand All @@ -82,6 +87,10 @@ var (
CalculationType: CalculationTypeFixed,
},
}
defaultDiscoveryType = discovery.M3DBSingleNodeType
defaultDiscovery = discovery.Configuration{
Type: &defaultDiscoveryType,
}
)

// Configuration is the top level configuration that includes both a DB
Expand Down Expand Up @@ -130,7 +139,7 @@ type DBConfiguration struct {
DebugListenAddress *string `yaml:"debugListenAddress"`

// HostID is the local host ID configuration.
HostID hostid.Configuration `yaml:"hostID"`
HostID *hostid.Configuration `yaml:"hostID"`

// Client configuration, used for inter-node communication and when used as a coordinator.
Client client.Configuration `yaml:"client"`
Expand Down Expand Up @@ -166,7 +175,7 @@ type DBConfiguration struct {
PoolingPolicy *PoolingPolicy `yaml:"pooling"`

// The discovery configuration.
DiscoveryConfig discovery.Configuration `yaml:"discovery"`
Discovery *discovery.Configuration `yaml:"discovery"`

// The configuration for hashing
Hashing HashingConfiguration `yaml:"hashing"`
Expand Down Expand Up @@ -262,6 +271,15 @@ func (c *DBConfiguration) DebugListenAddressOrDefault() string {
return *c.DebugListenAddress
}

// HostIDOrDefault returns the host ID or default.
func (c *DBConfiguration) HostIDOrDefault() hostid.Configuration {
if c.HostID == nil {
return defaultHostID
}

return *c.HostID
}

// CommitLogOrDefault returns the commit log policy or default.
func (c *DBConfiguration) CommitLogOrDefault() CommitLogPolicy {
if c.CommitLog == nil {
Expand Down Expand Up @@ -312,6 +330,15 @@ func (c *DBConfiguration) PoolingPolicyOrDefault() (PoolingPolicy, error) {
return policy, nil
}

// DiscoveryOrDefault returns the discovery configuration or defaults.
func (c *DBConfiguration) DiscoveryOrDefault() discovery.Configuration {
if c.Discovery == nil {
return defaultDiscovery
}

return *c.Discovery
}

// Validate validates the Configuration. We use this method to validate fields
// where the validator package falls short.
func (c *DBConfiguration) Validate() error {
Expand Down Expand Up @@ -589,12 +616,13 @@ func (c *ProtoConfiguration) Validate() error {
func NewEtcdEmbedConfig(cfg DBConfiguration) (*embed.Config, error) {
newKVCfg := embed.NewConfig()

hostID, err := cfg.HostID.Resolve()
hostID, err := cfg.HostIDOrDefault().Resolve()
if err != nil {
return nil, fmt.Errorf("failed resolving hostID %w", err)
}

envCfg, err := cfg.DiscoveryConfig.EnvironmentConfig(hostID)
discoveryCfg := cfg.DiscoveryOrDefault()
envCfg, err := discoveryCfg.EnvironmentConfig(hostID)
if err != nil {
return nil, fmt.Errorf("failed getting env config from discovery config %w", err)
}
Expand Down
3 changes: 2 additions & 1 deletion src/cmd/services/m3dbnode/main/main_index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ func TestIndexEnabledServer(t *testing.T) {
err = xconfig.LoadFile(&cfg, configFd.Name(), xconfig.Options{})
require.NoError(t, err)

envCfg, err := cfg.DB.DiscoveryConfig.EnvironmentConfig(hostID)
discoveryCfg := cfg.DB.DiscoveryOrDefault()
envCfg, err := discoveryCfg.EnvironmentConfig(hostID)
require.NoError(t, err)

syncCluster, err := envCfg.Services.SyncCluster()
Expand Down
6 changes: 4 additions & 2 deletions src/cmd/services/m3dbnode/main/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ func TestConfig(t *testing.T) {
err = xconfig.LoadFile(&cfg, configFd.Name(), xconfig.Options{})
require.NoError(t, err)

envCfg, err := cfg.DB.DiscoveryConfig.EnvironmentConfig(hostID)
discoveryCfg := cfg.DB.DiscoveryOrDefault()
envCfg, err := discoveryCfg.EnvironmentConfig(hostID)
require.NoError(t, err)

syncCluster, err := envCfg.Services.SyncCluster()
Expand Down Expand Up @@ -337,7 +338,8 @@ func TestEmbeddedConfig(t *testing.T) {
err = xconfig.LoadFile(&cfg, configFd.Name(), xconfig.Options{})
require.NoError(t, err)

envCfg, err := cfg.DB.DiscoveryConfig.EnvironmentConfig(hostID)
discoveryCfg := cfg.DB.DiscoveryOrDefault()
envCfg, err := discoveryCfg.EnvironmentConfig(hostID)
require.NoError(t, err)

syncCluster, err := envCfg.Services.SyncCluster()
Expand Down
7 changes: 0 additions & 7 deletions src/dbnode/config/m3dbnode-local-etcd-proto.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
coordinator: {}

db:
hostID:
resolver: config
value: m3db_local

discovery:
type: m3db_single_node

proto:
enabled: true
schema_registry:
Expand Down
15 changes: 1 addition & 14 deletions src/dbnode/config/m3dbnode-local-etcd.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,2 @@
coordinator: {}

db:
hostID:
resolver: config
value: m3db_local

discovery:
type: m3db_single_node

# un-comment the lines below to enable Jaeger tracing. See https://www.jaegertracing.io/docs/1.9/getting-started/
# for quick local setup (which this config will send data to).

# tracing:
# backend: jaeger
db: {}
5 changes: 3 additions & 2 deletions src/dbnode/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ func Run(runOpts RunOptions) {
logger.Fatal("could not connect to metrics", zap.Error(err))
}

hostID, err := cfg.HostID.Resolve()
hostID, err := cfg.HostIDOrDefault().Resolve()
if err != nil {
logger.Fatal("could not resolve local host ID", zap.Error(err))
}
Expand Down Expand Up @@ -268,7 +268,8 @@ func Run(runOpts RunOptions) {
}

// Presence of KV server config indicates embedded etcd cluster
envConfig, err := cfg.DiscoveryConfig.EnvironmentConfig(hostID)
discoveryConfig := cfg.DiscoveryOrDefault()
envConfig, err := discoveryConfig.EnvironmentConfig(hostID)
if err != nil {
logger.Fatal("could not get env config from discovery config", zap.Error(err))
}
Expand Down
10 changes: 6 additions & 4 deletions src/query/server/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,13 +436,14 @@ func Run(runOpts RunOptions) {

var serviceOptionDefaults []handleroptions.ServiceOptionsDefault
if dbCfg := runOpts.DBConfig; dbCfg != nil {
hostID, err := dbCfg.HostID.Resolve()
hostID, err := dbCfg.HostIDOrDefault().Resolve()
if err != nil {
logger.Fatal("could not resolve hostID",
zap.Error(err))
}

envCfg, err := dbCfg.DiscoveryConfig.EnvironmentConfig(hostID)
discoveryCfg := dbCfg.DiscoveryOrDefault()
envCfg, err := discoveryCfg.EnvironmentConfig(hostID)
if err != nil {
logger.Fatal("could not get env config from discovery config",
zap.Error(err))
Expand Down Expand Up @@ -826,13 +827,14 @@ func initClusters(
return nil, nil, nil, errors.New("environment config required when dynamically fetching namespaces")
}

hostID, err := dbCfg.HostID.Resolve()
hostID, err := dbCfg.HostIDOrDefault().Resolve()
if err != nil {
logger.Fatal("could not resolve hostID",
zap.Error(err))
}

envCfg, err := dbCfg.DiscoveryConfig.EnvironmentConfig(hostID)
discoveryCfg := dbCfg.DiscoveryOrDefault()
envCfg, err := discoveryCfg.EnvironmentConfig(hostID)
if err != nil {
logger.Fatal("could not get env config from discovery config",
zap.Error(err))
Expand Down

0 comments on commit a0a96a7

Please sign in to comment.