Skip to content

Commit

Permalink
config: use pointer for plan_rejection_tracker.enabled
Browse files Browse the repository at this point in the history
Using a pointer allow us to differentiate between a non-set value and an
explicit `false` if we decide to use `true` by default.
  • Loading branch information
lgfa29 committed Jul 12, 2022
1 parent fb2e761 commit f5936f0
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
4 changes: 3 additions & 1 deletion command/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,9 @@ func convertServerConfig(agentConfig *Config) (*nomad.Config, error) {

// Set plan rejection tracker configuration.
if planRejectConf := agentConfig.Server.PlanRejectionTracker; planRejectConf != nil {
conf.NodePlanRejectionEnabled = planRejectConf.Enabled
if planRejectConf.Enabled != nil {
conf.NodePlanRejectionEnabled = *planRejectConf.Enabled
}
conf.NodePlanRejectionThreshold = planRejectConf.NodeThreshold

if planRejectConf.NodeWindow == 0 {
Expand Down
4 changes: 2 additions & 2 deletions command/agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,12 +386,12 @@ func TestAgent_ServerConfig_PlanRejectionTracker(t *testing.T) {
{
name: "valid config",
trackerConfig: &PlanRejectionTracker{
Enabled: true,
Enabled: helper.BoolToPtr(true),
NodeThreshold: 123,
NodeWindow: 17 * time.Minute,
},
expectedConfig: &PlanRejectionTracker{
Enabled: true,
Enabled: helper.BoolToPtr(true),
NodeThreshold: 123,
NodeWindow: 17 * time.Minute,
},
Expand Down
7 changes: 4 additions & 3 deletions command/agent/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ type RaftBoltConfig struct {
// tracker.
type PlanRejectionTracker struct {
// Enabled controls if the plan rejection tracker is active or not.
Enabled bool `hcl:"enabled"`
Enabled *bool `hcl:"enabled"`

// NodeThreshold is the number of times a node can have plan rejections
// before it is marked as ineligible.
Expand All @@ -582,8 +582,8 @@ func (p *PlanRejectionTracker) Merge(b *PlanRejectionTracker) *PlanRejectionTrac
return &result
}

if b.Enabled {
result.Enabled = true
if b.Enabled != nil {
result.Enabled = b.Enabled
}

if b.NodeThreshold != 0 {
Expand Down Expand Up @@ -1037,6 +1037,7 @@ func DefaultConfig() *Config {
RaftProtocol: 3,
StartJoin: []string{},
PlanRejectionTracker: &PlanRejectionTracker{
Enabled: helper.BoolToPtr(false),
NodeThreshold: 100,
NodeWindow: 5 * time.Minute,
},
Expand Down
2 changes: 1 addition & 1 deletion command/agent/config_parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ var basicConfig = &Config{
EnableEventBroker: helper.BoolToPtr(false),
EventBufferSize: helper.IntToPtr(200),
PlanRejectionTracker: &PlanRejectionTracker{
Enabled: true,
Enabled: helper.BoolToPtr(true),
NodeThreshold: 100,
NodeWindow: 41 * time.Minute,
NodeWindowHCL: "41m",
Expand Down
4 changes: 2 additions & 2 deletions command/agent/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func TestConfig_Merge(t *testing.T) {
EnableEventBroker: helper.BoolToPtr(false),
EventBufferSize: helper.IntToPtr(0),
PlanRejectionTracker: &PlanRejectionTracker{
Enabled: true,
Enabled: helper.BoolToPtr(true),
NodeThreshold: 100,
NodeWindow: 11 * time.Minute,
},
Expand Down Expand Up @@ -349,7 +349,7 @@ func TestConfig_Merge(t *testing.T) {
EnableEventBroker: helper.BoolToPtr(true),
EventBufferSize: helper.IntToPtr(100),
PlanRejectionTracker: &PlanRejectionTracker{
Enabled: true,
Enabled: helper.BoolToPtr(true),
NodeThreshold: 100,
NodeWindow: 11 * time.Minute,
},
Expand Down

0 comments on commit f5936f0

Please sign in to comment.