Documentation
¶
Overview ¶
Package logs tails container and host log files per the contract in docs/log-contract.md.
Index ¶
Constants ¶
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 ¶
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.
type Line ¶
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 ¶
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 (*Tailer) Checkpoint ¶
Checkpoint persists offsets of every tailed stream in one batch.
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.