file

package
v0.0.0-...-2353f6e Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2025 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type File

type File struct {
	// Path contains the path to the file which should be tailed.
	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 is the ReplaceableSource that led to this File.
	Source *sources.ReplaceableSource
}

File represents a file to tail

func NewFile

func NewFile(path string, source *sources.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. The string uniquely identifies this File, even if sources for multiple containers use the same Path.

func (*File) Identifier

func (f *File) Identifier() string

type Fingerprinter

type Fingerprinter struct {
	FingerprintConfig types.FingerprintConfig
	// contains filtered or unexported fields
}

Fingerprinter is a struct that contains the fingerprinting configuration

func NewFingerprinter

func NewFingerprinter(fingerprintEnabled bool, fingerprintConfig types.FingerprintConfig) *Fingerprinter

NewFingerprinter creates a new Fingerprinter with the given configuration

func (*Fingerprinter) ComputeFingerprint

func (f *Fingerprinter) ComputeFingerprint(file *File) (*types.Fingerprint, error)

ComputeFingerprint computes the fingerprint for the given file path

func (*Fingerprinter) ComputeFingerprintFromConfig

func (f *Fingerprinter) ComputeFingerprintFromConfig(filepath string, fingerprintConfig *types.FingerprintConfig) (*types.Fingerprint, error)

ComputeFingerprintFromConfig computes the fingerprint for the given file path using a specific config

func (*Fingerprinter) GetFingerprintConfig

func (f *Fingerprinter) GetFingerprintConfig() *types.FingerprintConfig

GetFingerprintConfig returns the fingerprint configuration

func (*Fingerprinter) IsFingerprintingEnabled

func (f *Fingerprinter) IsFingerprintingEnabled() bool

IsFingerprintingEnabled returns whether or not our configuration has checksum fingerprinting enabled

func (*Fingerprinter) ShouldFileFingerprint

func (f *Fingerprinter) ShouldFileFingerprint(file *File) bool

ShouldFileFingerprint returns whether or not a given file should be fingerprinted to detect rotation and truncation

type Tailer

type Tailer struct {
	CapacityMonitor *metrics.CapacityMonitor
	// contains filtered or unexported fields
}

Tailer tails a file, decodes the messages it contains, and passes them to a supplied output channel for further processing.

Operational Overview

Tailers have three components, organized as a pipeline. The first, readForever, polls the file, trying to read more data. That data is passed to the second component, the decoder. The decoder produces decoder.Messages, which are passed to the third component, forwardMessages. This component translates the decoder.Messages into message.Messages and sends them to the tailer's output channel.

func NewTailer

func NewTailer(opts *TailerOptions) *Tailer

NewTailer returns an initialized Tailer, read to be started.

The resulting Tailer will read from the given `file`, decode the content with the given `decoder`, and send the resulting log messages to outputChan. The Tailer takes ownership of the decoder and will start and stop it as necessary.

The Tailer must poll for content in the file. The `sleepDuration` parameter specifies how long the tailer should wait between polls.

func (*Tailer) DidRotate

func (t *Tailer) DidRotate() (bool, error)

DidRotate returns true if the file has been log-rotated.

On *nix, when a log rotation occurs, the file can be either: - renamed and recreated - removed and recreated - truncated

func (*Tailer) DidRotateViaFingerprint

func (t *Tailer) DidRotateViaFingerprint(fingerprinter *Fingerprinter) (bool, error)

DidRotateViaFingerprint returns true if the file has been log-rotated via fingerprint.

On *nix, when a log rotation occurs, the file can be either: - renamed and recreated - removed and recreated - truncated

func (*Tailer) GetDetectedPattern

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

GetDetectedPattern returns the decoder's detected pattern.

func (*Tailer) GetId

func (t *Tailer) GetId() string

func (*Tailer) GetInfo

func (t *Tailer) GetInfo() *status.InfoRegistry

func (*Tailer) GetType

func (t *Tailer) GetType() string

func (*Tailer) Identifier

func (t *Tailer) Identifier() string

Identifier returns a string that identifies this tailer in the registry.

func (*Tailer) IsFinished

func (t *Tailer) IsFinished() bool

IsFinished returns true if the tailer has flushed all messages to the output channel, either because it has been stopped or because of an error reading from the input file.

func (*Tailer) NewRotatedTailer

func (t *Tailer) NewRotatedTailer(
	file *File,
	outputChan chan *message.Message,
	capacityMonitor *metrics.CapacityMonitor,
	decoder *decoder.Decoder,
	info *status.InfoRegistry,
	tagAdder tag.EntityTagAdder,
	fingerprint *logstypes.Fingerprint,
	registry auditor.Registry,
) *Tailer

NewRotatedTailer creates a new tailer that replaces this one, writing messages to a new channel and using an updated file and decoder.

func (*Tailer) ReplaceSource

func (t *Tailer) ReplaceSource(newSource *sources.LogSource)

ReplaceSource replaces the current source

func (*Tailer) Source

func (t *Tailer) Source() *sources.LogSource

Source gets the source (currently only used for testing)

func (*Tailer) Start

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

Start begins the tailer's operation in a dedicated goroutine.

func (*Tailer) StartFromBeginning

func (t *Tailer) StartFromBeginning() error

StartFromBeginning is a shortcut to start the tailer at the beginning of the file.

func (*Tailer) Stop

func (t *Tailer) Stop()

Stop stops the tailer and returns only after all in-flight messages have been flushed to the output channel.

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

type TailerOptions

type TailerOptions struct {
	OutputChan      chan *message.Message    // Required
	File            *File                    // Required
	SleepDuration   time.Duration            // Required
	Decoder         *decoder.Decoder         // Required
	Info            *status.InfoRegistry     // Required
	Rotated         bool                     // Optional
	TagAdder        tag.EntityTagAdder       // Required
	Fingerprint     *logstypes.Fingerprint   //Optional
	Registry        auditor.Registry         //Required
	CapacityMonitor *metrics.CapacityMonitor // Required
}

TailerOptions holds all possible parameters that NewTailer requires in addition to optional parameters that can be optionally passed into. This can be used for more optional parameters if required in future

Jump to

Keyboard shortcuts

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