file

package
v0.0.0-...-5655933 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2023 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultSleepDuration = 1 * time.Second

DefaultSleepDuration represents the amount of time the tailer waits before reading new data when no data is received

Variables

View Source
var ContainersLogsDir = "/var/log/containers"

ContainersLogsDir is the directory in which we should find containers logsfile with the container ID in their filename. Public to be able to change it while running unit tests.

Functions

func DidRotate

func DidRotate(file *os.File, lastReadOffset int64) (bool, error)

DidRotate returns true if the file has been log-rotated. When a log rotation occurs, the file can be either: - renamed and recreated - removed and recreated - truncated

func NewDecoderFromSource

func NewDecoderFromSource(source *logsconfig.LogSource) *decoder.Decoder

NewDecoderFromSource creates a new decoder from a log source

func NewDecoderFromSourceWithPattern

func NewDecoderFromSourceWithPattern(source *logsconfig.LogSource, multiLinePattern *regexp.Regexp) *decoder.Decoder

NewDecoderFromSourceWithPattern creates a new decoder from a log source with a multiline pattern

func Position

func Position(registry auditor.Registry, identifier string, mode logsconfig.TailingMode) (int64, int, error)

Position returns the position from where logs should be collected.

Types

type File

type File struct {
	Path string
	// IsWildcardPath is set to true when the File has been discovered
	// in a directory with wildcard(s) in the configuration.
	IsWildcardPath bool
	Source         *logsconfig.LogSource
}

File represents a file to tail

func NewFile

func NewFile(path string, source *logsconfig.LogSource, isWildcardPath bool) *File

NewFile returns a new File

func (*File) GetScanKey

func (t *File) GetScanKey() string

GetScanKey returns a key used by the scanner to index the scanned file. If it is a file scanned for a container, it will use the format: <filepath>/<container_id> Otherwise, it will simply use the format: <filepath>

type Provider

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

Provider implements the logic to retrieve at most filesLimit Files defined in sources

func NewProvider

func NewProvider(filesLimit int) *Provider

NewProvider returns a new Provider

func (*Provider) CollectFiles

func (p *Provider) CollectFiles(source *logsconfig.LogSource) ([]*File, error)

CollectFiles returns all the files matching the source path.

func (*Provider) FilesToTail

func (p *Provider) FilesToTail(sources []*logsconfig.LogSource) []*File

FilesToTail returns all the Files matching paths in sources, it cannot return more than filesLimit Files. For now, there is no way to prioritize specific Files over others, they are just returned in reverse lexicographical order, see `searchFiles`

type Scanner

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

Scanner checks all files provided by fileProvider and create new tailers or update the old ones if needed

func NewScanner

func NewScanner(sources *logsconfig.LogSources, tailingLimit int, pipelineProvider pipeline.Provider, registry auditor.Registry,
	tailerSleepDuration time.Duration, validatePodContainerID bool, scanPeriod time.Duration) *Scanner

NewScanner returns a new scanner.

func (*Scanner) Start

func (s *Scanner) Start()

Start starts the Scanner

func (*Scanner) Stop

func (s *Scanner) Stop()

Stop stops the Scanner and its tailers in parallel, this call returns only when all the tailers are stopped

type Tailer

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

Tailer tails one file and sends messages to an output channel

func NewTailer

func NewTailer(outputChan chan *message.Message, file *File, sleepDuration time.Duration, decoder *decoder.Decoder) *Tailer

NewTailer returns an initialized Tailer

func (*Tailer) GetDetectedPattern

func (t *Tailer) GetDetectedPattern() *regexp.Regexp

GetDetectedPattern returns a regexp if a pattern was detected

func (*Tailer) GetReadOffset

func (t *Tailer) GetReadOffset() int64

GetReadOffset returns the position of the last byte read in file

func (*Tailer) Identifier

func (t *Tailer) Identifier() string

Identifier returns a string that uniquely identifies a source. This is the identifier used in the registry. FIXME(remy): during container rotation, this Identifier() method could return the same value for different tailers. It is happening during container rotation where the dead container still has a tailer running on the log file, and the tailer of the freshly spawned container starts tailing this file as well.

func (*Tailer) SetDecodedOffset

func (t *Tailer) SetDecodedOffset(off int64)

SetDecodedOffset sets the position of the last byte decoded in the file

func (*Tailer) SetReadOffset

func (t *Tailer) SetReadOffset(off int64)

SetReadOffset sets the position of the last byte read in the file

func (*Tailer) Start

func (t *Tailer) Start(offset int64, whence int) error

Start let's the tailer open a file and tail from whence

func (*Tailer) StartFromBeginning

func (t *Tailer) StartFromBeginning() error

StartFromBeginning lets the tailer start tailing its file from the beginning

func (*Tailer) Stop

func (t *Tailer) Stop()

Stop stops the tailer and returns only when the decoder is flushed

func (*Tailer) StopAfterFileRotation

func (t *Tailer) StopAfterFileRotation()

StopAfterFileRotation prepares the tailer to stop after a timeout to finish reading its file that has been log-rotated

Jump to

Keyboard shortcuts

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