mgmt

package
v0.2.0 Latest Latest
Warning

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

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

Documentation

Overview

Package mgmt defines the control-socket protocol between the cliwrap management CLI and a running Manager.

Index

Constants

View Source
const (
	MsgListRequest     ipc.MsgType = 0xA0
	MsgListResponse    ipc.MsgType = 0xA1
	MsgStatusRequest   ipc.MsgType = 0xA2
	MsgStatusResponse  ipc.MsgType = 0xA3
	MsgLogsRequest     ipc.MsgType = 0xA4
	MsgLogsStream      ipc.MsgType = 0xA5
	MsgEventsSubscribe ipc.MsgType = 0xA6
	MsgEventsStream    ipc.MsgType = 0xA7
	MsgStartRequest    ipc.MsgType = 0xA8
	MsgStopRequest     ipc.MsgType = 0xA9
)

Management-specific message types. They reuse the ipc framing layer but use distinct numeric IDs in the 0xA0..0xAF range.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client is a synchronous client for the management socket. It is not safe for concurrent use - callers should open one per goroutine.

func Dial

func Dial(socketPath string) (*Client, error)

Dial opens a connection to the manager at socketPath.

func (*Client) Call

func (c *Client) Call(t ipc.MsgType, payload any) (ipc.Header, []byte, error)

Call sends a request and returns the response header and body.

func (*Client) Close

func (c *Client) Close() error

Close releases the connection.

func (*Client) ReadFrame added in v0.2.0

func (c *Client) ReadFrame() (ipc.Header, []byte, error)

ReadFrame reads one inbound frame from the server. Intended for use after Stream, where the server may push arbitrarily many frames. Returns io.EOF or a similar error when the server closes the connection.

func (*Client) Stream added in v0.2.0

func (c *Client) Stream(t ipc.MsgType, payload any) error

Stream sends a request without waiting for a response. Use this for streaming upgrades like MsgEventsSubscribe where the server pushes frames until the client disconnects. After Stream returns successfully, callers should drain frames via ReadFrame in a loop.

type EventsStreamPayload

type EventsStreamPayload struct {
	ProcessID string `msgpack:"pid"`
	Type      string `msgpack:"t"`
	Timestamp int64  `msgpack:"ts"`
	Summary   string `msgpack:"sum"`
}

EventsStreamPayload carries a serialized event summary.

type EventsSubscribePayload

type EventsSubscribePayload struct {
	ProcessIDs []string `msgpack:"pids"`
}

EventsSubscribePayload is sent by a client to subscribe to a stream of lifecycle events. An empty ProcessIDs slice subscribes to every process.

type ListEntry

type ListEntry struct {
	ID       string `msgpack:"id"`
	Name     string `msgpack:"name"`
	State    string `msgpack:"state"`
	ChildPID int    `msgpack:"pid"`
	RSS      uint64 `msgpack:"rss"`
}

ListEntry is one row in a list response.

type ListResponsePayload

type ListResponsePayload struct {
	Entries []ListEntry `msgpack:"entries"`
}

ListResponsePayload is returned for MsgListResponse.

type LogsRequestPayload

type LogsRequestPayload struct {
	ID     string `msgpack:"id"`
	Stream uint8  `msgpack:"s"`
	Follow bool   `msgpack:"f"`
}

LogsRequestPayload asks for log output from a process.

If Follow is false (the default), the server returns a single MsgLogsStream frame with EOF=true containing the current ring-buffer snapshot. If Follow is true, the server first sends the snapshot with EOF=false and then keeps the connection open, pushing additional MsgLogsStream frames (also EOF=false) as new chunks arrive, until the client disconnects or the manager shuts down.

type LogsStreamPayload

type LogsStreamPayload struct {
	ID     string `msgpack:"id"`
	Stream uint8  `msgpack:"s"`
	Data   []byte `msgpack:"d"`
	EOF    bool   `msgpack:"eof"`
}

LogsStreamPayload carries a single chunk of streamed log bytes.

type ManagerAPI

type ManagerAPI interface {
	List() []ListEntry
	StatusOf(id string) (ListEntry, error)
	Stop(ctx context.Context, id string) error
	LogsSnapshot(id string, stream uint8) []byte
	// WatchLogs returns a channel that delivers every log chunk
	// emitted for processID after the subscription is registered,
	// plus an unregister function the caller MUST invoke exactly
	// once. The channel closes when the manager shuts down.
	WatchLogs(processID string) (<-chan cwtypes.LogChunk, func())
	Events() event.Bus
}

ManagerAPI is the subset of Manager functionality the server exposes. Using an interface keeps tests decoupled from the concrete Manager.

type Server

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

Server listens on a Unix domain socket and handles management requests.

func NewServer

func NewServer(opts ServerOptions) (*Server, error)

NewServer returns a Server; call Start to begin accepting connections.

func (*Server) Close

func (s *Server) Close(ctx context.Context) error

Close stops the listener and waits for goroutines to exit.

func (*Server) Start

func (s *Server) Start() error

Start begins accepting connections in a background goroutine.

type ServerOptions

type ServerOptions struct {
	SocketPath string
	Manager    ManagerAPI
	SpillerDir string
}

ServerOptions configures the management server.

type StartRequestPayload

type StartRequestPayload struct {
	ID string `msgpack:"id"`
}

StartRequestPayload requests that a registered process be started.

type StatusRequestPayload

type StatusRequestPayload struct {
	ID string `msgpack:"id"`
}

StatusRequestPayload asks for a specific process's status.

type StatusResponsePayload

type StatusResponsePayload struct {
	Entry ListEntry `msgpack:"entry"`
	Err   string    `msgpack:"err"`
}

StatusResponsePayload summarizes one process.

type StopRequestPayload

type StopRequestPayload struct {
	ID string `msgpack:"id"`
}

StopRequestPayload requests that a running process be stopped.

Jump to

Keyboard shortcuts

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