fileconsumer

package
v0.55.0 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2022 License: Apache-2.0 Imports: 16 Imported by: 1

Documentation

Index

Constants

View Source
const DefaultFingerprintSize = 1000 // bytes
View Source
const MinFingerprintSize = 16 // bytes

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Finder                  `mapstructure:",squash" yaml:",inline"`
	IncludeFileName         bool                  `` /* 137-byte string literal not displayed */
	IncludeFilePath         bool                  `` /* 137-byte string literal not displayed */
	IncludeFileNameResolved bool                  `` /* 146-byte string literal not displayed */
	IncludeFilePathResolved bool                  `` /* 146-byte string literal not displayed */
	PollInterval            helper.Duration       `` /* 133-byte string literal not displayed */
	StartAt                 string                `` /* 128-byte string literal not displayed */
	FingerprintSize         helper.ByteSize       `` /* 136-byte string literal not displayed */
	MaxLogSize              helper.ByteSize       `` /* 132-byte string literal not displayed */
	MaxConcurrentFiles      int                   `` /* 140-byte string literal not displayed */
	Splitter                helper.SplitterConfig `` /* 127-byte string literal not displayed */
}

Config is the configuration of a file input operator

func NewConfig

func NewConfig() *Config

NewConfig creates a new input config with default values

func (Config) Build

func (c Config) Build(logger *zap.SugaredLogger, emit EmitFunc) (*Input, error)

Build will build a file input operator from the supplied configuration

type EmitFunc

type EmitFunc func(ctx context.Context, attrs *FileAttributes, token []byte)

type FileAttributes

type FileAttributes struct {
	Name         string
	Path         string
	NameResolved string
	PathResolved string
}

type Finder

type Finder struct {
	Include []string `mapstructure:"include,omitempty" json:"include,omitempty" yaml:"include,omitempty"`
	Exclude []string `mapstructure:"exclude,omitempty" json:"exclude,omitempty" yaml:"exclude,omitempty"`
}

func (Finder) FindFiles

func (f Finder) FindFiles() []string

FindFiles gets a list of paths given an array of glob patterns to include and exclude

type Fingerprint

type Fingerprint struct {
	FirstBytes []byte
}

Fingerprint is used to identify a file A file's fingerprint is the first N bytes of the file, where N is the fingerprintSize on the file_input operator

func (Fingerprint) Copy

func (f Fingerprint) Copy() *Fingerprint

Copy creates a new copy of the fingerprint

func (Fingerprint) StartsWith

func (f Fingerprint) StartsWith(old *Fingerprint) bool

StartsWith returns true if the fingerprints are the same or if the new fingerprint starts with the old one This is important functionality for tracking new files, since their initial size is typically less than that of a fingerprint. As the file grows, its fingerprint is updated until it reaches a maximum size, as configured on the operator

type Input

type Input struct {
	*zap.SugaredLogger

	PollInterval       time.Duration
	SplitterConfig     helper.SplitterConfig
	MaxLogSize         int
	MaxConcurrentFiles int
	SeenPaths          map[string]struct{}
	// contains filtered or unexported fields
}

TODO rename this struct

func (*Input) NewFingerprint

func (f *Input) NewFingerprint(file *os.File) (*Fingerprint, error)

NewFingerprint creates a new fingerprint from an open file

func (*Input) NewReader

func (f *Input) NewReader(path string, file *os.File, fp *Fingerprint, splitter *helper.Splitter, emit EmitFunc) (*Reader, error)

NewReader creates a new file reader

func (*Input) Start

func (f *Input) Start(persister operator.Persister) error

func (*Input) Stop

func (f *Input) Stop() error

Stop will stop the file monitoring process

type PositionalScanner

type PositionalScanner struct {
	*bufio.Scanner
	// contains filtered or unexported fields
}

PositionalScanner is a scanner that maintains position

func NewPositionalScanner

func NewPositionalScanner(r io.Reader, maxLogSize int, startOffset int64, splitFunc bufio.SplitFunc) *PositionalScanner

NewPositionalScanner creates a new positional scanner

func (*PositionalScanner) Pos

func (ps *PositionalScanner) Pos() int64

Pos returns the current position of the scanner

type Reader

type Reader struct {
	Fingerprint *Fingerprint
	Offset      int64

	*zap.SugaredLogger `json:"-"`
	// contains filtered or unexported fields
}

Reader manages a single file

func (*Reader) Close

func (r *Reader) Close()

Close will close the file

func (*Reader) Copy

func (r *Reader) Copy(file *os.File) (*Reader, error)

Copy creates a deep copy of a Reader

func (*Reader) InitializeOffset

func (r *Reader) InitializeOffset(startAtBeginning bool) error

InitializeOffset sets the starting offset

func (*Reader) Read

func (r *Reader) Read(dst []byte) (int, error)

Read from the file and update the fingerprint if necessary

func (*Reader) ReadToEnd

func (r *Reader) ReadToEnd(ctx context.Context)

ReadToEnd will read until the end of the file

Jump to

Keyboard shortcuts

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