drainer

package
v0.9.0-rc2 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2019 License: MPL-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// LimitStateQueriesPerSecond is the number of state queries allowed per
	// second
	LimitStateQueriesPerSecond = 100.0

	// BatchUpdateInterval is how long we wait to batch updates
	BatchUpdateInterval = 1 * time.Second

	// NodeDeadlineCoalesceWindow is the duration in which deadlining nodes will
	// be coalesced together
	NodeDeadlineCoalesceWindow = 5 * time.Second

	// NodeDrainEventComplete is used to indicate that the node drain is
	// finished.
	NodeDrainEventComplete = "Node drain complete"

	// NodeDrainEventDetailDeadlined is the key to use when the drain is
	// complete because a deadline. The acceptable values are "true" and "false"
	NodeDrainEventDetailDeadlined = "deadline_reached"
)

Variables

This section is empty.

Functions

func NewDeadlineHeap

func NewDeadlineHeap(ctx context.Context, coalesceWindow time.Duration) *deadlineHeap

NewDeadlineHeap returns a new deadline heap that coalesces for the given duration and will stop watching when the passed context is cancelled.

func NewDrainingJobWatcher

func NewDrainingJobWatcher(ctx context.Context, limiter *rate.Limiter, state *state.StateStore, logger log.Logger) *drainingJobWatcher

NewDrainingJobWatcher returns a new job watcher. The caller is expected to cancel the context to clean up the drainer.

func NewDrainingNode

func NewDrainingNode(node *structs.Node, state *state.StateStore) *drainingNode

func NewNodeDrainWatcher

func NewNodeDrainWatcher(ctx context.Context, limiter *rate.Limiter, state *state.StateStore, logger log.Logger, tracker NodeTracker) *nodeDrainWatcher

NewNodeDrainWatcher returns a new node drain watcher.

Types

type DrainDeadlineNotifier

type DrainDeadlineNotifier interface {
	// NextBatch returns the next batch of nodes that have reached their
	// deadline.
	NextBatch() <-chan []string

	// Remove removes the given node from being tracked for a deadline.
	Remove(nodeID string)

	// Watch marks the given node for being watched for its deadline.
	Watch(nodeID string, deadline time.Time)
}

DrainDeadlineNotifier allows batch notification of nodes that have reached their drain deadline.

func GetDeadlineNotifier

func GetDeadlineNotifier(ctx context.Context) DrainDeadlineNotifier

GetDeadlineNotifier returns a node deadline notifier with default coalescing.

type DrainDeadlineNotifierFactory

type DrainDeadlineNotifierFactory func(context.Context) DrainDeadlineNotifier

DrainDeadlineNotifierFactory returns a new DrainDeadlineNotifier

type DrainRequest

type DrainRequest struct {
	Allocs []*structs.Allocation
	Resp   *structs.BatchFuture
}

func NewDrainRequest

func NewDrainRequest(allocs []*structs.Allocation) *DrainRequest

type DrainingJobWatcher

type DrainingJobWatcher interface {
	// RegisterJob is used to start watching a draining job
	RegisterJobs(job []structs.NamespacedID)

	// Drain is used to emit allocations that should be drained.
	Drain() <-chan *DrainRequest

	// Migrated is allocations for draining jobs that have transitioned to
	// stop. There is no guarantee that duplicates won't be published.
	Migrated() <-chan []*structs.Allocation
}

DrainingJobWatcher is the interface for watching a job drain

func GetDrainingJobWatcher

func GetDrainingJobWatcher(ctx context.Context, limiter *rate.Limiter, state *state.StateStore, logger log.Logger) DrainingJobWatcher

GetDrainingJobWatcher returns a draining job watcher

type DrainingJobWatcherFactory

type DrainingJobWatcherFactory func(context.Context, *rate.Limiter, *state.StateStore, log.Logger) DrainingJobWatcher

DrainingJobWatcherFactory returns a new DrainingJobWatcher

type DrainingNodeWatcher

type DrainingNodeWatcher interface{}

DrainingNodeWatcher is the interface for watching for draining nodes.

type DrainingNodeWatcherFactory

type DrainingNodeWatcherFactory func(context.Context, *rate.Limiter, *state.StateStore, log.Logger, NodeTracker) DrainingNodeWatcher

DrainingNodeWatcherFactory returns a new DrainingNodeWatcher

func GetNodeWatcherFactory

func GetNodeWatcherFactory() DrainingNodeWatcherFactory

GetNodeWatcherFactory returns a DrainingNodeWatcherFactory

type MockNodeTracker

type MockNodeTracker struct {
	Nodes  map[string]*structs.Node
	Events []*MockNodeTrackerEvent
	sync.Mutex
}

func NewMockNodeTracker

func NewMockNodeTracker() *MockNodeTracker

func (*MockNodeTracker) Remove

func (m *MockNodeTracker) Remove(nodeID string)

func (*MockNodeTracker) TrackedNodes

func (m *MockNodeTracker) TrackedNodes() map[string]*structs.Node

func (*MockNodeTracker) Update

func (m *MockNodeTracker) Update(node *structs.Node)

type MockNodeTrackerEvent

type MockNodeTrackerEvent struct {
	NodeUpdate *structs.Node
	NodeRemove string
}

type NodeDrainer

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

NodeDrainer is used to orchestrate migrating allocations off of draining nodes.

func NewNodeDrainer

func NewNodeDrainer(c *NodeDrainerConfig) *NodeDrainer

NewNodeDrainer returns a new new node drainer. The node drainer is responsible for marking allocations on draining nodes with a desired migration transition, updating the drain strategy on nodes when they are complete and creating evaluations for the system to react to these changes.

func (*NodeDrainer) Remove

func (n *NodeDrainer) Remove(nodeID string)

Remove removes the given node from being tracked

func (*NodeDrainer) SetEnabled

func (n *NodeDrainer) SetEnabled(enabled bool, state *state.StateStore)

SetEnabled will start or stop the node draining goroutine depending on the enabled boolean.

func (*NodeDrainer) TrackedNodes

func (n *NodeDrainer) TrackedNodes() map[string]*structs.Node

TrackedNodes returns the set of tracked nodes

func (*NodeDrainer) Update

func (n *NodeDrainer) Update(node *structs.Node)

Update updates the node, either updating the tracked version or starting to track the node.

type NodeDrainerConfig

type NodeDrainerConfig struct {
	Logger               log.Logger
	Raft                 RaftApplier
	JobFactory           DrainingJobWatcherFactory
	NodeFactory          DrainingNodeWatcherFactory
	DrainDeadlineFactory DrainDeadlineNotifierFactory

	// StateQueriesPerSecond configures the query limit against the state store
	// that is allowed by the node drainer.
	StateQueriesPerSecond float64

	// BatchUpdateInterval is the interval in which allocation updates are
	// batched.
	BatchUpdateInterval time.Duration
}

NodeDrainerConfig is used to configure a new node drainer.

type NodeTracker

type NodeTracker interface {
	// TrackedNodes returns all the nodes that are currently tracked as
	// draining.
	TrackedNodes() map[string]*structs.Node

	// Remove removes a node from the draining set.
	Remove(nodeID string)

	// Update either updates the specification of a draining node or tracks the
	// node as draining.
	Update(node *structs.Node)
}

NodeTracker is the interface to notify an object that is tracking draining nodes of changes

type RaftApplier

type RaftApplier interface {
	AllocUpdateDesiredTransition(allocs map[string]*structs.DesiredTransition, evals []*structs.Evaluation) (uint64, error)
	NodesDrainComplete(nodes []string, event *structs.NodeEvent) (uint64, error)
}

RaftApplier contains methods for applying the raft requests required by the NodeDrainer.

Jump to

Keyboard shortcuts

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