autopilot

package
v1.8.0-beta1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2020 License: MPL-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsPotentialVoter

func IsPotentialVoter(suffrage raft.ServerSuffrage) bool

func NumPeers

func NumPeers(raftConfig raft.Configuration) int

NumPeers counts the number of voting peers in the given raft config.

func PromoteStableServers

func PromoteStableServers(autopilotConfig *Config, health OperatorHealthReply, servers []raft.Server) []raft.Server

PromoteStableServers is a basic autopilot promotion policy that promotes any server which has been healthy and stable for the duration specified in the given Autopilot config.

Types

type Autopilot

type Autopilot struct {
	// contains filtered or unexported fields
}

Autopilot is a mechanism for automatically managing the Raft quorum using server health information along with updates from Serf gossip. For more information, see https://www.consul.io/docs/guides/autopilot.html

func NewAutopilot

func NewAutopilot(logger hclog.Logger, delegate Delegate, interval, healthInterval time.Duration) *Autopilot

func (*Autopilot) GetClusterHealth

func (a *Autopilot) GetClusterHealth() OperatorHealthReply

func (*Autopilot) GetServerHealth

func (a *Autopilot) GetServerHealth(id string) *ServerHealth

func (*Autopilot) MinRaftProtocol

func (a *Autopilot) MinRaftProtocol() (int, error)

MinRaftProtocol returns the lowest supported Raft protocol among alive servers

func (*Autopilot) RemoveDeadServers

func (a *Autopilot) RemoveDeadServers()

RemoveDeadServers triggers a pruning of dead servers in a non-blocking way.

func (*Autopilot) Start

func (a *Autopilot) Start()

func (*Autopilot) Stop

func (a *Autopilot) Stop()

type Config

type Config struct {
	// CleanupDeadServers controls whether to remove dead servers when a new
	// server is added to the Raft peers.
	CleanupDeadServers bool

	// LastContactThreshold is the limit on the amount of time a server can go
	// without leader contact before being considered unhealthy.
	LastContactThreshold time.Duration

	// MaxTrailingLogs is the amount of entries in the Raft Log that a server can
	// 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

	// 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.
	ServerStabilizationTime time.Duration

	// (Enterprise-only) RedundancyZoneTag is the node tag to use for separating
	// servers into zones for redundancy. If left blank, this feature will be disabled.
	RedundancyZoneTag string

	// (Enterprise-only) DisableUpgradeMigration will disable Autopilot's upgrade migration
	// strategy of waiting until enough newer-versioned servers have been added to the
	// cluster before promoting them to voters.
	DisableUpgradeMigration bool

	// (Enterprise-only) UpgradeVersionTag is the node tag to use for version info when
	// performing upgrade migrations. If left blank, the Consul version will be used.
	UpgradeVersionTag string

	// CreateIndex/ModifyIndex store the create/modify indexes of this configuration.
	CreateIndex uint64
	ModifyIndex uint64
}

Config holds the Autopilot configuration for a cluster.

type Delegate

type Delegate interface {
	AutopilotConfig() *Config
	FetchStats(context.Context, []serf.Member) map[string]*ServerStats
	IsServer(serf.Member) (*ServerInfo, error)
	NotifyHealth(OperatorHealthReply)
	PromoteNonVoters(*Config, OperatorHealthReply) ([]raft.Server, error)
	Raft() *raft.Raft
	SerfLAN() *serf.Serf
	SerfWAN() *serf.Serf
}

Delegate is the interface for the Autopilot mechanism

type OperatorHealthReply

type OperatorHealthReply struct {
	// Healthy is true if all the servers in the cluster are healthy.
	Healthy bool

	// FailureTolerance is the number of healthy servers that could be lost without
	// an outage occurring.
	FailureTolerance int

	// Servers holds the health of each server.
	Servers []ServerHealth
}

OperatorHealthReply is a representation of the overall health of the cluster

func (*OperatorHealthReply) ServerHealth

func (o *OperatorHealthReply) ServerHealth(id string) *ServerHealth

type ServerHealth

type ServerHealth struct {
	// ID is the raft ID of the server.
	ID string

	// Name is the node name of the server.
	Name string

	// Address is the address of the server.
	Address string

	// The status of the SerfHealth check for the server.
	SerfStatus serf.MemberStatus

	// Version is the version of the server.
	Version string

	// Leader is whether this server is currently the leader.
	Leader bool

	// LastContact is the time since this node's last contact with the leader.
	LastContact time.Duration

	// LastTerm is the highest leader term this server has a record of in its Raft log.
	LastTerm uint64

	// LastIndex is the last log index this server has a record of in its Raft log.
	LastIndex uint64

	// Healthy is whether or not the server is healthy according to the current
	// Autopilot config.
	Healthy bool

	// Voter is whether this is a voting server.
	Voter bool

	// StableSince is the last time this server's Healthy value changed.
	StableSince time.Time
}

ServerHealth is the health (from the leader's point of view) of a server.

func (*ServerHealth) IsHealthy

func (h *ServerHealth) IsHealthy(lastTerm uint64, leaderLastIndex uint64, autopilotConf *Config) bool

IsHealthy determines whether this ServerHealth is considered healthy based on the given Autopilot config

func (*ServerHealth) IsStable

func (h *ServerHealth) IsStable(now time.Time, conf *Config) bool

IsStable returns true if the ServerHealth shows a stable, passing state according to the given AutopilotConfig

type ServerInfo

type ServerInfo struct {
	Name   string
	ID     string
	Addr   net.Addr
	Build  version.Version
	Status serf.MemberStatus
}

type ServerStats

type ServerStats struct {
	// LastContact is the time since this node's last contact with the leader.
	LastContact string

	// LastTerm is the highest leader term this server has a record of in its Raft log.
	LastTerm uint64

	// LastIndex is the last log index this server has a record of in its Raft log.
	LastIndex uint64
}

ServerStats holds miscellaneous Raft metrics for a server

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL