Documentation
¶
Index ¶
- Constants
- func CGroupPathForPid(pid uint32) (string, error)
- func WaitForVictoriaLogs(ctx context.Context, address string, timeout time.Duration) bool
- type BatchErrorHandler
- type BatchLogWriter
- type BatchLogWriterOption
- type BoundPort
- type DebugLogWriter
- type EntityStatus
- type LogEntry
- type LogReader
- func (l *LogReader) Read(ctx context.Context, id string, opts ...LogReaderOption) ([]LogEntry, error)
- func (l *LogReader) ReadBySandbox(ctx context.Context, sandboxID string, opts ...LogReaderOption) ([]LogEntry, error)
- func (l *LogReader) ReadStream(ctx context.Context, target LogTarget, logCh chan<- LogEntry, ...) error
- func (l *LogReader) TailStream(ctx context.Context, target LogTarget, logCh chan<- LogEntry, ...) error
- type LogReaderOption
- type LogStream
- type LogTarget
- type LogWriter
- type LogWriterOption
- type LogsMaintainer
- type PersistentLogReader
- type PersistentLogWriter
- type PortStatus
- type PortTracker
- type ResourcesMonitor
- type StatusMonitor
- type SystemLogHandler
Constants ¶
const DefaultLogReadLimit = 1000
const SystemLogEntityID = "system/miren-server"
SystemLogEntityID is the well-known entity ID for system/server logs.
Variables ¶
This section is empty.
Functions ¶
func CGroupPathForPid ¶
Types ¶
type BatchErrorHandler ¶ added in v0.13.0
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 DebugLogWriter ¶
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 LogReader ¶
type LogReader struct {
Address string
Timeout time.Duration
// contains filtered or unexported fields
}
func NewLogReader ¶ added in v0.3.0
NewLogReader creates a new LogReader.
func (*LogReader) ReadBySandbox ¶
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 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.
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.
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.
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)
type StatusMonitor ¶
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".