Skip to content

Commit

Permalink
ensure default value of 30s is set for server_join stanza
Browse files Browse the repository at this point in the history
  • Loading branch information
chelseakomlo committed May 29, 2018
1 parent 9343891 commit c4001a1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
4 changes: 4 additions & 0 deletions command/agent/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,10 @@ func (c *Command) Run(args []string) int {
}

if config.Client.Enabled && config.Client.ServerJoin != nil {
// COMPAT: Remove in 0.10 set the default RetryInterval value, as the
// ServerJoin stanza is not part of a default config for an agent.
config.Client.ServerJoin.RetryInterval = time.Duration(30) * time.Second

joiner := retryJoiner{
discover: &discover.Discover{},
errCh: c.retryJoinErrCh,
Expand Down
14 changes: 13 additions & 1 deletion command/agent/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,9 @@ func (a *ServerConfig) Merge(b *ServerConfig) *ServerConfig {
result.EncryptKey = b.EncryptKey
}
if b.ServerJoin != nil {
// // COMPAT: Remove in 0.10 - ServerJoin is not defined by default on an
// agent config, this should be eventually moved to DefaultConfig
result.ServerJoin = getDefaultServerJoin()
result.ServerJoin = result.ServerJoin.Merge(b.ServerJoin)
}

Expand All @@ -1135,6 +1138,12 @@ func (a *ServerConfig) Merge(b *ServerConfig) *ServerConfig {
return &result
}

func getDefaultServerJoin() *ServerJoin {
return &ServerJoin{
RetryInterval: time.Duration(30) * time.Second,
}
}

// Merge is used to merge two client configs together
func (a *ClientConfig) Merge(b *ClientConfig) *ClientConfig {
result := *a
Expand Down Expand Up @@ -1226,7 +1235,10 @@ func (a *ClientConfig) Merge(b *ClientConfig) *ClientConfig {
}

if b.ServerJoin != nil {
result.ServerJoin = b.ServerJoin
// // COMPAT: Remove in 0.10 - ServerJoin is not defined by default on an
// agent config, this should be eventually moved to DefaultConfig
result.ServerJoin = getDefaultServerJoin()
result.ServerJoin = result.ServerJoin.Merge(b.ServerJoin)
}

return &result
Expand Down
7 changes: 2 additions & 5 deletions command/agent/retry_join.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,8 @@ func (r *retryJoiner) Validate(config *Config) error {
if config.Server.RetryMaxAttempts != 0 {
return fmt.Errorf("server_join and retry_max cannot both be defined; try defining only server_join")
}
if config.Server.RetryInterval != "0" && config.Server.RetryInterval != "" {
// 30s is the default value that is set, ignore if this is the case
if config.Server.RetryInterval != "30s" {
return fmt.Errorf("server_join and retry_interval cannot both be defined; prefer setting the server_join parameter")
}
if config.Server.RetryInterval != "30s" {
return fmt.Errorf("server_join and retry_interval cannot both be defined; prefer setting the server_join parameter")
}

if len(config.Server.ServerJoin.RetryJoin) != 0 && len(config.Server.ServerJoin.StartJoin) != 0 {
Expand Down
2 changes: 1 addition & 1 deletion command/agent/retry_join_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ func TestRetryJoin_Validate(t *testing.T) {
},
StartJoin: []string{},
RetryMaxAttempts: 0,
RetryInterval: "0",
RetryInterval: "30s",
RetryJoin: []string{},
},
},
Expand Down

0 comments on commit c4001a1

Please sign in to comment.