drain

package
v2.4.1 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2024 License: Apache-2.0 Imports: 16 Imported by: 1

Documentation

Index

Constants

View Source
const (
	StateNotActive uint32 = 0
	StateActive    uint32 = 1

	MetricNotDraining float64 = 0.0
	MetricDraining    float64 = 1.0

	Drained = "drained"
)

Variables

View Source
var (
	ErrActive    error = errors.New("a drain operation is already running")
	ErrNotActive error = errors.New("no drain operation is running")
)

Functions

This section is empty.

Types

type Cancel

type Cancel struct {
	Drainer Interface
}

Cancel is an HTTP handler that allows cancellation of drain jobs

func (*Cancel) ServeHTTP

func (c *Cancel) ServeHTTP(response http.ResponseWriter, request *http.Request)

type DrainFilter

type DrainFilter interface {
	device.Filter
	GetFilterRequest() devicegate.FilterRequest
}

DrainFilter contains the filter information for a drain job

type Interface

type Interface interface {
	// Start attempts to begin draining devices.  The supplied Job describes how the drain will proceed.
	// The returned channel can be used to wait for the drain job to complete.  The returned Job will be
	// the result of applying defaults and will represent the actual Job being executed.  For example, if Job.Rate
	// is set but Job.Tick is not, the returned Job will reflect the default of 1 second for Job.Tick.
	Start(Job) (<-chan struct{}, Job, error)

	// Status returns information about the current drain job, if any.  The boolean return indicates whether
	// the job is currently active, while the returned Job describes the actual options used in starting the drainer.
	// This returned Job instance will not necessarily be the same as that passed to Start, as certain fields
	// may be computed or defaulted.
	Status() (bool, Job, Progress)

	// Cancel asynchronously halts any running drain job.  The returned channel can be used to wait for the job to actually exit.
	// If no job is running, an error is returned along with a nil channel.
	Cancel() (<-chan struct{}, error)
}

Interface describes the behavior of a component which can execute a Job to drain devices. Only (1) drain Job is allowed to run at any time.

func New

func New(options ...Option) Interface

New constructs a drainer using the supplied options

type Job

type Job struct {
	// Count is the total number of devices to disconnect.  If this field is nonpositive and percent is unset,
	// the count of connected devices at the start of job execution is used.  If Percent is set, this field's
	// original value is ignored and it is set to that percentage of total devices connected at the time the
	// job starts.
	Count int `json:"count" schema:"count"`

	// Percent is the fraction of devices to drain.  If this field is set, Count's original value is ignored
	// and set to the computed percentage of connected devices at the time the job starts.
	Percent int `json:"percent,omitempty" schema:"percent"`

	// Rate is the number of devices per tick to disconnect.  If this field is nonpositive,
	// devices are disconnected as fast as possible.
	Rate int `json:"rate,omitempty" schema:"rate"`

	// Tick is the time unit for the Rate field.  If Rate is set but this field is not set,
	// a tick of 1 second is used as the default.
	Tick time.Duration `json:"tick,omitempty" schema:"tick"`

	// DrainFilter holds the filter to drain devices by. If this is set for the job, only devices that match the filter will be drained
	DrainFilter DrainFilter `json:"filter,omitempty" schema:"filter"`
}

func (Job) ToMap

func (j Job) ToMap() map[string]interface{}

ToMap returns a map representation of this Job appropriate for marshaling to formats like JSON. This method makes things a bit prettier, like the Tick.

type Option

type Option func(*drainer)

func WithConnector

func WithConnector(c device.Connector) Option

func WithDrainCounter

func WithDrainCounter(a xmetrics.Adder) Option

func WithLogger

func WithLogger(l *zap.Logger) Option

func WithManager

func WithManager(m device.Manager) Option

func WithRegistry

func WithRegistry(r device.Registry) Option

func WithStateGauge

func WithStateGauge(s xmetrics.Setter) Option

type Progress

type Progress struct {
	// Visited is the number of devices handled so far.  This value will not
	// exceed the Job.Count value.
	Visited int `json:"visited"`

	// Drained is the count of visited devices that have actually been disconnected
	// due to the drain.  Devices can disconnect or be disconnected outside a drain job,
	// so this value can be lower than Visited, even in a job that has finished.
	Drained int `json:"drained"`

	// Started is the UTC system time at which the drain job was started.
	Started time.Time `json:"started"`

	// Finished is the UTC system time at which the drain job finished or was canceled.
	// If the job is running, this field will be nil.
	Finished *time.Time `json:"finished,omitempty"`
}

Progress represents a snapshot of what a drain job has done so far.

type Start

type Start struct {
	Drainer Interface
}

func (*Start) ServeHTTP

func (s *Start) ServeHTTP(response http.ResponseWriter, request *http.Request)

type Status

type Status struct {
	Drainer Interface
}

Status returns a JSON message describing the status of the drain job

func (*Status) ServeHTTP

func (s *Status) ServeHTTP(response http.ResponseWriter, request *http.Request)

Jump to

Keyboard shortcuts

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