decoder

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: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Utf16leEOL is the bytes sequence for UTF-16 Little-Endian end-of-line char
	Utf16leEOL = []byte{'\n', 0x00}
	// Utf16beEOL is the bytes sequence for UTF-16 Big-Endian end-of-line char
	Utf16beEOL = []byte{0x00, '\n'}
)

Functions

This section is empty.

Types

type AutoMultilineHandler

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

AutoMultilineHandler can attempts to detect a known/commob pattern (a timestamp) in the logs and will switch to a MultiLine handler if one is detected and the thresholds are met.

func NewAutoMultilineHandler

func NewAutoMultilineHandler(outputChan chan *Message,
	lineLimit, linesToAssess int,
	matchThreshold float64,
	matchTimeout time.Duration,
	flushTimeout time.Duration,
	source *logsconfig.LogSource,
	additionalPatterns []*regexp.Regexp,
	detectedPattern *DetectedPattern,
) *AutoMultilineHandler

NewAutoMultilineHandler returns a new AutoMultilineHandler.

func (*AutoMultilineHandler) Handle

func (h *AutoMultilineHandler) Handle(input *Message)

Handle puts all new lines into a channel for later processing.

func (*AutoMultilineHandler) Start

func (h *AutoMultilineHandler) Start()

Start starts the handler.

func (*AutoMultilineHandler) Stop

func (h *AutoMultilineHandler) Stop()

Stop stops the handler.

type BytesSequenceMatcher

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

BytesSequenceMatcher defines the criterion to whether to end a line based on an arbitrary byte sequence

func NewBytesSequenceMatcher

func NewBytesSequenceMatcher(sequence []byte) *BytesSequenceMatcher

NewBytesSequenceMatcher Returns a new matcher based on custom bytes sequence

func (*BytesSequenceMatcher) Match

func (b *BytesSequenceMatcher) Match(exists []byte, appender []byte, start int, end int) bool

Match returns true whenever it finds a matching sequence at the end of append(exists, appender[start:end+1])

func (*BytesSequenceMatcher) SeparatorLen

func (b *BytesSequenceMatcher) SeparatorLen() int

SeparatorLen return the number of byte to ignore

type DecodedInput

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

DecodedInput represents a decoded line and the raw length

func NewDecodedInput

func NewDecodedInput(content []byte, rawDataLen int) *DecodedInput

NewDecodedInput returns a new decoded input.

type Decoder

type Decoder struct {
	InputChan  chan *Input
	OutputChan chan *Message
	// contains filtered or unexported fields
}

Decoder splits raw data into lines and passes them to a lineParser that passes them to a lineHandler that emits outputs Input->[decoder]->[parser]->[handler]->Message

func InitializeDecoder

func InitializeDecoder(source *config.LogSource, parser parser.Parser) *Decoder

InitializeDecoder returns a properly initialized Decoder

func New

func New(InputChan chan *Input, OutputChan chan *Message, lineParser LineParser, contentLenLimit int, matcher EndLineMatcher, detectedPattern *DetectedPattern) *Decoder

New returns an initialized Decoder

func NewDecoderWithEndLineMatcher

func NewDecoderWithEndLineMatcher(source *config.LogSource, parser parser.Parser, matcher EndLineMatcher, multiLinePattern *regexp.Regexp) *Decoder

NewDecoderWithEndLineMatcher initialize a decoder with given endline strategy.

func (*Decoder) GetDetectedPattern

func (d *Decoder) GetDetectedPattern() *regexp.Regexp

GetDetectedPattern returns a detected pattern (if any)

func (*Decoder) GetLineCount

func (d *Decoder) GetLineCount() int64

GetLineCount returns the number of decoded lines

func (*Decoder) Start

func (d *Decoder) Start()

Start starts the Decoder

func (*Decoder) Stop

func (d *Decoder) Stop()

Stop stops the Decoder

type DetectedPattern

type DetectedPattern struct {
	sync.Mutex
	// contains filtered or unexported fields
}

DetectedPattern is a container to safely access a detected multiline pattern

func (*DetectedPattern) Get

func (d *DetectedPattern) Get() *regexp.Regexp

Get gets the pattern

func (*DetectedPattern) Set

func (d *DetectedPattern) Set(pattern *regexp.Regexp)

Set sets the pattern

type EndLineMatcher

type EndLineMatcher interface {
	// Match takes the existing bytes and the bytes to be appended, returns
	// true if the combination matches the end of line condition.
	Match(exists []byte, appender []byte, start int, end int) bool
	SeparatorLen() int
}

EndLineMatcher defines the criterion to whether to end a line or not.

type Input

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

Input represents a chunk of line.

func NewInput

func NewInput(content []byte) *Input

NewInput returns a new input.

type LineHandler

type LineHandler interface {
	Handle(input *Message)
	Start()
	Stop()
}

LineHandler handles raw lines to form structured lines

type LineParser

type LineParser interface {
	Handle(input *DecodedInput)
	Start()
	Stop()
}

LineParser e

type Message

type Message struct {
	Content            []byte
	Status             string
	RawDataLen         int
	Timestamp          string
	IngestionTimestamp int64
}

Message represents a structured line.

func NewMessage

func NewMessage(content []byte, status string, rawDataLen int, timestamp string) *Message

NewMessage returns a new output.

type MultiLineHandler

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

MultiLineHandler makes sure that multiple lines from a same content are properly put together.

func NewMultiLineHandler

func NewMultiLineHandler(outputChan chan *Message, newContentRe *regexp.Regexp, flushTimeout time.Duration, lineLimit int) *MultiLineHandler

NewMultiLineHandler returns a new MultiLineHandler.

func (*MultiLineHandler) Handle

func (h *MultiLineHandler) Handle(input *Message)

Handle forward lines to lineChan to process them.

func (*MultiLineHandler) Start

func (h *MultiLineHandler) Start()

Start starts the handler.

func (*MultiLineHandler) Stop

func (h *MultiLineHandler) Stop()

Stop stops the handler.

type MultiLineParser

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

MultiLineParser makes sure that chunked lines are properly put together.

func NewMultiLineParser

func NewMultiLineParser(flushTimeout time.Duration, parser parser.Parser, lineHandler LineHandler, lineLimit int) *MultiLineParser

NewMultiLineParser returns a new MultiLineParser.

func (*MultiLineParser) Handle

func (p *MultiLineParser) Handle(input *DecodedInput)

Handle forward lines to lineChan to process them.

func (*MultiLineParser) Start

func (p *MultiLineParser) Start()

Start starts the handler.

func (*MultiLineParser) Stop

func (p *MultiLineParser) Stop()

Stop stops the handler.

type NewLineMatcher

type NewLineMatcher struct {
	EndLineMatcher
}

NewLineMatcher implements EndLineMatcher for line ending with '\n'

func (*NewLineMatcher) Match

func (n *NewLineMatcher) Match(exists []byte, appender []byte, start int, end int) bool

Match returns true whenever a '\n' (newline) is met.

func (*NewLineMatcher) SeparatorLen

func (n *NewLineMatcher) SeparatorLen() int

SeparatorLen returns the length of the line separator

type SingleLineHandler

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

SingleLineHandler takes care of tracking the line length and truncating them when they are too long.

func NewSingleLineHandler

func NewSingleLineHandler(outputChan chan *Message, lineLimit int) *SingleLineHandler

NewSingleLineHandler returns a new SingleLineHandler.

func (*SingleLineHandler) Handle

func (h *SingleLineHandler) Handle(input *Message)

Handle puts all new lines into a channel for later processing.

func (*SingleLineHandler) Start

func (h *SingleLineHandler) Start()

Start starts the handler.

func (*SingleLineHandler) Stop

func (h *SingleLineHandler) Stop()

Stop stops the handler.

type SingleLineParser

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

SingleLineParser makes sure that multiple lines from a same content are properly put together.

func NewSingleLineParser

func NewSingleLineParser(parser parser.Parser, lineHandler LineHandler) *SingleLineParser

NewSingleLineParser returns a new SingleLineParser.

func (*SingleLineParser) Handle

func (p *SingleLineParser) Handle(input *DecodedInput)

Handle puts all new lines into a channel for later processing.

func (*SingleLineParser) Start

func (p *SingleLineParser) Start()

Start starts the parser.

func (*SingleLineParser) Stop

func (p *SingleLineParser) Stop()

Stop stops the parser.

Jump to

Keyboard shortcuts

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