Skip to content

Commit

Permalink
Merge pull request #7171 from hashicorp/update-autopilot-20200214
Browse files Browse the repository at this point in the history
Update consul vendor and add MinQuorum flag
  • Loading branch information
Mahmood Ali authored Feb 19, 2020
2 parents 40bb81d + a3b0b25 commit 90381d8
Show file tree
Hide file tree
Showing 87 changed files with 4,021 additions and 533 deletions.
4 changes: 4 additions & 0 deletions api/operator_autopilot.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ type AutopilotConfiguration struct {
// be behind before being considered unhealthy.
MaxTrailingLogs uint64

// MinQuorum sets the minimum number of servers allowed in a cluster before
// autopilot can prune dead servers.
MinQuorum uint

// ServerStabilizationTime is the minimum amount of time a server must be
// in a stable, healthy state before it can be added to the cluster. Only
// applicable with Raft protocol version 3 or higher.
Expand Down
2 changes: 1 addition & 1 deletion client/allocrunner/groupservice_hook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"time"

consulapi "github.com/hashicorp/consul/api"
ctestutil "github.com/hashicorp/consul/testutil"
ctestutil "github.com/hashicorp/consul/sdk/testutil"
"github.com/hashicorp/nomad/client/allocrunner/interfaces"
"github.com/hashicorp/nomad/client/consul"
"github.com/hashicorp/nomad/client/taskenv"
Expand Down
2 changes: 1 addition & 1 deletion client/allocrunner/taskrunner/envoybootstrap_hook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"testing"

consulapi "github.com/hashicorp/consul/api"
consultest "github.com/hashicorp/consul/testutil"
consultest "github.com/hashicorp/consul/sdk/testutil"
"github.com/hashicorp/nomad/client/allocdir"
"github.com/hashicorp/nomad/client/allocrunner/interfaces"
"github.com/hashicorp/nomad/client/taskenv"
Expand Down
2 changes: 1 addition & 1 deletion client/allocrunner/taskrunner/template/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"testing"
"time"

ctestutil "github.com/hashicorp/consul/testutil"
ctestutil "github.com/hashicorp/consul/sdk/testutil"
"github.com/hashicorp/nomad/client/config"
"github.com/hashicorp/nomad/client/taskenv"
"github.com/hashicorp/nomad/helper"
Expand Down
3 changes: 3 additions & 0 deletions command/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ func convertServerConfig(agentConfig *Config) (*nomad.Config, error) {
if agentConfig.Autopilot.MaxTrailingLogs != 0 {
conf.AutopilotConfig.MaxTrailingLogs = uint64(agentConfig.Autopilot.MaxTrailingLogs)
}
if agentConfig.Autopilot.MinQuorum != 0 {
conf.AutopilotConfig.MinQuorum = uint(agentConfig.Autopilot.MinQuorum)
}
if agentConfig.Autopilot.EnableRedundancyZones != nil {
conf.AutopilotConfig.EnableRedundancyZones = *agentConfig.Autopilot.EnableRedundancyZones
}
Expand Down
1 change: 1 addition & 0 deletions command/agent/config_parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ var basicConfig = &Config{
LastContactThreshold: 12705 * time.Second,
LastContactThresholdHCL: "12705s",
MaxTrailingLogs: 17849,
MinQuorum: 3,
EnableRedundancyZones: &trueValue,
DisableUpgradeMigration: &trueValue,
EnableCustomUpgrades: &trueValue,
Expand Down
2 changes: 2 additions & 0 deletions command/agent/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ func TestConfig_Merge(t *testing.T) {
ServerStabilizationTime: 1 * time.Second,
LastContactThreshold: 1 * time.Second,
MaxTrailingLogs: 1,
MinQuorum: 1,
EnableRedundancyZones: &falseValue,
DisableUpgradeMigration: &falseValue,
EnableCustomUpgrades: &falseValue,
Expand Down Expand Up @@ -365,6 +366,7 @@ func TestConfig_Merge(t *testing.T) {
ServerStabilizationTime: 2 * time.Second,
LastContactThreshold: 2 * time.Second,
MaxTrailingLogs: 2,
MinQuorum: 2,
EnableRedundancyZones: &trueValue,
DisableUpgradeMigration: &trueValue,
EnableCustomUpgrades: &trueValue,
Expand Down
2 changes: 1 addition & 1 deletion command/agent/consul/group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/hashicorp/consul/api"
consulapi "github.com/hashicorp/consul/api"
"github.com/hashicorp/consul/testutil"
"github.com/hashicorp/consul/sdk/testutil"
"github.com/hashicorp/nomad/helper/testlog"
"github.com/hashicorp/nomad/nomad/mock"
"github.com/hashicorp/nomad/nomad/structs"
Expand Down
2 changes: 1 addition & 1 deletion command/agent/consul/int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"time"

consulapi "github.com/hashicorp/consul/api"
"github.com/hashicorp/consul/testutil"
"github.com/hashicorp/consul/sdk/testutil"
log "github.com/hashicorp/go-hclog"
"github.com/hashicorp/nomad/client/allocdir"
"github.com/hashicorp/nomad/client/allocrunner/taskrunner"
Expand Down
2 changes: 2 additions & 0 deletions command/agent/operator_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ func (s *HTTPServer) OperatorAutopilotConfiguration(resp http.ResponseWriter, re
CleanupDeadServers: reply.CleanupDeadServers,
LastContactThreshold: reply.LastContactThreshold,
MaxTrailingLogs: reply.MaxTrailingLogs,
MinQuorum: reply.MinQuorum,
ServerStabilizationTime: reply.ServerStabilizationTime,
EnableRedundancyZones: reply.EnableRedundancyZones,
DisableUpgradeMigration: reply.DisableUpgradeMigration,
Expand All @@ -131,6 +132,7 @@ func (s *HTTPServer) OperatorAutopilotConfiguration(resp http.ResponseWriter, re
CleanupDeadServers: conf.CleanupDeadServers,
LastContactThreshold: conf.LastContactThreshold,
MaxTrailingLogs: conf.MaxTrailingLogs,
MinQuorum: conf.MinQuorum,
ServerStabilizationTime: conf.ServerStabilizationTime,
EnableRedundancyZones: conf.EnableRedundancyZones,
DisableUpgradeMigration: conf.DisableUpgradeMigration,
Expand Down
2 changes: 1 addition & 1 deletion command/agent/operator_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"testing"
"time"

"github.com/hashicorp/consul/testutil/retry"
"github.com/hashicorp/consul/sdk/testutil/retry"
"github.com/hashicorp/nomad/api"
"github.com/hashicorp/nomad/nomad/structs"
"github.com/stretchr/testify/assert"
Expand Down
1 change: 1 addition & 0 deletions command/agent/testdata/basic.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ autopilot {
disable_upgrade_migration = true
last_contact_threshold = "12705s"
max_trailing_logs = 17849
min_quorum = 3
enable_redundancy_zones = true
server_stabilization_time = "23057s"
enable_custom_upgrades = true
Expand Down
1 change: 1 addition & 0 deletions command/agent/testdata/basic.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"enable_redundancy_zones": true,
"last_contact_threshold": "12705s",
"max_trailing_logs": 17849,
"min_quorum": 3,
"server_stabilization_time": "23057s"
}
],
Expand Down
1 change: 1 addition & 0 deletions command/operator_autopilot_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func (c *OperatorAutopilotGetCommand) Run(args []string) int {
c.Ui.Output(fmt.Sprintf("CleanupDeadServers = %v", config.CleanupDeadServers))
c.Ui.Output(fmt.Sprintf("LastContactThreshold = %v", config.LastContactThreshold.String()))
c.Ui.Output(fmt.Sprintf("MaxTrailingLogs = %v", config.MaxTrailingLogs))
c.Ui.Output(fmt.Sprintf("MinQuorum = %v", config.MinQuorum))
c.Ui.Output(fmt.Sprintf("ServerStabilizationTime = %v", config.ServerStabilizationTime.String()))
c.Ui.Output(fmt.Sprintf("EnableRedundancyZones = %v", config.EnableRedundancyZones))
c.Ui.Output(fmt.Sprintf("DisableUpgradeMigration = %v", config.DisableUpgradeMigration))
Expand Down
7 changes: 7 additions & 0 deletions command/operator_autopilot_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func (c *OperatorAutopilotSetCommand) Name() string { return "operator autopilot
func (c *OperatorAutopilotSetCommand) Run(args []string) int {
var cleanupDeadServers flags.BoolValue
var maxTrailingLogs flags.UintValue
var minQuorum flags.UintValue
var lastContactThreshold flags.DurationValue
var serverStabilizationTime flags.DurationValue
var enableRedundancyZones flags.BoolValue
Expand All @@ -50,6 +51,7 @@ func (c *OperatorAutopilotSetCommand) Run(args []string) int {
f.Var(&enableRedundancyZones, "enable-redundancy-zones", "")
f.Var(&disableUpgradeMigration, "disable-upgrade-migration", "")
f.Var(&enableCustomUpgrades, "enable-custom-upgrades", "")
f.Var(&minQuorum, "min-quorum", "")

if err := f.Parse(args); err != nil {
c.Ui.Error(fmt.Sprintf("Failed to parse args: %v", err))
Expand Down Expand Up @@ -80,6 +82,7 @@ func (c *OperatorAutopilotSetCommand) Run(args []string) int {
trailing := uint(conf.MaxTrailingLogs)
maxTrailingLogs.Merge(&trailing)
conf.MaxTrailingLogs = uint64(trailing)
minQuorum.Merge(&conf.MinQuorum)
lastContactThreshold.Merge(&conf.LastContactThreshold)
serverStabilizationTime.Merge(&conf.ServerStabilizationTime)

Expand Down Expand Up @@ -131,6 +134,10 @@ Set Config Options:
Controls the maximum number of log entries that a server can trail
the leader by before being considered unhealthy.
-min-quorum=<value>
Controls the minimum number of servers required in a cluster
before autopilot can prune dead servers.
-redundancy-zone-tag=<value>
(Enterprise-only) Controls the node_meta tag name used for
separating servers into different redundancy zones.
Expand Down
2 changes: 2 additions & 0 deletions command/operator_autopilot_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func TestOperatorAutopilotSetConfigCommand(t *testing.T) {
"-address=" + addr,
"-cleanup-dead-servers=false",
"-max-trailing-logs=99",
"-min-quorum=3",
"-last-contact-threshold=123ms",
"-server-stabilization-time=123ms",
"-enable-redundancy-zones=true",
Expand All @@ -46,6 +47,7 @@ func TestOperatorAutopilotSetConfigCommand(t *testing.T) {

require.False(conf.CleanupDeadServers)
require.EqualValues(99, conf.MaxTrailingLogs)
require.EqualValues(3, conf.MinQuorum)
require.EqualValues(123*time.Millisecond, conf.LastContactThreshold)
require.EqualValues(123*time.Millisecond, conf.ServerStabilizationTime)
require.True(conf.EnableRedundancyZones)
Expand Down
2 changes: 1 addition & 1 deletion helper/freeport/freeport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"sync"
"testing"

"github.com/hashicorp/consul/testutil/retry"
"github.com/hashicorp/consul/sdk/testutil/retry"
)

// reset will reverse the setup from initialize() and then redo it (for tests)
Expand Down
2 changes: 1 addition & 1 deletion internal/testing/apitests/operator_autopilot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"fmt"

"github.com/hashicorp/consul/testutil/retry"
"github.com/hashicorp/consul/sdk/testutil/retry"
"github.com/hashicorp/nomad/api"
"github.com/hashicorp/nomad/testutil"
"github.com/stretchr/testify/require"
Expand Down
2 changes: 1 addition & 1 deletion internal/testing/apitests/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package apitests
import (
"testing"

"github.com/hashicorp/consul/testutil/retry"
"github.com/hashicorp/consul/sdk/testutil/retry"
"github.com/hashicorp/nomad/api"
"github.com/stretchr/testify/require"
)
Expand Down
8 changes: 7 additions & 1 deletion nomad/autopilot.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func (d *AutopilotDelegate) AutopilotConfig() *autopilot.Config {
CleanupDeadServers: c.CleanupDeadServers,
LastContactThreshold: c.LastContactThreshold,
MaxTrailingLogs: c.MaxTrailingLogs,
MinQuorum: c.MinQuorum,
ServerStabilizationTime: c.ServerStabilizationTime,
DisableUpgradeMigration: c.DisableUpgradeMigration,
ModifyIndex: c.ModifyIndex,
Expand Down Expand Up @@ -96,6 +97,11 @@ func (d *AutopilotDelegate) Raft() *raft.Raft {
return d.server.raft
}

func (d *AutopilotDelegate) Serf() *serf.Serf {
func (d *AutopilotDelegate) SerfLAN() *serf.Serf {
return d.server.serf
}

func (d *AutopilotDelegate) SerfWAN() *serf.Serf {
// serf WAN isn't supported in nomad yet
return nil
}
2 changes: 1 addition & 1 deletion nomad/autopilot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"fmt"

"github.com/hashicorp/consul/agent/consul/autopilot"
"github.com/hashicorp/consul/testutil/retry"
"github.com/hashicorp/consul/sdk/testutil/retry"
"github.com/hashicorp/nomad/testutil"
"github.com/hashicorp/raft"
"github.com/hashicorp/serf/serf"
Expand Down
4 changes: 4 additions & 0 deletions nomad/fsm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3033,6 +3033,7 @@ func TestFSM_Autopilot(t *testing.T) {
CleanupDeadServers: true,
LastContactThreshold: 10 * time.Second,
MaxTrailingLogs: 300,
MinQuorum: 3,
},
}
buf, err := structs.Encode(structs.AutopilotRequestType, req)
Expand All @@ -3058,6 +3059,9 @@ func TestFSM_Autopilot(t *testing.T) {
if config.MaxTrailingLogs != req.Config.MaxTrailingLogs {
t.Fatalf("bad: %v", config.MaxTrailingLogs)
}
if config.MinQuorum != req.Config.MinQuorum {
t.Fatalf("bad: %v", config.MinQuorum)
}

// Now use CAS and provide an old index
req.CAS = true
Expand Down
2 changes: 1 addition & 1 deletion nomad/leader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"testing"
"time"

"github.com/hashicorp/consul/testutil/retry"
"github.com/hashicorp/consul/sdk/testutil/retry"
"github.com/hashicorp/go-hclog"
memdb "github.com/hashicorp/go-memdb"
"github.com/hashicorp/go-version"
Expand Down
3 changes: 1 addition & 2 deletions nomad/server_setup_oss.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ package nomad

import (
"github.com/hashicorp/consul/agent/consul/autopilot"
log "github.com/hashicorp/go-hclog"
)

type EnterpriseState struct{}

func (s *Server) setupEnterprise(config *Config) error {
// Set up the OSS version of autopilot
apDelegate := &AutopilotDelegate{s}
s.autopilot = autopilot.NewAutopilot(s.logger.StandardLoggerIntercept(&log.StandardLoggerOptions{InferLevels: true}), apDelegate, config.AutopilotInterval, config.ServerHealthInterval)
s.autopilot = autopilot.NewAutopilot(s.logger, apDelegate, config.AutopilotInterval, config.ServerHealthInterval)

return nil
}
Expand Down
1 change: 1 addition & 0 deletions nomad/state/autopilot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func TestStateStore_Autopilot(t *testing.T) {
CleanupDeadServers: true,
LastContactThreshold: 5 * time.Second,
MaxTrailingLogs: 500,
MinQuorum: 3,
ServerStabilizationTime: 100 * time.Second,
EnableRedundancyZones: true,
DisableUpgradeMigration: true,
Expand Down
7 changes: 7 additions & 0 deletions nomad/structs/config/autopilot.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ type AutopilotConfig struct {
// be behind before being considered unhealthy.
MaxTrailingLogs int `hcl:"max_trailing_logs"`

// MinQuorum sets the minimum number of servers required in a cluster
// before autopilot can prune dead servers.
MinQuorum int `hcl:"min_quorum"`

// (Enterprise-only) EnableRedundancyZones specifies whether to enable redundancy zones.
EnableRedundancyZones *bool `hcl:"enable_redundancy_zones"`

Expand Down Expand Up @@ -73,6 +77,9 @@ func (a *AutopilotConfig) Merge(b *AutopilotConfig) *AutopilotConfig {
if b.MaxTrailingLogs != 0 {
result.MaxTrailingLogs = b.MaxTrailingLogs
}
if b.MinQuorum != 0 {
result.MinQuorum = b.MinQuorum
}
if b.EnableRedundancyZones != nil {
result.EnableRedundancyZones = b.EnableRedundancyZones
}
Expand Down
3 changes: 3 additions & 0 deletions nomad/structs/config/autopilot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ func TestAutopilotConfig_Merge(t *testing.T) {
ServerStabilizationTime: 1 * time.Second,
LastContactThreshold: 1 * time.Second,
MaxTrailingLogs: 1,
MinQuorum: 1,
EnableRedundancyZones: &trueValue,
DisableUpgradeMigration: &falseValue,
EnableCustomUpgrades: &trueValue,
Expand All @@ -24,6 +25,7 @@ func TestAutopilotConfig_Merge(t *testing.T) {
ServerStabilizationTime: 2 * time.Second,
LastContactThreshold: 2 * time.Second,
MaxTrailingLogs: 2,
MinQuorum: 2,
EnableRedundancyZones: nil,
DisableUpgradeMigration: nil,
EnableCustomUpgrades: nil,
Expand All @@ -34,6 +36,7 @@ func TestAutopilotConfig_Merge(t *testing.T) {
ServerStabilizationTime: 2 * time.Second,
LastContactThreshold: 2 * time.Second,
MaxTrailingLogs: 2,
MinQuorum: 2,
EnableRedundancyZones: &trueValue,
DisableUpgradeMigration: &falseValue,
EnableCustomUpgrades: &trueValue,
Expand Down
4 changes: 4 additions & 0 deletions nomad/structs/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ type AutopilotConfig struct {
// be behind before being considered unhealthy.
MaxTrailingLogs uint64

// MinQuorum sets the minimum number of servers required in a cluster
// before autopilot can prune dead servers.
MinQuorum uint

// (Enterprise-only) EnableRedundancyZones specifies whether to enable redundancy zones.
EnableRedundancyZones bool

Expand Down
Loading

0 comments on commit 90381d8

Please sign in to comment.