observability

package
v0.13.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const DefaultLogReadLimit = 1000
View Source
const SystemLogEntityID = "system/miren-server"

SystemLogEntityID is the well-known entity ID for system/server logs.

Variables

This section is empty.

Functions

func CGroupPathForPid

func CGroupPathForPid(pid uint32) (string, error)

func WaitForVictoriaLogs added in v0.5.0

func WaitForVictoriaLogs(ctx context.Context, address string, timeout time.Duration) bool

WaitForVictoriaLogs blocks until VictoriaLogs is reachable or the context is cancelled. Returns true if VictoriaLogs became available.

Types

type BatchErrorHandler added in v0.13.0

type BatchErrorHandler func(err error, dropped int)

BatchErrorHandler reports a batch that never reached VictoriaLogs. dropped is the number of entries lost with it; the buffer is not retried, so they are gone by the time this is called.

It runs synchronously on the flush loop, so it must return promptly. A handler that blocks holds up every later flush while WriteEntry keeps accepting entries with no backpressure, so the buffer grows for exactly as long as the block lasts. That is worst at precisely the wrong moment, since whatever is making the handler slow is likely the same outage that made the flush fail. Hand slow work to something else rather than doing it here.

Think about where this reports before setting it on a writer that receives the process's own logs. The coordinator tees its slog output into a BatchLogWriter (see cli/commands/server.go), so logging a flush failure through that same logger feeds the failure back into the buffer and re-amplifies it on every flush. Report somewhere that cannot loop back, or leave it unset.

type BatchLogWriter added in v0.5.0

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

BatchLogWriter implements LogWriter by buffering entries and flushing them as a single NDJSON HTTP POST to VictoriaLogs. This reduces write pressure compared to one POST per log record.

func NewBatchLogWriter added in v0.5.0

func NewBatchLogWriter(writer *PersistentLogWriter, opts ...BatchLogWriterOption) *BatchLogWriter

NewBatchLogWriter wraps a PersistentLogWriter with batching. Entries are buffered and flushed either every 250ms or when 50 entries accumulate, whichever comes first.

func (*BatchLogWriter) Close added in v0.5.0

func (b *BatchLogWriter) Close()

Close signals the background goroutine to perform a final flush and stop. It is safe to call multiple times.

func (*BatchLogWriter) WriteEntry added in v0.5.0

func (b *BatchLogWriter) WriteEntry(entity string, le LogEntry) error

WriteEntry marshals the entry to NDJSON and appends it to the internal buffer. It never blocks the caller — writes are best-effort.

type BatchLogWriterOption added in v0.13.0

type BatchLogWriterOption func(*BatchLogWriter)

BatchLogWriterOption customizes a BatchLogWriter at construction.

func WithBatchErrorHandler added in v0.13.0

func WithBatchErrorHandler(fn BatchErrorHandler) BatchLogWriterOption

WithBatchErrorHandler makes flush failures observable.

The default is to stay silent, which is what this writer has always done and is survivable while it carries a copy of logs that are also going to stderr. It stops being survivable once a writer is the only path for a runner's logs and the send can fail for a reason nobody would guess, an expired credential being the obvious one. Callers in that position should set this.

type BoundPort

type BoundPort struct {
	Addr netip.Addr
	Port int
}

type DebugLogWriter

type DebugLogWriter struct {
	Log *slog.Logger
}

func NewDebugLogWriter added in v0.3.0

func NewDebugLogWriter(log *slog.Logger) *DebugLogWriter

NewDebugLogWriter creates a new DebugLogWriter.

func (*DebugLogWriter) WriteEntry

func (d *DebugLogWriter) WriteEntry(entity string, le LogEntry) error

type EntityStatus

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

func (*EntityStatus) Id

func (e *EntityStatus) Id() string

type LogEntry

type LogEntry struct {
	Timestamp  time.Time
	Stream     LogStream
	TraceID    string
	Attributes map[string]string
	Extra      map[string]string
	Body       string
}

type LogReader

type LogReader struct {
	Address string
	Timeout time.Duration
	// contains filtered or unexported fields
}

func NewLogReader added in v0.3.0

func NewLogReader(address string, timeout time.Duration) *LogReader

NewLogReader creates a new LogReader.

func (*LogReader) Read

func (l *LogReader) Read(ctx context.Context, id string, opts ...LogReaderOption) ([]LogEntry, error)

func (*LogReader) ReadBySandbox

func (l *LogReader) ReadBySandbox(ctx context.Context, sandboxID string, opts ...LogReaderOption) ([]LogEntry, error)

func (*LogReader) ReadStream

func (l *LogReader) ReadStream(ctx context.Context, target LogTarget, logCh chan<- LogEntry, opts ...LogReaderOption) error

ReadStream queries historical logs and sends them to a channel as they're parsed. Unlike Read(), this has no limit and streams results incrementally.

func (*LogReader) TailStream

func (l *LogReader) TailStream(ctx context.Context, target LogTarget, logCh chan<- LogEntry, opts ...LogReaderOption) error

TailStream connects to VictoriaLogs tail endpoint for live tailing. Blocks until context is cancelled.

type LogReaderOption

type LogReaderOption func(*logReadOpts)

func WithFromTime

func WithFromTime(t time.Time) LogReaderOption

func WithLimit

func WithLimit(l int) LogReaderOption

func WithUntilTime added in v0.11.0

func WithUntilTime(t time.Time) LogReaderOption

WithUntilTime bounds the query to entries at or before t. When unset, queries read up to the present.

type LogStream

type LogStream string
const (
	Stdout  LogStream = "stdout"
	Stderr  LogStream = "stderr"
	Error   LogStream = "error"
	UserOOB LogStream = "user-oob"
)

type LogTarget

type LogTarget struct {
	EntityID  string
	SandboxID string
	Filter    string // Optional LogsQL filter expression (e.g., "error" or ~"regex")
}

LogTarget specifies what logs to query - either by entity ID or sandbox ID.

func (LogTarget) Query added in v0.2.0

func (t LogTarget) Query() string

Query returns the LogsQL query string for this target.

type LogWriter

type LogWriter interface {
	WriteEntry(entity string, le LogEntry) error
}

type LogWriterOption added in v0.13.0

type LogWriterOption func(*PersistentLogWriter)

LogWriterOption customizes a PersistentLogWriter at construction.

func WithHTTPClient added in v0.13.0

func WithHTTPClient(client *http.Client) LogWriterOption

WithHTTPClient replaces the writer's default HTTP client.

Callers that cannot reach VictoriaLogs with a plain client supply their own. A distributed runner ships logs through the coordinator rather than dialing VictoriaLogs directly, which means an HTTP/3 transport carrying a credential. Putting that in the client's RoundTripper keeps this writer unaware of how it is authenticated. BatchLogWriter borrows this client, so wrapping a writer in batching preserves the transport.

type LogsMaintainer

type LogsMaintainer struct {
}

func NewLogsMaintainer added in v0.3.0

func NewLogsMaintainer() *LogsMaintainer

NewLogsMaintainer creates a new LogsMaintainer.

func (*LogsMaintainer) Setup

func (m *LogsMaintainer) Setup(ctx context.Context) error

type PersistentLogReader

type PersistentLogReader struct {
	Address string
	Timeout time.Duration
	// contains filtered or unexported fields
}

func NewPersistentLogReader added in v0.3.0

func NewPersistentLogReader(address string, timeout time.Duration) *PersistentLogReader

NewPersistentLogReader creates a new PersistentLogReader.

func (*PersistentLogReader) Read

func (l *PersistentLogReader) Read(ctx context.Context, id string) ([]LogEntry, error)

type PersistentLogWriter

type PersistentLogWriter struct {
	Address string
	Timeout time.Duration
	// contains filtered or unexported fields
}

func NewPersistentLogWriter added in v0.3.0

func NewPersistentLogWriter(address string, timeout time.Duration, opts ...LogWriterOption) *PersistentLogWriter

NewPersistentLogWriter creates a new PersistentLogWriter.

func (*PersistentLogWriter) Client

func (l *PersistentLogWriter) Client() *http.Client

func (*PersistentLogWriter) WriteEntry

func (l *PersistentLogWriter) WriteEntry(entity string, le LogEntry) error

type PortStatus

type PortStatus string
const (
	PortStatusBound   PortStatus = "bound"
	PortStatusUnbound PortStatus = "unbound"
	PortStatusActive  PortStatus = "active"
)

type PortTracker

type PortTracker interface {
	SetPortStatus(containerID string, bp BoundPort, status PortStatus)
}

type ResourcesMonitor

type ResourcesMonitor struct {
	Log    *slog.Logger
	Writer *metrics.VictoriaMetricsWriter
	Reader *metrics.VictoriaMetricsReader
}

func NewResourcesMonitor added in v0.3.0

func NewResourcesMonitor(log *slog.Logger, writer *metrics.VictoriaMetricsWriter, reader *metrics.VictoriaMetricsReader) *ResourcesMonitor

NewResourcesMonitor creates a new ResourcesMonitor.

func (*ResourcesMonitor) LastestUsage

func (m *ResourcesMonitor) LastestUsage(id string) (float64, uint64, error)

func (*ResourcesMonitor) Monitor

func (m *ResourcesMonitor) Monitor(ctx context.Context, id, cgroupPath string) error

func (*ResourcesMonitor) Setup

func (m *ResourcesMonitor) Setup(ctx context.Context) error

type StatusMonitor

type StatusMonitor struct {
	Log *slog.Logger
	// contains filtered or unexported fields
}

func NewStatusMonitor added in v0.3.0

func NewStatusMonitor(log *slog.Logger) *StatusMonitor

NewStatusMonitor creates a new StatusMonitor.

func (*StatusMonitor) EntityBoundPorts

func (s *StatusMonitor) EntityBoundPorts(entity string) ([]BoundPort, error)

func (*StatusMonitor) FindBoundPort

func (s *StatusMonitor) FindBoundPort(bp BoundPort) ([]*EntityStatus, error)

func (*StatusMonitor) SetPortStatus

func (s *StatusMonitor) SetPortStatus(entity string, port BoundPort, status PortStatus)

type SystemLogHandler added in v0.5.0

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

SystemLogHandler is an slog.Handler that tees log records to both an underlying handler (typically stderr) and a VictoriaLogs log writer. This enables querying server logs through the same `miren logs system` interface used for application and sandbox logs.

func NewSystemLogHandler added in v0.5.0

func NewSystemLogHandler(inner slog.Handler, writer LogWriter) *SystemLogHandler

NewSystemLogHandler wraps an existing handler, adding a tee to the given log writer. All log records are written to VictoriaLogs under the SystemLogEntityID entity with source:"system".

func (*SystemLogHandler) Enabled added in v0.5.0

func (h *SystemLogHandler) Enabled(ctx context.Context, level slog.Level) bool

func (*SystemLogHandler) Handle added in v0.5.0

func (h *SystemLogHandler) Handle(ctx context.Context, record slog.Record) error

func (*SystemLogHandler) WithAttrs added in v0.5.0

func (h *SystemLogHandler) WithAttrs(attrs []slog.Attr) slog.Handler

func (*SystemLogHandler) WithGroup added in v0.5.0

func (h *SystemLogHandler) WithGroup(name string) slog.Handler

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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