drainer

package
v2.0.4 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2020 License: MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Name  = "drainer"
	Usage = `` /* 280-byte string literal not displayed */

)

Variables

View Source
var (
	// ErrLifecycleActionTimeout is returned by PostponeLifecycleHookAction
	// when the lifecycle action times out (or isn't found in the first place).
	ErrLifecycleActionTimeout = goerrors.New("lifecycle action timed out")

	// ErrTestLifecycleAction is return by NewLifecycleAction when
	// the passed CloudWatchEvent doesn't represent a valid LifecycleAction.
	ErrInvalidLifecycleAction = goerrors.New("invalid lifecycle action")
)

Functions

This section is empty.

Types

type App

type App struct {
	*kingpin.Application
	// contains filtered or unexported fields
}

App holds application state.

func NewApp

func NewApp(r prometheus.Registerer) (*App, error)

NewApp returns a new App.

func (*App) Main

func (app *App) Main(g prometheus.Gatherer)

Main is the main method of App and should be called in main.main() after flag parsing.

type CloudWatchEventEmitter

type CloudWatchEventEmitter struct {

	// Metrics.
	Received prometheus.Counter
	Deleted  prometheus.Counter
	// contains filtered or unexported fields
}

CloudWatchEventEmitter consumes CloudWatch events from an SQS queue and emits them as github.com/olebedev/emitter events.

func NewCloudWatchEventEmitter

func NewCloudWatchEventEmitter(c sqsiface.ClientAPI, queueURL string, e *emitter.Emitter) *CloudWatchEventEmitter

NewCloudWatchEventEmitter returns a new CloudWatchEventEmitter.

func (*CloudWatchEventEmitter) Run

Run receives and emits CloudWatch events until the context is canceled or an error occurs.

type ClusterState

type ClusterState struct {
	// Nodes in the cluster.
	Nodes []string

	// Count of shards per-node.
	Shards map[string]int

	// Shard allocation exclusions.
	Exclusions *es.ShardAllocationExcludeSettings
}

ClusterState represents the state of an Elasticsearch cluster.

func NewClusterState

NewClusterState returns a new ClusterState.

func (*ClusterState) DiffNodes

func (s *ClusterState) DiffNodes(o *ClusterState) (add, remove []string)

DiffNodes returns the difference between the nodes of two cluster states.

func (*ClusterState) DiffShards

func (s *ClusterState) DiffShards(o *ClusterState) map[string]int

DiffNodes returns the difference between the shards of two cluster states.

func (*ClusterState) HasNode

func (s *ClusterState) HasNode(name string) bool

HasNode returns true if a node with the given node is in the Elasticsearch cluster.

type ElasticsearchFacade

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

ElasticsearchFacade provides a facade for the drainer app's interactions with the ElasticsearchFacade API.

func NewElasticsearchFacade

func NewElasticsearchFacade(c *elastic.Client) *ElasticsearchFacade

NewElasticsearchFacade returns a new ElasticsearchFacade.

func (*ElasticsearchFacade) DrainNodes

func (e *ElasticsearchFacade) DrainNodes(ctx context.Context, names []string) error

DrainNodes puts Elasticsearch nodes into a draining state by adding their names to the list of nodes excluded for data shard allocation. Once set, Elasticsearch will being moving any data shards to other nodes.

See also: https://www.elastic.co/guide/en/elasticsearch/reference/7.0/allocation-filtering.html

func (*ElasticsearchFacade) GetState

func (e *ElasticsearchFacade) GetState(ctx context.Context) (*ClusterState, error)

GetState returns a ClusterState representing the current state of the Elasticsearch cluster.

func (*ElasticsearchFacade) UndrainNodes

func (e *ElasticsearchFacade) UndrainNodes(ctx context.Context, names []string) error

UndrainNodes reverses DrainNodes by removing from the list of nodes excluded from shard allocation.

See also: https://www.elastic.co/guide/en/elasticsearch/reference/7.0/allocation-filtering.html

type ElasticsearchFacadeIface

type ElasticsearchFacadeIface interface {
	GetState(context.Context) (*ClusterState, error)
	DrainNodes(context.Context, []string) error
	UndrainNodes(context.Context, []string) error
}

ElasticsearchFacadeIface is an interface for Elasticsearch so it can be mocked during tests.

type Flags

type Flags struct {
	// The URL of an SQS queue which is configured to receive
	// CloudWatch events from Spot Instance Interruptions and
	// AutoScaling termination events from the Elasticsearch
	// AutoScaling Groups.
	Queue *url.URL

	// The interval at which drainer should poll
	// Elasticsearch for status information.
	PollInterval time.Duration

	*cmd.AWSFlags
	*cmd.ElasticsearchFlags
	*cmd.LoggingFlags
	*cmd.ServerFlags
}

Flags holds command line flags for the drainer App.

func NewFlags

func NewFlags(app *kingpin.Application) *Flags

NewFlags returns a new Flags.

type Healthchecks

type Healthchecks struct {
	Handler healthcheck.Handler

	// Flag to be set true once a connection
	// to Elasticsearch is successfully established.
	ElasticSessionCreated bool

	// Flag to be set true once an AWS session
	// has been successfully created.
	AWSSessionCreated bool
}

func NewHealthchecks

func NewHealthchecks(r prometheus.Registerer, namespace string) *Healthchecks

type Instrumentation

type Instrumentation struct {
	// Count of the number of times cloudwatcher has
	// polled Elasticsearch for information.
	PollTotal prometheus.Counter

	// Total number of SQS messages received.
	MessagesReceived prometheus.Counter

	// Total number of Elasticsearch nodes that
	// got Spot interrupted.
	SpotInterruptions prometheus.Counter

	// Total number of Elasticsearch nodes that
	// have been terminated by an AutoScaling Group
	// scaling down.
	TerminationHookActionsTotal prometheus.Counter

	// Number of ongoing Elasticsearch node terminations
	// due to an AutoScaling Group scaledown.
	TerminationHookActionsInProgress prometheus.Gauge
}

Instrumentation holds Prometheus metrics specific to the drainer App.

func NewInstrumentation

func NewInstrumentation(namespace string) *Instrumentation

NewInstrumentation returns a new Metrics.

func (*Instrumentation) Collect

func (m *Instrumentation) Collect(c chan<- prometheus.Metric)

Collect implements the prometheus.Collector interface.

func (*Instrumentation) Describe

func (m *Instrumentation) Describe(c chan<- *prometheus.Desc)

Describe implements the prometheus.Collector interface.

type LifecycleAction

type LifecycleAction struct {
	// The name of the AWS AutoScaling Group.
	AutoScalingGroupName string

	// The name of the Lifecycle Hook attached
	// to the AutoScaling Group.
	LifecycleHookName string

	// A unique token (UUID) identifing this particular
	// autoscaling action.
	Token string

	// The ID of the EC2 instance effected by the
	// autoscaling action.
	InstanceID string

	// One of: "autoscaling:EC2_INSTANCE_LAUNCHING", "autoscaling:EC2_INSTANCE_TERMINATING".
	LifecycleTransition string

	// The time the autoscaling action started.
	Start time.Time
}

LifecycleAction contains information about on on-going AWS AutoScaling Group scaling event, as related to a Lifecycle Hook on that Group.

See also: https://docs.aws.amazon.com/autoscaling/ec2/userguide/lifecycle-hooks.html#lifecycle-hooks-overview

func NewLifecycleAction

func NewLifecycleAction(e *events.CloudWatchEvent) (*LifecycleAction, error)

NewLifecycleAction returns a new LifecycleAction from a CloudWatchEvent. It will return ErrInvalidLifecycleAction if the event doesn't represent a valid LifecycleAction.

type LifecycleActionPostponer

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

LifecycleActionPostponer prevents LifecycleActions from timing out. See the Postpone method for more details.

func NewLifecycleActionPostponer

func NewLifecycleActionPostponer(client autoscalingiface.ClientAPI) *LifecycleActionPostponer

NewLifecycleActionPostponer returns a new LifecycleActionPostponer.

func (*LifecycleActionPostponer) Postpone

Postpone postpones the timeout of a AWS AutoScaling Group Lifecycle Hook action until the context is canceled, an error occurs, or the Lifecycle Hook's global timeout is reached.

If the action expires (or can't be found; there's no way to distinguish in the AWS API) then ErrLifecycleActionTimeout will be returned.

See also: https://docs.aws.amazon.com/autoscaling/ec2/userguide/lifecycle-hooks.html#lifecycle-hooks-overview

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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