observability

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 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 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) *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 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
	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

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 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) *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