logs

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package logs tails container and host log files per the contract in docs/log-contract.md.

Index

Constants

View Source
const (
	DefaultMaxLineBytes       = 64 << 10
	DefaultPollInterval       = time.Second
	DefaultCheckpointInterval = 10 * time.Second
	DefaultReadBudget         = 4 << 20
	DefaultEnrichWait         = time.Minute
)

Defaults.

Variables

This section is empty.

Functions

This section is empty.

Types

type EnrichFunc

type EnrichFunc func(namespace, pod, uid, container string) map[string]string

EnrichFunc returns workload labels for a container, or nil while the pod is not yet known.

type Event

type Event struct {
	Kind      GapKind
	Path      string
	Labels    map[string]string
	Time      time.Time
	LostBytes int64
	Detail    string
}

Event discloses a gap. LostBytes is -1 when the amount is unknown.

type FileOptions

type FileOptions struct {
	Paths              []string
	Labels             map[string]string
	Store              kv.Store
	Sink               func(Line)
	OnEvent            func(Event)
	Filter             StreamFilter
	MaxLineBytes       int
	PollInterval       time.Duration
	CheckpointInterval time.Duration
	RescanInterval     time.Duration
	// RotatedIdle is how long a file renamed away keeps being read after it stops growing.
	RotatedIdle time.Duration
	ReadBudget  int64
	MaxDepth    int
	Clock       func() time.Time
}

FileOptions configures a FileTailer over allowlisted host paths (files or directories).

type FileTailer

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

FileTailer tails host log files; each file is a stream labeled filename.

func NewFileTailer

func NewFileTailer(o FileOptions) (*FileTailer, error)

NewFileTailer loads persisted offsets. Nothing is read until a filter is set.

func (*FileTailer) Checkpoint

func (ft *FileTailer) Checkpoint() error

Checkpoint persists offsets of every tailed file in one batch.

func (*FileTailer) Close

func (ft *FileTailer) Close() error

Close checkpoints and releases every open file.

func (*FileTailer) Poll

func (ft *FileTailer) Poll(ctx context.Context) error

Poll performs one discovery and read pass.

func (*FileTailer) Run

func (ft *FileTailer) Run(ctx context.Context) error

Run polls and checkpoints until ctx ends.

func (*FileTailer) SetFilter

func (ft *FileTailer) SetFilter(f StreamFilter)

SetFilter replaces the stream filter.

func (*FileTailer) Stats

func (ft *FileTailer) Stats() Stats

Stats returns counters.

type GapKind

type GapKind string

GapKind names a disclosed input gap.

const (
	GapTruncated        GapKind = "truncated"
	GapOffsetBeyondSize GapKind = "offset_beyond_size"
	GapMissedRotation   GapKind = "missed_rotation"
	GapReadError        GapKind = "read_error"
)

type Line

type Line struct {
	Labels    map[string]string
	Time      time.Time
	Text      string
	Truncated bool
}

Line is one delivered log line. Labels is shared by every line of its stream and must not be modified.

type Options

type Options struct {
	Root               string
	Node               string
	Store              kv.Store
	Sink               func(Line)
	OnEvent            func(Event)
	Filter             StreamFilter
	Enrich             EnrichFunc
	EnrichWait         time.Duration
	MaxLineBytes       int
	PollInterval       time.Duration
	CheckpointInterval time.Duration
	ReadBudget         int64
	Clock              func() time.Time
}

Options configures a pod log Tailer.

type RangeOptions

type RangeOptions struct {
	MaxLines     int
	MaxBytes     int64
	MaxScanBytes int64
	MaxLineBytes int
	Node         string
	Enrich       EnrichFunc
}

RangeOptions bounds an on-demand read. Zero values take the defaults.

type RangeResult

type RangeResult struct {
	Lines []Line
	// Truncated reports that older matching lines were omitted to respect MaxLines or MaxBytes.
	Truncated bool
	Omitted   int
	// ScanLimited reports that MaxScanBytes stopped the read before every candidate file was scanned.
	ScanLimited  bool
	FilesRead    int
	BytesScanned int64
}

RangeResult holds the newest matching lines in time order, newest last.

func ReadRange

func ReadRange(ctx context.Context, root string, sel StreamFilter, from, to time.Time, o RangeOptions) (*RangeResult, error)

ReadRange returns bounded lines in [from, to] from streams accepted by sel, retaining nothing.

type Stats

type Stats struct {
	Streams        int
	Files          int
	Lines          uint64
	Bytes          uint64
	TruncatedLines uint64
	Unparsed       uint64
	Gaps           uint64
}

Stats counts tailer activity.

type StreamFilter

type StreamFilter func(labels map[string]string) bool

StreamFilter decides from stream labels whether a stream is read at all.

type Tailer

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

Tailer tails /var/log/pods/<namespace>_<pod>_<uid>/<container>/<N>.log for accepted streams.

func NewTailer

func NewTailer(o Options) (*Tailer, error)

NewTailer loads persisted offsets. Nothing is read until a filter is set.

func (*Tailer) Checkpoint

func (t *Tailer) Checkpoint() error

Checkpoint persists offsets of every tailed stream in one batch.

func (*Tailer) Close

func (t *Tailer) Close() error

Close checkpoints and releases every open file.

func (*Tailer) Poll

func (t *Tailer) Poll(ctx context.Context) error

Poll performs one discovery and read pass.

func (*Tailer) Run

func (t *Tailer) Run(ctx context.Context) error

Run polls and checkpoints until ctx ends, then checkpoints and closes files.

func (*Tailer) SetFilter

func (t *Tailer) SetFilter(f StreamFilter)

SetFilter replaces the stream filter; it is re-evaluated for every stream on the next poll.

func (*Tailer) Stats

func (t *Tailer) Stats() Stats

Stats returns counters.

Jump to

Keyboard shortcuts

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