Documentation
¶
Overview ¶
Package diag holds the server-side in-memory ring buffer of diagnostic (operational) log records gathered from sqi-server itself and from connected workers. It is deliberately bounded and ephemeral: it provides a "recent glance" in the web UI, not a durable searchable archive. The buffer is lost on server restart by design (see the design spec, transport choice A1).
Index ¶
Constants ¶
const ServerComponent = "server"
ServerComponent is the component label for the sqi-server process's own logs.
Variables ¶
This section is empty.
Functions ¶
func NewServerSink ¶
NewServerSink returns a sqilog.Sink that appends sqi-server's own log records into buf under ServerComponent.
Types ¶
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer is a concurrency-safe, per-component bounded ring buffer of Record.
func NewBuffer ¶
NewBuffer creates a Buffer retaining up to perComponent records per component. notify, if non-nil, is called synchronously for every appended record (used to fan out to the WebSocket hub). notify MUST NOT emit slog records.
func (*Buffer) Append ¶
Append stores r under its component, evicting the oldest record for that component when the per-component cap is exceeded, then invokes notify. If the global component ceiling is exceeded after the insert, the component with the oldest most-recent record (LRU by latest activity) is evicted; ServerComponent is never chosen for eviction.
func (*Buffer) Query ¶
Query returns matching records in chronological (oldest-first) order, capped to Filter.Limit (newest retained when the cap truncates).
func (*Buffer) SetMaxComponents ¶
SetMaxComponents overrides the global ceiling on the number of distinct component rings retained. Values ≤ 0 are clamped to 1. Safe for concurrent use; typically called once at server boot to tune the default.
type Filter ¶
type Filter struct {
Component string // exact component match; empty = all components
MinLevel string // minimum level (DEBUG|INFO|WARN|ERROR); empty = all
TaskID string // match records whose Attrs["task_id"] equals this
Since time.Time // only records with Ts after this; zero = no lower bound
Limit int // max records returned (newest kept); <=0 = default 200
}
Filter selects records in a Buffer.Query. Zero-valued fields are ignored.
type Record ¶
type Record struct {
Ts time.Time `json:"ts"`
Component string `json:"component"` // "server" or "worker:<id>"
Level string `json:"level"` // DEBUG|INFO|WARN|ERROR
Msg string `json:"msg"`
Attrs map[string]string `json:"attrs,omitempty"`
}
Record is one diagnostic log entry held in the buffer.