agent_server

package
v0.33.0 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2026 License: Apache-2.0 Imports: 30 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

View Source
var LogSinkMirrorHook func(spaceId, userId, username, spaceName string, logMsg *msg.LogMessage)

LogSinkMirrorHook is called (leader-gated) for each log record received from a space, with the space id, its owner's user id and username, and the space name — owner scoping is enforced inside the implementation.

View Source
var LogSinkRegisterHook func(session *Session, user *model.User, port int, format string)

LogSinkRegisterHook is called when an agent advertises a log sink in its registration message. Receives the session and the (already loaded) owner.

View Source
var LogSinkUnregisterHook func(spaceId string)

LogSinkUnregisterHook is called when a space's session is removed, so a registered sink stops receiving mirrors.

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 NotifyScriptLibsChanged added in v0.33.0

func NotifyScriptLibsChanged(userId string)

NotifyScriptLibsChanged tells agents that a `lib`-type script changed on the server so they drop their cached libs.zip package. A non-empty userId (a user library change) targets that user's space agents; an empty userId (a global library change) broadcasts to every connected agent.

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
	UserId                string // owner of the space, used for log sink scoping
	Username              string // owner's username, attached to mirrored/forwarded logs
	SpaceName             string // space name, attached to mirrored/forwarded logs
	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) SendJobsList added in v0.33.0

func (s *Session) SendJobsList() (*spacejobs.JobsSnapshot, error)

SendJobsList asks the space's agent for its scheduled jobs snapshot.

func (*Session) SendJobsRun added in v0.33.0

func (s *Session) SendJobsRun(name string) (*msg.JobsResponse, error)

SendJobsRun asks the space's agent to start a job immediately.

func (*Session) SendMirrorLog added in v0.33.0

func (s *Session) SendMirrorLog(batch *msg.MirrorLogMessage) error

SendMirrorLog pushes a batch of mirrored log records to the space's agent (fire and forget — the agent writes them to its local log service).

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) SendScriptLibsChanged added in v0.33.0

func (s *Session) SendScriptLibsChanged() error

SendScriptLibsChanged sends the fire-and-forget libs-changed notification to the agent on a new mux stream.

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) SendUpdateJobs added in v0.33.0

func (s *Session) SendUpdateJobs(jobs []model.SpaceJob, enabled bool) error

SendUpdateJobs pushes the space's persisted job definitions and runner state to the agent. Fire-and-forget: if the agent is unreachable the push is skipped and the definitions re-arrive in its next registration response.

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