informant

package
v0.15.0-alpha Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2023 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

The VM informant currently supports v1.1 and v1.2 of the agent<->informant protocol.

If you update either of these values, make sure to also update VERSIONING.md.

View Source
const (
	PrometheusPort uint16 = 9100

	CheckDeadlockDelay   time.Duration = 1 * time.Second
	CheckDeadlockTimeout time.Duration = 250 * time.Millisecond

	AgentBackgroundCheckDelay   time.Duration = 10 * time.Second
	AgentBackgroundCheckTimeout time.Duration = 250 * time.Millisecond

	AgentResumeTimeout  time.Duration = 100 * time.Millisecond
	AgentSuspendTimeout time.Duration = 5 * time.Second        // may take a while; it /suspend intentionally waits
	AgentUpscaleTimeout time.Duration = 400 * time.Millisecond // does not include waiting for /upscale response

	MonitorResponseTimeout  time.Duration = 2 * time.Second
	MonitorHealthCheckDelay time.Duration = 5 * time.Second
)
View Source
const (
	MinMonitorProtocolVersion api.MonitorProtoVersion = api.MonitorProtoV1_0
	MaxMonitorProtocolVersion api.MonitorProtoVersion = api.MonitorProtoV1_0
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Agent

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

func (*Agent) CheckID

func (a *Agent) CheckID(logger *zap.Logger, timeout time.Duration) error

CheckID checks that the Agent's ID matches what's expected

If the agent has already been registered, then a failure in this method will unregister the agent.

If the Agent is unregistered before the call to CheckID() completes, the request will be cancelled and this method will return context.Canceled.

func (*Agent) EnsureUnregistered

func (a *Agent) EnsureUnregistered(logger *zap.Logger) (wasCurrent bool)

EnsureUnregistered unregisters the Agent if it is currently registered, signalling the AgentSet to use a new Agent if it isn't already

Returns whether the agent was the current Agent in use.

func (*Agent) Resume

func (a *Agent) Resume(logger *zap.Logger, timeout time.Duration) error

Resume attempts to restore the Agent as the current one in use, sending a request to its /resume endpoint

If the Agent is unregistered before the call to Resume() completes, the request will be cancelled and this method will return context.Canceled.

If the request fails, the Agent will be unregistered.

func (*Agent) SpawnRequestUpscale added in v0.1.4

func (a *Agent) SpawnRequestUpscale(logger *zap.Logger, timeout time.Duration, handleError func(error))

SpawnRequestUpscale requests that the Agent increase the resource allocation to this VM

This method blocks until the request is picked up by the message queue, and returns without waiting for the request to complete (it'll do that on its own).

The timeout applies only once the request is in-flight.

This method MUST NOT be called while holding a.parent.lock; if that happens, it may deadlock.

func (*Agent) Suspend added in v0.1.4

func (a *Agent) Suspend(logger *zap.Logger, timeout time.Duration, handleError func(error))

Suspend signals to the Agent that it is not *currently* in use, sending a request to its /suspend endpoint

If the Agent is unregistered before the call to Suspend() completes, the request will be cancelled and this method will return context.Canceled.

If the request fails, the Agent will be unregistered.

type AgentSet

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

AgentSet is the global state handling various autoscaler-agents that we could connect to

func NewAgentSet

func NewAgentSet(logger *zap.Logger) *AgentSet

NewAgentSet creates a new AgentSet and starts the necessary background tasks

On completion, the background tasks should be ended with the Stop method.

func (*AgentSet) Current added in v0.10.0

func (s *AgentSet) Current() *Agent

Returns the current agent, which can be nil

func (*AgentSet) CurrentIdStr added in v0.10.0

func (s *AgentSet) CurrentIdStr() string

Returns the id of the AgentSet's current agent as a string. If the current agent is nil, returns "<nil>"

func (*AgentSet) Get

func (s *AgentSet) Get(id uuid.UUID) (_ *Agent, ok bool)

Get returns the requested Agent, if it exists

func (*AgentSet) ReceivedUpscale added in v0.1.4

func (s *AgentSet) ReceivedUpscale()

ReceivedUpscale marks any desired upscaling from a prior s.RequestUpscale() as resolved

Typically, (*CgroupState).ReceivedUpscale() is also called alongside this method.

func (*AgentSet) RegisterNewAgent

func (s *AgentSet) RegisterNewAgent(logger *zap.Logger, info *api.AgentDesc) (api.InformantProtoVersion, int, error)

RegisterNewAgent instantiates our local information about the autsocaler-agent

Returns: protocol version, status code, error (if unsuccessful)

func (*AgentSet) RequestUpscale added in v0.1.4

func (s *AgentSet) RequestUpscale(logger *zap.Logger)

RequestUpscale requests an immediate upscale for more memory, if there's an agent currently enabled

If there's no current agent, then RequestUpscale marks the upscale as desired, and will request upscaling from the next agent we connect to.

type Dispatcher added in v0.15.0

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

The Dispatcher is the main object managing the websocket connection to the monitor. For more information on the protocol, see pkg/api/types.go

func NewDispatcher added in v0.15.0

func NewDispatcher(logger *zap.Logger, addr string, notifier util.CondChannelSender) (disp Dispatcher, _ error)

Create a new Dispatcher, establishing a connection with the informant. Note that this does not immediately start the Dispatcher. Call Run() to start it.

func (*Dispatcher) Call added in v0.15.0

func (disp *Dispatcher) Call(ctx context.Context, sender util.SignalSender[*MonitorResult], message any) error

Make a request to the monitor. The dispatcher will handle returning a response on the provided SignalSender. The value passed into message must be a valid value to send to the monitor. See the docs for SerializeInformantMessage.

func (*Dispatcher) DoHealthChecks added in v0.15.0

func (disp *Dispatcher) DoHealthChecks(ctx context.Context)

func (*Dispatcher) HandleMessage added in v0.15.0

func (disp *Dispatcher) HandleMessage(
	ctx context.Context,
	logger *zap.Logger,
	handlers messageHandlerFuncs,
) error

Handle messages from the monitor. Make sure that all message types the monitor can send are included in the inner switch statement.

type MonitorResult added in v0.15.0

type MonitorResult struct {
	Result       *api.DownscaleResult
	Confirmation *api.UpscaleConfirmation
	HealthCheck  *api.HealthCheck
}

This struct represents the result of a dispatcher.Call. Because the SignalSender passed in can only be generic over one type - we have this mock enum. Only one field should ever be non-nil, and it should always be clear which field is readable. For example, the caller of dispatcher.call(HealthCheck { .. }) should only read the healthcheck field.

type State

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

State is the global state of the informant

func NewState

func NewState(logger *zap.Logger) (state State, _ error)

func (*State) HealthCheck added in v0.7.0

func (s *State) HealthCheck(ctx context.Context, logger *zap.Logger, info *api.AgentIdentification) (*api.InformantHealthCheckResp, int, error)

HealthCheck is a dummy endpoint that allows the autoscaler-agent to check that (a) the informant is up and running, and (b) the agent is still registered.

Returns: body (if successful), status code, error (if unsuccessful)

func (*State) NotifyUpscale

func (s *State) NotifyUpscale(
	ctx context.Context,
	logger *zap.Logger,
	newResources *api.AgentResourceMessage,
) (*struct{}, int, error)

NotifyUpscale signals that the VM's resource usage has been increased to the new amount

Returns: body (if successful), status code and error (if unsuccessful)

func (*State) RegisterAgent

func (s *State) RegisterAgent(ctx context.Context, logger *zap.Logger, info *api.AgentDesc) (*api.InformantDesc, int, error)

RegisterAgent registers a new or updated autoscaler-agent

Returns: body (if successful), status code, error (if unsuccessful)

func (*State) TryDownscale

func (s *State) TryDownscale(ctx context.Context, logger *zap.Logger, target *api.AgentResourceMessage) (*api.DownscaleResult, int, error)

TryDownscale tries to downscale the VM's current resource usage, returning whether the proposed amount is ok

Returns: body (if successful), status code and error (if unsuccessful)

func (*State) UnregisterAgent

func (s *State) UnregisterAgent(ctx context.Context, logger *zap.Logger, info *api.AgentDesc) (*api.UnregisterAgent, int, error)

UnregisterAgent unregisters the autoscaler-agent given by info, if it is currently registered

If a different autoscaler-agent is currently registered, this method will do nothing.

Returns: body (if successful), status code and error (if unsuccessful)

Jump to

Keyboard shortcuts

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