Documentation ¶
Index ¶
- Constants
- func NewDeadlineHeap(ctx context.Context, coalesceWindow time.Duration) *deadlineHeap
- func NewDrainingJobWatcher(ctx context.Context, limiter *rate.Limiter, state *state.StateStore, ...) *drainingJobWatcher
- func NewDrainingNode(node *structs.Node, state *state.StateStore) *drainingNode
- func NewNodeDrainWatcher(ctx context.Context, limiter *rate.Limiter, state *state.StateStore, ...) *nodeDrainWatcher
- type DrainDeadlineNotifier
- type DrainDeadlineNotifierFactory
- type DrainRequest
- type DrainingJobWatcher
- type DrainingJobWatcherFactory
- type DrainingNodeWatcher
- type DrainingNodeWatcherFactory
- type MockDeadlineNotifier
- type MockJobWatcher
- type MockRaftApplierShim
- type NodeDrainer
- type NodeDrainerConfig
- type NodeTracker
- type RaftApplier
Constants ¶
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 ¶
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(jobs []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 MockDeadlineNotifier ¶ added in v1.3.14
func (*MockDeadlineNotifier) NextBatch ¶ added in v1.3.14
func (m *MockDeadlineNotifier) NextBatch() <-chan []string
NextBatch returns the channel of expired nodes. Tests can send on this channel to simulate timer events in the NodeDrainer watch loop. (Sending on this channel will block anywhere else.)
func (*MockDeadlineNotifier) Remove ¶ added in v1.3.14
func (m *MockDeadlineNotifier) Remove(nodeID string)
Remove removes the given node from being tracked for a deadline.
type MockJobWatcher ¶ added in v1.3.14
func (*MockJobWatcher) Drain ¶ added in v1.3.14
func (m *MockJobWatcher) Drain() <-chan *DrainRequest
Drain returns the DrainRequest channel. Tests can send on this channel to simulate steps through the NodeDrainer watch loop. (Sending on this channel will block anywhere else.)
func (*MockJobWatcher) Migrated ¶ added in v1.3.14
func (m *MockJobWatcher) Migrated() <-chan []*structs.Allocation
Migrated returns the channel of migrated allocations. Tests can send on this channel to simulate steps through the NodeDrainer watch loop. (Sending on this channel will block anywhere else.)
func (*MockJobWatcher) RegisterJobs ¶ added in v1.3.14
func (m *MockJobWatcher) RegisterJobs(jobs []structs.NamespacedID)
RegisterJobs marks the job as being watched
type MockRaftApplierShim ¶ added in v1.3.14
type MockRaftApplierShim struct {
// contains filtered or unexported fields
}
func (*MockRaftApplierShim) AllocUpdateDesiredTransition ¶ added in v1.3.14
func (m *MockRaftApplierShim) AllocUpdateDesiredTransition( allocs map[string]*structs.DesiredTransition, evals []*structs.Evaluation) (uint64, error)
AllocUpdateDesiredTransition mocks a write to raft as a state store update
func (*MockRaftApplierShim) NodesDrainComplete ¶ added in v1.3.14
func (m *MockRaftApplierShim) NodesDrainComplete( nodes []string, event *structs.NodeEvent) (uint64, error)
NodesDrainComplete mocks a write to raft as a state store update
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.