strategy

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2020 License: MPL-2.0 Imports: 4 Imported by: 3

Documentation

Index

Constants

View Source
const (
	// ScaleDirectionDown indicates the target should lower the number of running
	// instances of the resource.
	ScaleDirectionDown = iota - 1

	// ScaleDirectionNone indicates no scaling is required.
	ScaleDirectionNone

	// ScaleDirectionUp indicates the target should increase the number of
	// running instances of the resource.
	ScaleDirectionUp
)

The following constants are used to standardize the possible scaling directions for an Action. They are ordered from riskier to safest, with ScaleDirectionNone as the default and zero value.

View Source
const (

	// MetaValueDryRunCount is a special count value used when performing
	// dry-run scaling activities. The Autoscaler will never set a count to a
	// negative value during normal operation, so the agent is safe to assume a
	// count set to this value implies dry-run.
	MetaValueDryRunCount = -1
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action struct {

	// Count represents the desired count of the target resource. It should
	// always be zero or above, expect in the event of dry-run where it can use
	// the MetaValueDryRunCount value.
	Count int64

	Reason string
	Error  bool

	// Direction is the scaling direction the strategy has decided should
	// happen. This is particularly helpful for non-Nomad target
	// implementations whose APIs dead with increment changes rather than
	// absolute counts.
	Direction ScaleDirection

	Meta map[string]interface{}
}

Action represents a Strategy's intention to modify.

func PreemptAction added in v0.1.0

func PreemptAction(a *Action, b *Action) *Action

PreemptAction determines which Action should take precedence.

The result is based on the scaling direction and count. The order of precedence for the scaling directions is defined by the order in which they are declared in the above enum.

If the scaling direction is the same, the priority is given to the safest option, where safest is defined as lowest impact in the underlying infrastructure:

  • ScaleDirectionUp: Action with highest count
  • ScaleDirectionDown: Action with highest count

func (*Action) Canonicalize

func (a *Action) Canonicalize()

Canonicalize ensures Action has proper default values.

func (*Action) CapCount

func (a *Action) CapCount(min, max int64)

CapCount caps the value of Count so it remains within the specified limits. If Count is MetaValueDryRunCount this method has no effect.

func (*Action) SetDryRun

func (a *Action) SetDryRun()

SetDryRun marks the Action to be executed in dry-run mode. Dry-run mode is indicated using Meta tags. A dry-run action doesn't modify the Target's count value.

type Plugin

type Plugin struct {
	Impl Strategy
}

Plugin is the plugin.Plugin

func (Plugin) Client

func (Plugin) Client(b *plugin.MuxBroker, c *rpc.Client) (interface{}, error)

func (*Plugin) Server

func (p *Plugin) Server(*plugin.MuxBroker) (interface{}, error)

type RPC

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

func (*RPC) PluginInfo

func (r *RPC) PluginInfo() (*base.PluginInfo, error)

func (*RPC) Run

func (r *RPC) Run(req RunRequest) (Action, error)

func (*RPC) SetConfig

func (r *RPC) SetConfig(config map[string]string) error

type RPCServer

type RPCServer struct {
	Impl Strategy
}

func (*RPCServer) PluginInfo

func (s *RPCServer) PluginInfo(_ interface{}, r *base.PluginInfo) error

func (*RPCServer) Run

func (s *RPCServer) Run(req RunRequest, resp *Action) error

func (*RPCServer) SetConfig

func (s *RPCServer) SetConfig(config map[string]string, resp *error) error

type RunRequest

type RunRequest struct {
	PolicyID string
	Count    int64
	Metric   float64
	Config   map[string]string
}

type ScaleDirection added in v0.1.0

type ScaleDirection int8

ScaleDirection is an identifier used by strategy plugins to identify how the target should scale the named resource.

func (ScaleDirection) String added in v0.1.0

func (d ScaleDirection) String() string

String satisfies the Stringer interface and returns as string representation of the scaling direction.

type Strategy

type Strategy interface {
	Run(req RunRequest) (Action, error)
	PluginInfo() (*base.PluginInfo, error)
	SetConfig(config map[string]string) error
}

Jump to

Keyboard shortcuts

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