diag

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

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

View Source
const ServerComponent = "server"

ServerComponent is the component label for the sqi-server process's own logs.

Variables

This section is empty.

Functions

func NewServerSink

func NewServerSink(buf *Buffer) sqilog.Sink

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

func NewBuffer(perComponent int, notify func(Record)) *Buffer

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

func (b *Buffer) Append(r Record)

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

func (b *Buffer) Query(f Filter) []Record

Query returns matching records in chronological (oldest-first) order, capped to Filter.Limit (newest retained when the cap truncates).

func (*Buffer) SetMaxComponents

func (b *Buffer) SetMaxComponents(n int)

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.

func (*Buffer) SetNotify

func (b *Buffer) SetNotify(fn func(Record))

SetNotify sets (or replaces) the per-append notify callback. Intended to be called once during boot (e.g. after the WebSocket hub exists) before heavy traffic. Safe for concurrent use.

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.

Jump to

Keyboard shortcuts

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