core

package
v0.35.0 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EstimateTrueWorkingSetSize added in v0.33.0

func EstimateTrueWorkingSetSize(
	series []float64,
	cfg WssEstimatorConfig,
) float64

EstimateTrueWorkingSetSize returns an estimate of the "true" current working set size, given a series of datapoints for the observed working set size over increasing time intervals.

In practice, the 'series' is e.g., values of 'neon.lfc_approximate_working_set_size_seconds(d)' for equidistant values of 'd' from 1 minute to 60 minutes.

This function panics if: * cfg.WindowSize < 2 * cfg.InitialOffset < cfg.WindowSize - 1

func ParseMetrics added in v0.31.0

func ParseMetrics(content io.Reader, metrics FromPrometheus) error

ParseMetrics reads the prometheus text-format content, parses it, and uses M's implementation of FromPrometheus to populate it before returning.

func ProjectNextHighest added in v0.33.0

func ProjectNextHighest(series []float64, projectLen float64) float64

ProjectNextHighest looks at the rate of change between points in 'series', returning the maximum value if any of these slopes were to continue for 'projectLen' additional datapoints.

For example, given the series '0, 1, 3, 4, 5', projectLen of 3, and ceil equal to 6, ProjectNextHighest will return 9 (because 1 → 3 would reach 9 if it continued for another 3 datapoints (→ 5 → 7 → 9).

Internally, ProjectNextHighest is used to allow preemptive scale-up when we can see that the observed working set size is increasing, but we don't know how big it'll get. In short, this function helps answer: "How much should we scale-up to accommodate expected increases in demand?".

Types

type ActionMonitorDownscale

type ActionMonitorDownscale struct {
	Current        api.Resources         `json:"current"`
	Target         api.Resources         `json:"target"`
	TargetRevision vmv1.RevisionWithTime `json:"targetRevision"`
}

func (ActionMonitorDownscale) MarshalLogObject added in v0.18.1

func (a ActionMonitorDownscale) MarshalLogObject(enc zapcore.ObjectEncoder) error

MarshalLogObject implements zapcore.ObjectMarshaler, so that ActionMonitorDownscale can be used with zap.Object

type ActionMonitorUpscale

type ActionMonitorUpscale struct {
	Current        api.Resources         `json:"current"`
	Target         api.Resources         `json:"target"`
	TargetRevision vmv1.RevisionWithTime `json:"targetRevision"`
}

func (ActionMonitorUpscale) MarshalLogObject added in v0.18.1

func (a ActionMonitorUpscale) MarshalLogObject(enc zapcore.ObjectEncoder) error

MarshalLogObject implements zapcore.ObjectMarshaler, so that ActionMonitorUpscale can be used with zap.Object

type ActionNeonVMRequest

type ActionNeonVMRequest struct {
	Current        api.Resources         `json:"current"`
	Target         api.Resources         `json:"target"`
	TargetRevision vmv1.RevisionWithTime `json:"targetRevision"`
}

func (ActionNeonVMRequest) MarshalLogObject added in v0.18.1

func (a ActionNeonVMRequest) MarshalLogObject(enc zapcore.ObjectEncoder) error

MarshalLogObject implements zapcore.ObjectMarshaler, so that ActionNeonVMRequest can be used with zap.Object

type ActionPluginRequest

type ActionPluginRequest struct {
	LastPermit     *api.Resources        `json:"current"`
	Target         api.Resources         `json:"target"`
	Metrics        *api.Metrics          `json:"metrics"`
	TargetRevision vmv1.RevisionWithTime `json:"targetRevision"`
}

func (ActionPluginRequest) MarshalLogObject added in v0.18.1

func (a ActionPluginRequest) MarshalLogObject(enc zapcore.ObjectEncoder) error

MarshalLogObject implements zapcore.ObjectMarshaler, so that ActionPluginRequest can be used with zap.Object

type ActionSet

type ActionSet struct {
	Wait             *ActionWait             `json:"wait,omitempty"`
	PluginRequest    *ActionPluginRequest    `json:"pluginRequest,omitempty"`
	NeonVMRequest    *ActionNeonVMRequest    `json:"neonvmRequest,omitempty"`
	MonitorDownscale *ActionMonitorDownscale `json:"monitorDownscale,omitempty"`
	MonitorUpscale   *ActionMonitorUpscale   `json:"monitorUpscale,omitempty"`
}

func (ActionSet) MarshalLogObject added in v0.18.1

func (s ActionSet) MarshalLogObject(enc zapcore.ObjectEncoder) error

type ActionWait

type ActionWait struct {
	Duration time.Duration `json:"duration"`
}

func (ActionWait) MarshalLogObject added in v0.18.1

func (a ActionWait) MarshalLogObject(enc zapcore.ObjectEncoder) error

MarshalLogObject implements zapcore.ObjectMarshaler, so that ActionWait can be used with zap.Object

type Config

type Config struct {
	// ComputeUnit is the desired ratio between CPU and memory, copied from the global
	// autoscaler-agent config.
	ComputeUnit api.Resources

	// DefaultScalingConfig is just copied from the global autoscaler-agent config.
	// If the VM's ScalingConfig is nil, we use this field instead.
	DefaultScalingConfig api.ScalingConfig

	// NeonVMRetryWait gives the amount of time to wait to retry after a failed request
	NeonVMRetryWait time.Duration

	// PluginRequestTick gives the period at which we should be making requests to the scheduler
	// plugin, even if nothing's changed.
	PluginRequestTick time.Duration

	// PluginRetryWait gives the amount of time to wait to retry after a failed request
	PluginRetryWait time.Duration

	// PluginDeniedRetryWait gives the amount of time we must wait before re-requesting resources
	// that were not fully granted.
	PluginDeniedRetryWait time.Duration

	// MonitorDeniedDownscaleCooldown gives the time we must wait between making duplicate
	// downscale requests to the vm-monitor where the previous failed.
	MonitorDeniedDownscaleCooldown time.Duration

	// MonitorRequestedUpscaleValidPeriod gives the duration for which requested upscaling from the
	// vm-monitor must be respected.
	MonitorRequestedUpscaleValidPeriod time.Duration

	// MonitorRetryWait gives the amount of time to wait to retry after a *failed* request.
	MonitorRetryWait time.Duration

	// Log provides an outlet for (*State).NextActions() to give informative messages or warnings
	// about conditions that are impeding its ability to execute.
	Log LogConfig `json:"-"`

	// RevisionSource is the source of revisions to track the progress during scaling.
	RevisionSource RevisionSource `json:"-"`

	// ObservabilityCallbacks are the callbacks to submit datapoints for observability.
	ObservabilityCallbacks ObservabilityCallbacks `json:"-"`
}

Config represents some of the static configuration underlying the decision-making of State

type FromPrometheus added in v0.31.0

type FromPrometheus interface {
	// contains filtered or unexported methods
}

FromPrometheus represents metric types that can be parsed from prometheus output.

type LFCMetrics added in v0.31.0

type LFCMetrics struct {
	CacheHitsTotal   float64
	CacheMissesTotal float64
	CacheWritesTotal float64

	// lfc_approximate_working_set_size_windows, currently requires that values are exactly every
	// minute
	ApproximateworkingSetSizeBuckets []float64
}

type LogConfig

type LogConfig struct {
	// Info, if not nil, will be called to provide information during normal functioning.
	// For example, we log the calculated desired resources on every call to NextActions.
	Info func(string, ...zap.Field)
	// Warn, if not nil, will be called to log conditions that are impeding the ability to move the
	// current resources to what's desired.
	// A typical warning may be something like "wanted to do X but couldn't because of Y".
	Warn func(string, ...zap.Field)
}

type MonitorHandle

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

MonitorHandle provides write access to the vm-monitor pieces of an UpdateState

func (MonitorHandle) Active

func (h MonitorHandle) Active(active bool)

func (MonitorHandle) DownscaleRequestAllowed

func (h MonitorHandle) DownscaleRequestAllowed(now time.Time, rev vmv1.RevisionWithTime)

func (MonitorHandle) DownscaleRequestDenied

func (h MonitorHandle) DownscaleRequestDenied(now time.Time, targetRevision vmv1.RevisionWithTime)

Downscale request was successful but the monitor denied our request.

func (MonitorHandle) DownscaleRequestFailed

func (h MonitorHandle) DownscaleRequestFailed(now time.Time)

func (MonitorHandle) Reset

func (h MonitorHandle) Reset()

func (MonitorHandle) StartingDownscaleRequest

func (h MonitorHandle) StartingDownscaleRequest(now time.Time, resources api.Resources)

func (MonitorHandle) StartingUpscaleRequest

func (h MonitorHandle) StartingUpscaleRequest(now time.Time, resources api.Resources)

func (MonitorHandle) UpscaleRequestFailed

func (h MonitorHandle) UpscaleRequestFailed(now time.Time)

func (MonitorHandle) UpscaleRequestSuccessful

func (h MonitorHandle) UpscaleRequestSuccessful(now time.Time)

func (MonitorHandle) UpscaleRequested

func (h MonitorHandle) UpscaleRequested(now time.Time, resources api.MoreResources)

type NeonVMHandle

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

func (NeonVMHandle) RequestFailed

func (h NeonVMHandle) RequestFailed(now time.Time)

func (NeonVMHandle) RequestSuccessful

func (h NeonVMHandle) RequestSuccessful(now time.Time)

func (NeonVMHandle) StartingRequest

func (h NeonVMHandle) StartingRequest(now time.Time, resources api.Resources)

type ObservabilityCallbacks added in v0.33.0

type ObservabilityCallbacks struct {
	PluginLatency  revsource.ObserveCallback
	MonitorLatency revsource.ObserveCallback
	NeonVMLatency  revsource.ObserveCallback
}

type PluginHandle

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

PluginHandle provides write access to the scheduler plugin pieces of an UpdateState

func (PluginHandle) RequestFailed

func (h PluginHandle) RequestFailed(now time.Time)

func (PluginHandle) RequestSuccessful

func (h PluginHandle) RequestSuccessful(
	now time.Time,
	targetRevision vmv1.RevisionWithTime,
	resp api.PluginResponse,
) (_err error)

func (PluginHandle) StartingRequest

func (h PluginHandle) StartingRequest(now time.Time, resources api.Resources)

type RevisionSource added in v0.33.0

type RevisionSource interface {
	Next(ts time.Time, flags vmv1.Flag) vmv1.Revision
	Observe(moment time.Time, rev vmv1.Revision) error
}

type State

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

State holds all of the necessary internal state for a VM in order to make scaling decisions

func NewState

func NewState(vm api.VmInfo, config Config) *State

func (*State) Debug

func (s *State) Debug(enabled bool)

Debug sets s.debug = enabled. This method is exclusively meant to be used in tests, to make it easier to enable print debugging only for a single call to NextActions, via s.warn() or otherwise.

func (*State) DesiredResourcesFromMetricsOrRequestedUpscaling

func (s *State) DesiredResourcesFromMetricsOrRequestedUpscaling(now time.Time) (api.Resources, func(ActionSet) *time.Duration)

public version, for testing.

func (*State) Dump

func (s *State) Dump() StateDump

Dump produces a JSON-serializable copy of the State

func (*State) Monitor

func (s *State) Monitor() MonitorHandle

func (*State) NeonVM

func (s *State) NeonVM() NeonVMHandle

func (*State) NextActions

func (s *State) NextActions(now time.Time) ActionSet

NextActions is used to implement the state machine. It's a pure function that *just* indicates what the executor should do.

func (*State) Plugin

func (s *State) Plugin() PluginHandle

func (*State) UpdateLFCMetrics added in v0.31.0

func (s *State) UpdateLFCMetrics(metrics LFCMetrics)

func (*State) UpdateSystemMetrics added in v0.31.0

func (s *State) UpdateSystemMetrics(metrics SystemMetrics)

func (*State) UpdatedVM

func (s *State) UpdatedVM(vm api.VmInfo)

type StateDump

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

StateDump provides introspection into the current values of the fields of State

It implements json.Marshaler.

func (StateDump) MarshalJSON added in v0.21.0

func (d StateDump) MarshalJSON() ([]byte, error)

type SystemMetrics added in v0.31.0

type SystemMetrics struct {
	LoadAverage1Min float64

	MemoryUsageBytes  float64
	MemoryCachedBytes float64
}

func (SystemMetrics) ToAPI added in v0.31.0

func (m SystemMetrics) ToAPI() api.Metrics

type WssEstimatorConfig added in v0.33.0

type WssEstimatorConfig struct {
	// MaxAllowedIncreaseFactor is the maximum tolerable increase in slope between windows.
	// If the slope increases by more than this factor, we will cut off the working set size as the
	// border between the two windows.
	MaxAllowedIncreaseFactor float64
	// InitialOffset is the index of the minimum working set size we must consider.
	//
	// In practice, this is taken from the scaling config's LFCMinWaitBeforeDownscaleMinutes, with
	// the expectation that datapoints are all one minute apart, starting at 1m. So a value of 15m
	// translates to an InitialOffset of 14 (-1 because indexes start at zero, but the first
	// datapoint is 1m).
	InitialOffset int
	// WindowSize sets the offset for datapoints used in the calculation of the slope before & after
	// a point. For window size W, we calculate the slope at point P as value[P]-value[P-(W-1)].
	// This value must be >= 2.
	//
	// In practice, this value is taken from the scaling config's LFCWindowSizeMinutes, with the
	// expectation that datapoints are all one minute apart. So, a value of 5 minutes translates to
	// a WindowSize of 5.
	WindowSize int
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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