Documentation
¶
Index ¶
- Constants
- Variables
- func ExpandMetricQuery(ctx context.Context, query, app string) string
- func FormatWildcardAsRegexp(s string) string
- type FlapsClient
- type FlyClient
- type MetricCollector
- type NewFlapsClientFunc
- type Reconciler
- func (r *Reconciler) CalcMaxCreatedMachineN() (int, bool, error)
- func (r *Reconciler) CalcMaxStartedMachineN() (int, bool, error)
- func (r *Reconciler) CalcMinCreatedMachineN() (int, bool, error)
- func (r *Reconciler) CalcMinStartedMachineN() (int, bool, error)
- func (r *Reconciler) CollectMetrics(ctx context.Context) error
- func (r *Reconciler) NextRegion() string
- func (r *Reconciler) Reconcile(ctx context.Context) error
- func (r *Reconciler) SetValue(name string, value float64)
- func (r *Reconciler) Value(name string) (float64, bool)
- type ReconcilerPool
- type ReconcilerStats
Constants ¶
Variables ¶
var ( ErrExprRequired = errors.New("expression required") ErrExprNaN = errors.New("expression returned NaN") ErrExprInf = errors.New("expression returned Inf") )
Expression errors.
Functions ¶
func ExpandMetricQuery ¶ added in v0.3.0
ExpandMetricQuery replaces variables in query with their values.
func FormatWildcardAsRegexp ¶ added in v0.3.0
FormatWildcardAsRegexp returns a regexp for a given wildcard expression.
Types ¶
type FlapsClient ¶ added in v0.3.0
type FlapsClient interface {
List(ctx context.Context, state string) ([]*fly.Machine, error)
Launch(ctx context.Context, input fly.LaunchMachineInput) (*fly.Machine, error)
Destroy(ctx context.Context, input fly.RemoveMachineInput, nonce string) error
Start(ctx context.Context, id, nonce string) (*fly.MachineStartResponse, error)
Stop(ctx context.Context, in fly.StopMachineInput, nonce string) error
}
type MetricCollector ¶
type MetricCollector interface {
Name() string
CollectMetric(ctx context.Context, app string) (float64, error)
}
MetricCollector represents a client for collecting metrics from an external source.
type NewFlapsClientFunc ¶ added in v0.3.0
type NewFlapsClientFunc func(ctx context.Context, appName string) (FlapsClient, error)
type Reconciler ¶
type Reconciler struct {
// Client to connect to Machines API to scale app. Required.
Client FlapsClient
// The name of the app currently being reconciled.
AppName string
// List of regions that machines can be created in.
// The reconciler uses a round-robin approach to choosing next region.
Regions []string
// Expression used for calculating the number of created machines.
// If current number is less than min, more machines will be created.
// If current number is more than max, machines will be destroyed.
MinCreatedMachineN string
MaxCreatedMachineN string
// Expression used for calculating the number of currently started machines.
// If current number is less than min, more machines will be started.
// If current number is more than max, machines will be stopped.
MinStartedMachineN string
MaxStartedMachineN string
// Initial machine state (started or stopped)
InitialMachineState string
// List of collectors to fetch metric values from.
Collectors []MetricCollector
// Must also be registered in RegisterPromMetrics() for visibility.
Stats *ReconcilerStats
// contains filtered or unexported fields
}
Reconciler represents the central part of the autoscaler that stores metrics, computes the number of necessary machines, and performs scaling.
func NewReconciler ¶
func NewReconciler() *Reconciler
func (*Reconciler) CalcMaxCreatedMachineN ¶ added in v0.2.1
func (r *Reconciler) CalcMaxCreatedMachineN() (int, bool, error)
CalcMaxCreatedMachineN returns the maximum number of created machines.
func (*Reconciler) CalcMaxStartedMachineN ¶ added in v0.2.0
func (r *Reconciler) CalcMaxStartedMachineN() (int, bool, error)
CalcMaxStartedMachineN returns the maximum number of started machines.
func (*Reconciler) CalcMinCreatedMachineN ¶ added in v0.2.1
func (r *Reconciler) CalcMinCreatedMachineN() (int, bool, error)
CalcMinCreatedMachineN returns the minimum number of created machines.
func (*Reconciler) CalcMinStartedMachineN ¶ added in v0.2.0
func (r *Reconciler) CalcMinStartedMachineN() (int, bool, error)
CalcMinStartedMachineN returns the minimum number of started machines.
func (*Reconciler) CollectMetrics ¶
func (r *Reconciler) CollectMetrics(ctx context.Context) error
CollectMetrics fetches metrics from all collectors.
func (*Reconciler) NextRegion ¶ added in v0.2.1
func (r *Reconciler) NextRegion() string
NextRegion returns the next region to launch a machine in. If Regions is empty, returns a blank string.
func (*Reconciler) Reconcile ¶
func (r *Reconciler) Reconcile(ctx context.Context) error
Reconcile scales the number of machines up, if needed. Machines should shut themselves down to scale down. Returns the number of started machines, if any.
func (*Reconciler) SetValue ¶
func (r *Reconciler) SetValue(name string, value float64)
SetValue sets the value of a named metric.
type ReconcilerPool ¶ added in v0.3.0
type ReconcilerPool struct {
// Time allowed to perform reconciliation for a single app.
ReconcileTimeout time.Duration
// Frequency to run the reconciliation loop for each app.
ReconcileInterval time.Duration
// Frequency to update the list of matching apps when using wildcards.
AppListRefreshInterval time.Duration
// Name of application to scale. Supports wildcards for multiple apps.
// All applications must be in the same org.
AppName string
// Organization slug. Required if app name is a wildcard.
OrganizationSlug string
// NewFlapsClient is a constructor for building a FLAPS client for a given app.
NewFlapsClient NewFlapsClientFunc
// NewReconciler is a constructor for building reconcilers.
// Called one or more times on Open().
NewReconciler func() *Reconciler
// Shared stats for all reconcilers.
Stats ReconcilerStats
// contains filtered or unexported fields
}
ReconcilerPool represents a set of reconcilers that act as a worker pool.
This is used to distribute scaling across multiple applications while also limiting the maximum concurrency allowed by the scaler.
func NewReconcilerPool ¶ added in v0.3.0
func NewReconcilerPool(flyClient FlyClient, concurrency int) *ReconcilerPool
NewReconcilerPool returns a new instance of ReconcilerPool.
func (*ReconcilerPool) Close ¶ added in v0.3.0
func (p *ReconcilerPool) Close() error
Close stops all processing of the pool and underlying reconcilers. Only returns once all reconcilers have finished processing.
func (*ReconcilerPool) Open ¶ added in v0.3.0
func (p *ReconcilerPool) Open() error
func (*ReconcilerPool) RegisterPromMetrics ¶ added in v0.3.0
func (p *ReconcilerPool) RegisterPromMetrics(reg prometheus.Registerer)
type ReconcilerStats ¶ added in v0.3.0
type ReconcilerStats struct {
// Outcomes, incremented for each reconciliation.
BulkCreate atomic.Int64
BulkDestroy atomic.Int64
BulkStart atomic.Int64
BulkStop atomic.Int64
NoScale atomic.Int64
// Individual machine stats.
MachineCreated atomic.Int64
MachineCreateFailed atomic.Int64
MachineDestroyed atomic.Int64
MachineDestroyFailed atomic.Int64
MachineStarted atomic.Int64
MachineStartFailed atomic.Int64
MachineStopped atomic.Int64
MachineStopFailed atomic.Int64
}