Documentation
¶
Index ¶
- Constants
- func ActiveInboundCount(inst Instance, conns []Connection) (int, time.Duration, error)
- type Connection
- type ConnectionEvent
- type ConnectionEventType
- type ConnectionKey
- type ConnectionSource
- type ConnectionStream
- type ConntrackSource
- type Controller
- type ControllerOptions
- type Instance
- type InstanceEvent
- type InstanceEventAction
- type InstanceStore
- type Metrics
- type Policy
- type Reason
- type Runtime
- type Status
- type StatusSnapshot
- type TCPState
Constants ¶
const (
StateRunning = "Running"
)
Variables ¶
This section is empty.
Functions ¶
func ActiveInboundCount ¶
ActiveInboundCount returns the number of active inbound TCP connections for an instance and the compiled idle timeout that should be applied to it.
Types ¶
type Connection ¶
type Connection struct {
OriginalSourceIP netip.Addr
OriginalSourcePort uint16
OriginalDestinationIP netip.Addr
OriginalDestinationPort uint16
TCPState TCPState
}
Connection is the normalized network view used by activity classification.
type ConnectionEvent ¶
type ConnectionEvent struct {
Type ConnectionEventType
Connection Connection
ObservedAt time.Time
}
ConnectionEvent is a single conntrack event delivered from the host observer.
type ConnectionEventType ¶
type ConnectionEventType string
const ( ConnectionEventNew ConnectionEventType = "new" ConnectionEventDestroy ConnectionEventType = "destroy" )
type ConnectionKey ¶
type ConnectionSource ¶
type ConnectionSource interface {
ListConnections(ctx context.Context) ([]Connection, error)
OpenStream(ctx context.Context) (ConnectionStream, error)
}
ConnectionSource provides startup snapshots and live conntrack events.
type ConnectionStream ¶
type ConnectionStream interface {
Events() <-chan ConnectionEvent
Errors() <-chan error
Close() error
}
ConnectionStream is a live conntrack event stream.
type ConntrackSource ¶
type ConntrackSource struct {
// contains filtered or unexported fields
}
ConntrackSource reads current IPv4 TCP conntrack entries from the host.
func NewConntrackSource ¶
func NewConntrackSource() *ConntrackSource
NewConntrackSource creates a conntrack-backed connection source.
func (*ConntrackSource) ListConnections ¶
func (s *ConntrackSource) ListConnections(context.Context) ([]Connection, error)
ListConnections returns normalized TCP flows from the host conntrack table.
func (*ConntrackSource) OpenStream ¶
func (s *ConntrackSource) OpenStream(ctx context.Context) (ConnectionStream, error)
OpenStream subscribes to IPv4 conntrack NEW, UPDATE, and DESTROY events.
type Controller ¶
type Controller struct {
// contains filtered or unexported fields
}
Controller decides when eligible instances should transition to standby.
func NewController ¶
func NewController(store InstanceStore, source ConnectionSource, opts ControllerOptions) *Controller
NewController creates a new event-driven auto-standby controller.
func (*Controller) Describe ¶
func (c *Controller) Describe(inst Instance) StatusSnapshot
Describe returns the current diagnostic view for an instance.
type ControllerOptions ¶
type ControllerOptions struct {
Log *slog.Logger
Meter metric.Meter
Tracer trace.Tracer
Now func() time.Time
ReconnectDelay time.Duration
ReconcileDelay time.Duration
SnapshotSyncInterval time.Duration
}
ControllerOptions configures logging, timing, and observability.
type Instance ¶
type Instance struct {
ID string
Name string
State string
NetworkEnabled bool
IP string
HasVGPU bool
AutoStandby *Policy
Runtime *Runtime
}
Instance is the minimal instance view needed by the auto-standby controller.
type InstanceEvent ¶
type InstanceEvent struct {
Action InstanceEventAction
InstanceID string
Instance *Instance
}
InstanceEvent carries an instance lifecycle update into the controller.
type InstanceEventAction ¶
type InstanceEventAction string
InstanceEventAction identifies an instance lifecycle change relevant to auto-standby.
const ( InstanceEventCreate InstanceEventAction = "create" InstanceEventUpdate InstanceEventAction = "update" InstanceEventStart InstanceEventAction = "start" InstanceEventStop InstanceEventAction = "stop" InstanceEventStandby InstanceEventAction = "standby" InstanceEventRestore InstanceEventAction = "restore" InstanceEventDelete InstanceEventAction = "delete" InstanceEventFork InstanceEventAction = "fork" )
type InstanceStore ¶
type InstanceStore interface {
ListInstances(ctx context.Context) ([]Instance, error)
StandbyInstance(ctx context.Context, id string) error
SetRuntime(ctx context.Context, id string, runtime *Runtime) error
SubscribeInstanceEvents() (<-chan InstanceEvent, func(), error)
}
InstanceStore supplies the controller with instance state, lifecycle events, runtime persistence, and standby actions.
type Policy ¶
type Policy struct {
Enabled bool `json:"enabled"`
IdleTimeout string `json:"idle_timeout,omitempty"`
IgnoreSourceCIDRs []string `json:"ignore_source_cidrs,omitempty"`
IgnoreDestinationPorts []uint16 `json:"ignore_destination_ports,omitempty"`
}
Policy configures per-instance automatic standby behavior.
func NormalizePolicy ¶
NormalizePolicy validates and canonicalizes a policy for storage.
type Reason ¶
type Reason string
const ( ReasonUnsupportedPlatform Reason = "unsupported_platform" ReasonPolicyMissing Reason = "policy_missing" ReasonPolicyDisabled Reason = "policy_disabled" ReasonInstanceNotRunning Reason = "instance_not_running" ReasonNetworkDisabled Reason = "network_disabled" ReasonMissingIP Reason = "missing_ip" ReasonHasVGPU Reason = "has_vgpu" ReasonActiveInbound Reason = "active_inbound_connections" ReasonIdleTimeoutNotElapsed Reason = "idle_timeout_not_elapsed" ReasonObserverError Reason = "observer_error" ReasonReadyForStandby Reason = "ready_for_standby" )
type Runtime ¶
type Runtime struct {
IdleSince *time.Time `json:"idle_since,omitempty"`
LastInboundActivityAt *time.Time `json:"last_inbound_activity_at,omitempty"`
}
Runtime stores persisted and in-memory idle-tracking timestamps.
type Status ¶
type Status string
const ( StatusUnsupported Status = "unsupported" StatusDisabled Status = "disabled" StatusIneligible Status = "ineligible" StatusActive Status = "active" StatusIdleCountdown Status = "idle_countdown" StatusReadyForStandby Status = "ready_for_standby" StatusStandbyRequested Status = "standby_requested" StatusError Status = "error" )
type StatusSnapshot ¶
type StatusSnapshot struct {
Supported bool
Configured bool
Enabled bool
Eligible bool
Status Status
Reason Reason
ActiveInboundCount int
IdleTimeout string
IdleSince *time.Time
LastInboundActivityAt *time.Time
NextStandbyAt *time.Time
CountdownRemaining *time.Duration
TrackingMode string
}
StatusSnapshot is a diagnostic view of the controller's current state for one VM.
type TCPState ¶
type TCPState uint8
TCPState is the conntrack TCP state for a flow.
const ( TCPStateNone TCPState = 0 TCPStateSynSent TCPState = 1 TCPStateSynRecv TCPState = 2 TCPStateEstablished TCPState = 3 TCPStateFinWait TCPState = 4 TCPStateCloseWait TCPState = 5 TCPStateLastAck TCPState = 6 TCPStateTimeWait TCPState = 7 TCPStateClose TCPState = 8 TCPStateListen TCPState = 9 TCPStateIgnore TCPState = 10 TCPStateRetrans TCPState = 11 )