agent_server

package
v0.32.1 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2026 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AGENT_SCHEDULE_INTERVAL       = 1 * time.Minute
	AGENT_LIVENESS_CHECK_INTERVAL = 10 * time.Second
	AGENT_LIVENESS_TIMEOUT        = 30 * time.Second
)
View Source
const (
	AGENT_SESSION_LOG_HISTORY = 1000 // Number of lines of log history to keep
)

Variables

This section is empty.

Functions

func DisconnectSession added in v0.25.0

func DisconnectSession(spaceId string, session *Session)

func ExpireSession added in v0.25.0

func ExpireSession(spaceId string, session *Session)

func GetPoolSessionState added in v0.28.0

func GetPoolSessionState(spaceId string) *service.PoolSessionState

func ListenAndServe

func ListenAndServe(listen string, tlsConfig *tls.Config)

func QueueSpaceReconcile added in v0.25.0

func QueueSpaceReconcile(spaceId string)

func RemoveSession

func RemoveSession(spaceId string)

Types

type Session

type Session struct {
	Id                    string
	Version               string
	PeerPort              uint16
	HasCodeServer         bool
	SSHPort               int
	VNCHttpPort           int
	HasTerminal           bool
	TcpPorts              map[string]string
	HttpPorts             map[string]string
	HasVSCodeTunnel       bool
	VSCodeTunnelName      string
	CPUPercent            float64
	MemoryUsedBytes       uint64
	MemoryLimitBytes      uint64
	DiskUsedBytes         uint64
	DiskLimitBytes        uint64
	ActivityWriteCount    uint32
	ActivityCreateCount   uint32
	ActivityDeleteCount   uint32
	ActivityRenameCount   uint32
	ActivityDistinctPaths uint32
	LastActivityAtUnix    int64
	MethodCallsTotal      uint64
	HTTPRequestsTotal     uint64
	TCPConnectionsTotal   uint64
	MethodRPS             float64
	HTTPRPS               float64
	TCPRPS                float64
	LastStateAt           time.Time

	LastPingAt time.Time

	MuxSession *yamux.Session

	// The log history
	LogHistoryMutex *sync.RWMutex
	LogHistory      []*msg.LogMessage

	// The list of listeners for log messages
	LogListenersMutex *sync.RWMutex
	LogListeners      map[string]chan *msg.LogMessage
	// contains filtered or unexported fields
}

Struct holding the state / registration information of an agent

func GetSession

func GetSession(spaceId string) *Session

GetSession retrieves the agent session associated with the given spaceId. If an agent session is found for the provided spaceId, it returns the session; otherwise, it returns nil.

func NewSession

func NewSession(spaceId string, version string) *Session

creates a new agent session

func (*Session) CloseLogListeners added in v0.28.0

func (s *Session) CloseLogListeners()

CloseLogListeners closes and removes every registered log listener. Called when the session is torn down (e.g. the space terminated) so that streaming log readers unblock on their channel and close the client WebSocket — the same way the terminal closes when the mux session ends. Entries are deleted as they're closed so a concurrent UnregisterLogListener won't double-close.

func (*Session) GetLastPingAt added in v0.29.0

func (s *Session) GetLastPingAt() time.Time

GetLastPingAt returns the time of the last successful mux ping.

func (*Session) GetLastStateAt added in v0.28.0

func (s *Session) GetLastStateAt() time.Time

GetLastStateAt returns the time of the last state report. LastStateAt is written by the agent state handler and the stale-session checker from different goroutines, so all access goes through these helpers.

func (*Session) Ping

func (s *Session) Ping() bool

func (*Session) RegisterLogListener added in v0.11.5

func (s *Session) RegisterLogListener() (string, chan *msg.LogMessage)

func (*Session) SendCallMethod added in v0.28.0

func (s *Session) SendCallMethod(call *msg.CallMethodRequest, timeoutSeconds int) (*msg.CallMethodResponse, error)

func (*Session) SendCallMethodBatch added in v0.28.0

func (s *Session) SendCallMethodBatch(req *msg.CallMethodBatchRequest, timeoutSeconds int) (*msg.CallMethodBatchResponse, error)

SendCallMethodBatch sends a sub-batch of calls to the agent in a single yamux stream. The agent processes each item concurrently through the method server and returns all responses in one CallMethodBatchResponse. Used by the server to forward batch items grouped by destination space.

func (*Session) SendCopyFile added in v0.19.0

func (s *Session) SendCopyFile(copyCmd *msg.CopyFileMessage) (chan *msg.CopyFileResponse, error)

func (*Session) SendDeleteFile added in v0.31.0

func (s *Session) SendDeleteFile(d *msg.DeleteFileMessage) (chan *msg.DeleteFileResponse, error)

SendDeleteFile sends a DeleteFileMessage to the agent and returns the response.

func (*Session) SendEditFile added in v0.30.0

func (s *Session) SendEditFile(e *msg.EditFileMessage) (chan *msg.EditFileResponse, error)

SendEditFile sends an EditFileMessage to the agent and returns the response.

func (*Session) SendExecuteScript added in v0.23.0

func (s *Session) SendExecuteScript(execMsg *msg.ExecuteScriptMessage) (chan *msg.ExecuteScriptResponse, error)

func (*Session) SendExecuteScriptStream added in v0.23.0

func (s *Session) SendExecuteScriptStream(execMsg *msg.ExecuteScriptStreamMessage) (io.ReadWriteCloser, error)

func (*Session) SendFind added in v0.30.0

func (s *Session) SendFind(f *msg.FindMessage) (chan *msg.FindResponse, error)

SendFind sends a FindMessage to the agent and returns the response.

func (*Session) SendGrep added in v0.30.0

func (s *Session) SendGrep(g *msg.GrepMessage) (chan *msg.GrepResponse, error)

SendGrep sends a GrepMessage to the agent and returns the response.

func (*Session) SendNotificationMethod added in v0.28.0

func (s *Session) SendNotificationMethod(call *msg.CallMethodRequest) error

SendNotificationMethod forwards a notification to the agent without waiting for a JSON-RPC response.

func (*Session) SendPortForward added in v0.22.2

func (s *Session) SendPortForward(portCmd *msg.PortForwardRequest) (*msg.PortForwardResponse, error)

func (*Session) SendPortList added in v0.22.2

func (s *Session) SendPortList() (*msg.PortListResponse, error)

func (*Session) SendPortStop added in v0.22.2

func (s *Session) SendPortStop(portCmd *msg.PortStopRequest) (*msg.PortStopResponse, error)

func (*Session) SendRunCommand added in v0.19.0

func (s *Session) SendRunCommand(runCmd *msg.RunCommandMessage) (chan *msg.RunCommandResponse, error)

func (*Session) SendSed added in v0.30.0

func (s *Session) SendSed(sd *msg.SedMessage) (chan *msg.SedResponse, error)

SendSed sends a SedMessage to the agent and returns the response.

func (*Session) SendThrottle added in v0.31.0

func (s *Session) SendThrottle(req *msg.ThrottlePortRequest) (*msg.ThrottlePortResponse, error)

func (*Session) SendTunnelList added in v0.29.0

func (s *Session) SendTunnelList() (*msg.TunnelListResponse, error)

func (*Session) SendTunnelStart added in v0.29.0

func (s *Session) SendTunnelStart(req *msg.TunnelStartRequest) (*msg.TunnelStartResponse, error)

func (*Session) SendTunnelStop added in v0.29.0

func (s *Session) SendTunnelStop(req *msg.TunnelStopRequest) (*msg.TunnelStopResponse, error)

func (*Session) SendUpdateAuthorizedKeys

func (s *Session) SendUpdateAuthorizedKeys(sshKeys []string, sshPrivateKey string, githubUsernames []string) error

func (*Session) SendUpdateHealthConfig added in v0.28.0

func (s *Session) SendUpdateHealthConfig(config *msg.HealthConfig) error

func (*Session) SendUpdateShell added in v0.11.5

func (s *Session) SendUpdateShell(shell string) error

func (*Session) SetLastPingAt added in v0.29.0

func (s *Session) SetLastPingAt(t time.Time)

SetLastPingAt records the time of the last successful mux ping.

func (*Session) SetLastStateAt added in v0.28.0

func (s *Session) SetLastStateAt(t time.Time)

SetLastStateAt records the time of the last state report.

func (*Session) TelemetryLive added in v0.29.0

func (s *Session) TelemetryLive() bool

TelemetryLive reports whether a real agent state report (CmdUpdateState) has been received within the agent liveness window. A successful mux ping does NOT count: the state-reporting loop and the ping responder are independent goroutines, so a wedged state loop can leave a ping-alive session holding a frozen last reading. Callers that want to present data as "current" (e.g. the usage gauge) must check this rather than just session presence.

func (*Session) UnregisterLogListener added in v0.11.5

func (s *Session) UnregisterLogListener(listenerId string)

Jump to

Keyboard shortcuts

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