state

package
v0.0.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// ScaleChemtrailSource is the source used when building the start event for a scaling
	// activity.
	ScaleChemtrailSource = "chemtrail"

	// ScaleStartMessage is the message used as the first event in a scaling activity.
	ScaleStartMessage = "scaling activity has started"
)
View Source
const (
	// GarbageCollectionThreshold is a time in nanoseconds. This is used to determine whether or
	// not scaling events should be garbage collected. This is 24hrs.
	GarbageCollectionThreshold = 172800000000000
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientProvider

type ClientProvider string

ClientProvider is an identifier to the backend which provides the Nomad client workers. This is used to ensure the correct APIs are called when wanting to perform scaling activities.

const (
	// AWSAutoScaling uses AWS AutoScaling groups to provide the client workers.
	AWSAutoScaling ClientProvider = "aws-autoscaling"
)

func (ClientProvider) String

func (c ClientProvider) String() string

String returns the string representation of the client provider.

func (ClientProvider) Validate

func (c ClientProvider) Validate() error

Validate can be used to ensure the passed ClientProvider is valid and able to be handled by the current Chemtrail version.

type ClientScalingPolicy

type ClientScalingPolicy struct {
	Enabled        bool                    `json:"Enabled"`
	Class          string                  `json:"Class"`
	MinCount       int                     `json:"MinCount"`
	MaxCount       int                     `json:"MaxCount"`
	ScaleOutCount  int                     `json:"ScaleOutCount"`
	ScaleInCount   int                     `json:"ScaleInCount"`
	Provider       ClientProvider          `json:"Provider"`
	ProviderConfig map[string]string       `json:"ProviderConfig"`
	Checks         map[string]*PolicyCheck `json:"Checks"`
}

ClientScalingPolicy represents a Nomad client class scaling document. It is used to define all parameters and configuration options needed to perform scaling evaluations and requests.

func (ClientScalingPolicy) Validate

func (c ClientScalingPolicy) Validate() error

Validate can be used to validate the contents of a scaling policy. This ensures it contains the minimum viable config available for both Chemtrail, and the backend provider it is intended to be used with.

type ComparisonAction

type ComparisonAction string

ComparisonAction is the action to take if the metric breaks the threshold.

const (
	// ActionScaleIn performs a scale in operation.
	ActionScaleIn ComparisonAction = "scale-in"

	// ActionScaleOut performs a scale out operation.
	ActionScaleOut ComparisonAction = "scale-out"
)

func (ComparisonAction) String

func (ca ComparisonAction) String() string

String returns the string form of the ComparisonAction.

func (ComparisonAction) Validate

func (ca ComparisonAction) Validate() error

Validate checks the ComparisonAction is a valid and that it can be handled within the autoscaler.

type ComparisonOperator

type ComparisonOperator string

ComparisonOperator is the operator used when evaluating a metric value against a threshold.

const (
	ComparisonGreaterThan ComparisonOperator = "greater-than"
	ComparisonLessThan    ComparisonOperator = "less-than"
)

func (ComparisonOperator) String

func (co ComparisonOperator) String() string

String returns the string form of the ComparisonOperator.

func (ComparisonOperator) Validate

func (co ComparisonOperator) Validate() error

Validate checks the ComparisonOperator is a valid and that it can be handled within the autoscaler.

type Event

type Event struct {
	Timestamp int64
	Message   string
	Source    string
}

type EventMessage

type EventMessage struct {
	ID        uuid.UUID
	Timestamp int64
	Source    string
	Message   string
	Error     error
}

func (EventMessage) MarshalZerologObject

func (em EventMessage) MarshalZerologObject(e *zerolog.Event)

type PolicyBackend

type PolicyBackend interface {

	// GetPolicies returns all the currently stored policies from the backend. The map is keyed by
	// the class identifier.
	GetPolicies() (map[string]*ClientScalingPolicy, error)

	// GetPolicy takes an input class identifier and returns the scaling policy if it is found
	// within the backend.
	GetPolicy(class string) (*ClientScalingPolicy, error)

	// PutPolicy is used to write a new or update an existing class policy. Updates should
	// overwrite any stored information for the class.
	PutPolicy(policy *ClientScalingPolicy) error

	// DeletePolicy is used to delete the class scaling policy if it exists within the backend
	// storage. If the specified class does not have a policy within the backend, the call will be
	// no-op.
	DeletePolicy(class string) error
}

PolicyBackend is the interface which must be satisfied in order to store Chemtrail scaling policies.

type PolicyCheck

type PolicyCheck struct {

	// Enabled is a boolean flag to identify whether this specific check should be actively run or
	// not.
	Enabled bool `json:"Enabled"`

	// Resource identifies the Nomad resource which will be checked within this policy check
	// evaluation.
	Resource ScaleResource `json:"Resource"`

	// ComparisonOperator determines how the value if compared to the theshold.
	ComparisonOperator ComparisonOperator `json:"ComparisonOperator"`

	// ComparisonPercentage is the float64 value that will be compared to the result of the metric
	// query.
	ComparisonPercentage float64 `json:"ComparisonPercentage"`

	// Action is the scaling action that should be taken if the queried metric fails the comparison
	// check.
	Action ComparisonAction `json:"Action"`
}

PolicyCheck is an individual check to be performed as part of an autoscaling evaluation of the Nomad client class.

type ScaleBackend

type ScaleBackend interface {

	// GetScalingActivities returns all the currently stored scaling activates from the storage
	// backend. The map is keyed by the scaling ID.
	GetScalingActivities() (map[uuid.UUID]*ScalingActivity, error)

	// GetScalingActivity attempts to retrieve a single scaling activity from the store based on
	// the scaling ID.
	GetScalingActivity(id uuid.UUID) (*ScalingActivity, error)

	// RunStateGarbageCollection triggers a cleanup of the scaling state, removing all entries
	// which are older than the configured threshold.
	RunStateGarbageCollection()

	// WriteRequest is used to write an initial scaling request to the store. This should be called
	// immediately after an activity is requested.
	WriteRequest(req *ScalingRequest) error

	// WriteRequestEvent updates the stored request details with the passed event. This should not
	// overwrite the stored data, but append to the list of stored events.
	WriteRequestEvent(message *ScalingUpdate) error
}

ScaleBackend is the interface which storage providers must implement in order to store scaling state.

type ScaleDirection

type ScaleDirection string

ScaleDirection describes the direction which a scaling activity should take.

const (
	// ScaleDirectionIn indicates that an activity should be undertaken to decrement the current
	// client count.
	ScaleDirectionIn ScaleDirection = "in"

	// ScaleDirectionOut indicates that an activity should be undertaken to increment the current client count.
	ScaleDirectionOut ScaleDirection = "out"

	// ScaleDirectionNone is an indication that no scaling action is required.
	ScaleDirectionNone ScaleDirection = "none"
)

func (ScaleDirection) String

func (sd ScaleDirection) String() string

String is a helper method to return the string of the ScaleDirection.

type ScaleResource

type ScaleResource string

ScaleResource is the Nomad resource to evaluate within the defined check.

const (
	// ScaleResourceCPU represents the CPU resource stanza parameter in a Nomad job as specified:
	// https://www.nomadproject.io/docs/job-specification/resources.html#cpu
	ScaleResourceCPU ScaleResource = "cpu"

	// ScaleResourceMemory represents the memory resource stanza parameter in a Nomad job as
	// specified: https://www.nomadproject.io/docs/job-specification/resources.html#memory
	ScaleResourceMemory ScaleResource = "memory"
)

func (ScaleResource) String

func (r ScaleResource) String() string

String returns the string form of the ScaleResource.

func (ScaleResource) Validate

func (r ScaleResource) Validate() error

Validate checks the ScaleResource is a valid and that it can be handled within the autoscaler.

type ScaleStatus

type ScaleStatus string

ScaleStatus describes the state of a scaling activity as well as the state an activity was in when an event was recorded.

const (
	// ScaleStatusStarted represents the initial event of a scaling operation. The source of an
	// event using this status should always be Chemtrail.
	ScaleStatusStarted ScaleStatus = "started"

	// ScaleStatusInProgress is a general purpose status which all downstream activity providers
	// can use to record scaling operation events.
	ScaleStatusInProgress ScaleStatus = "in-progress"

	// ScaleStatusCompleted is a terminally successful scaling status. The source of an event using
	// this status should always be Chemtrail.
	ScaleStatusCompleted ScaleStatus = "completed"

	// ScaleStatusFailed is a terminally unsuccessful scaling status. The source of an event using
	// this status should always be Chemtrail.
	ScaleStatusFailed ScaleStatus = "failed"
)

func (ScaleStatus) String

func (s ScaleStatus) String() string

String is a helper method to return the string of the ScaleStatus.

type ScalingActivity

type ScalingActivity struct {

	// Events is a list of events which occurred during the scaling operation and provides insight
	// into the operations and actions conducted.
	Events []Event

	// ScaleDirection is the direction of scaling.
	Direction ScaleDirection

	// LastUpdate is the UnixNano timestamp of the last update to the scaling operation and if the
	// status is terminal, indicates the time of the last action of the scaling event.
	LastUpdate int64

	// ScaleStatus indicates the current status of the scaling operation.
	Status ScaleStatus

	// Provider indicated the backend node provider used for this scaling operation.
	Provider ClientProvider

	// ProviderCfg is a key value map containing any runtime specific information for the node
	// provider. This should not include credentials, but instead items such as ASG name,
	// instanceIDs or IP addresses.
	ProviderCfg map[string]string
}

ScalingActivity represents an individual scaling operation and is designed to take the overall configuration, as well as events during the operation.

type ScalingRequest

type ScalingRequest struct {
	ID           uuid.UUID
	Direction    ScaleDirection
	TargetNodeID string
	Policy       *ClientScalingPolicy
}

func (ScalingRequest) MarshalZerologObject

func (sr ScalingRequest) MarshalZerologObject(e *zerolog.Event)

type ScalingUpdate

type ScalingUpdate struct {
	ID     uuid.UUID
	Status ScaleStatus
	Detail Event
}

func (ScalingUpdate) MarshalZerologObject

func (su ScalingUpdate) MarshalZerologObject(e *zerolog.Event)

Directories

Path Synopsis
policy
scale

Jump to

Keyboard shortcuts

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