log

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: May 28, 2021 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ConvertDuration = "duration"
	ConvertFloat    = "float"
)

Variables

View Source
var (
	NoopPipeline Pipeline = &noopPipeline{}
	NoopStage    Stage    = &noopStage{}
)
View Source
var (
	ErrorLabel = "__error__"
)
View Source
var (

	// NoopLabelFilter is a label filter that doesn't filter out any values.
	NoopLabelFilter = noopLabelFilter{}
)
View Source
var TrueFilter = trueFilter{}

TrueFilter is a filter that returns and matches all log lines whatever their content.

Functions

This section is empty.

Types

type BinaryLabelFilter

type BinaryLabelFilter struct {
	Left  LabelFilterer
	Right LabelFilterer
	// contains filtered or unexported fields
}

func NewAndLabelFilter

func NewAndLabelFilter(left LabelFilterer, right LabelFilterer) *BinaryLabelFilter

NewAndLabelFilter creates a new LabelFilterer from a and binary operation of two LabelFilterer.

func NewOrLabelFilter

func NewOrLabelFilter(left LabelFilterer, right LabelFilterer) *BinaryLabelFilter

NewOrLabelFilter creates a new LabelFilterer from a or binary operation of two LabelFilterer.

func (*BinaryLabelFilter) Process

func (b *BinaryLabelFilter) Process(line []byte, lbs *LabelsBuilder) ([]byte, bool)

func (*BinaryLabelFilter) String

func (b *BinaryLabelFilter) String() string

type BytesLabelFilter

type BytesLabelFilter struct {
	Name  string
	Value uint64
	Type  LabelFilterType
}

func NewBytesLabelFilter

func NewBytesLabelFilter(t LabelFilterType, name string, b uint64) *BytesLabelFilter

NewBytesLabelFilter creates a new label filterer which parses bytes string representation (1KB) from the value of the named label and compares it with the given b value.

func (*BytesLabelFilter) Process

func (d *BytesLabelFilter) Process(line []byte, lbs *LabelsBuilder) ([]byte, bool)

func (*BytesLabelFilter) String

func (d *BytesLabelFilter) String() string

type DurationLabelFilter

type DurationLabelFilter struct {
	Name  string
	Value time.Duration
	Type  LabelFilterType
}

func NewDurationLabelFilter

func NewDurationLabelFilter(t LabelFilterType, name string, d time.Duration) *DurationLabelFilter

NewDurationLabelFilter creates a new label filterer which parses duration string representation (5s) from the value of the named label and compares it with the given d value.

func (*DurationLabelFilter) Process

func (d *DurationLabelFilter) Process(line []byte, lbs *LabelsBuilder) ([]byte, bool)

func (*DurationLabelFilter) String

func (d *DurationLabelFilter) String() string

type Filterer

type Filterer interface {
	Filter(line []byte) bool
	ToStage() Stage
}

Filterer is a interface to filter log lines.

func NewAndFilter

func NewAndFilter(left Filterer, right Filterer) Filterer

NewAndFilter creates a new filter which matches only if left and right matches.

func NewFilter

func NewFilter(match string, mt labels.MatchType) (Filterer, error)

NewFilter creates a new line filter from a match string and type.

type FiltererFunc

type FiltererFunc func(line []byte) bool

LineFilterFunc is a syntax sugar for creating line filter from a function

func (FiltererFunc) Filter

func (f FiltererFunc) Filter(line []byte) bool

type JSONParser

type JSONParser struct{}

func NewJSONParser

func NewJSONParser() *JSONParser

NewJSONParser creates a log stage that can parse a json log line and add properties as labels.

func (*JSONParser) Process

func (j *JSONParser) Process(line []byte, lbs *LabelsBuilder) ([]byte, bool)

type LabelFilterType

type LabelFilterType int

LabelFilterType is an enum for label filtering types.

const (
	LabelFilterEqual LabelFilterType = iota
	LabelFilterNotEqual
	LabelFilterGreaterThan
	LabelFilterGreaterThanOrEqual
	LabelFilterLesserThan
	LabelFilterLesserThanOrEqual
)

Possible LabelFilterType.

func (LabelFilterType) String

func (f LabelFilterType) String() string

type LabelFilterer

type LabelFilterer interface {
	Stage
	fmt.Stringer
}

LabelFilterer can filter extracted labels.

func ReduceAndLabelFilter

func ReduceAndLabelFilter(filters []LabelFilterer) LabelFilterer

ReduceAndLabelFilter Reduces multiple label filterer into one using binary and operation.

type LabelFmt

type LabelFmt struct {
	Name  string
	Value string

	Rename bool
}

LabelFmt is a configuration struct for formatting a label.

func NewRenameLabelFmt

func NewRenameLabelFmt(dst, target string) LabelFmt

NewRenameLabelFmt creates a configuration to rename a label.

func NewTemplateLabelFmt

func NewTemplateLabelFmt(dst, template string) LabelFmt

NewTemplateLabelFmt creates a configuration to format a label using text template.

type LabelsBuilder

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

LabelsBuilder is the same as labels.Builder but tailored for this package.

func NewLabelsBuilder added in v1.7.0

func NewLabelsBuilder() *LabelsBuilder

NewLabelsBuilder creates a new labels builder.

func (*LabelsBuilder) Base added in v1.7.0

func (b *LabelsBuilder) Base() labels.Labels

Base returns the base labels unmodified

func (*LabelsBuilder) Del

func (b *LabelsBuilder) Del(ns ...string) *LabelsBuilder

Del deletes the label of the given name.

func (*LabelsBuilder) Get

func (b *LabelsBuilder) Get(key string) (string, bool)

func (*LabelsBuilder) GetErr

func (b *LabelsBuilder) GetErr() string

GetErr return the current error label value.

func (*LabelsBuilder) HasErr

func (b *LabelsBuilder) HasErr() bool

HasErr tells if the error label has been set.

func (*LabelsBuilder) Labels

func (b *LabelsBuilder) Labels() labels.Labels

Labels returns the labels from the builder. If no modifications were made, the original labels are returned.

func (*LabelsBuilder) Reset

func (b *LabelsBuilder) Reset(base labels.Labels)

Reset clears all current state for the builder.

func (*LabelsBuilder) Set

func (b *LabelsBuilder) Set(n, v string) *LabelsBuilder

Set the name/value pair as a label.

func (*LabelsBuilder) SetErr

func (b *LabelsBuilder) SetErr(err string) *LabelsBuilder

SetErr sets the error label.

func (*LabelsBuilder) WithLabels added in v1.7.0

func (b *LabelsBuilder) WithLabels(names ...string) labels.Labels

func (*LabelsBuilder) WithoutLabels added in v1.7.0

func (b *LabelsBuilder) WithoutLabels(names ...string) labels.Labels

type LabelsFormatter

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

func NewLabelsFormatter

func NewLabelsFormatter(fmts []LabelFmt) (*LabelsFormatter, error)

NewLabelsFormatter creates a new formatter that can format multiple labels at once. Either by renaming or using text template. It is not allowed to reformat the same label twice within the same formatter.

func (*LabelsFormatter) Process

func (lf *LabelsFormatter) Process(l []byte, lbs *LabelsBuilder) ([]byte, bool)

type LineExtractor

type LineExtractor func([]byte) float64

LineExtractor extracts a float64 from a log line.

var (
	CountExtractor LineExtractor = func(line []byte) float64 { return 1. }
	BytesExtractor LineExtractor = func(line []byte) float64 { return float64(len(line)) }
)

func (LineExtractor) ToSampleExtractor added in v1.7.0

func (l LineExtractor) ToSampleExtractor(groups []string, without bool, noLabels bool) SampleExtractor

ToSampleExtractor transform a LineExtractor into a SampleExtractor. Useful for metric conversion without log Pipeline.

type LineFormatter

type LineFormatter struct {
	*template.Template
	// contains filtered or unexported fields
}

func NewFormatter

func NewFormatter(tmpl string) (*LineFormatter, error)

NewFormatter creates a new log line formatter from a given text template.

func (*LineFormatter) Process

func (lf *LineFormatter) Process(_ []byte, lbs *LabelsBuilder) ([]byte, bool)

type LogfmtParser

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

func NewLogfmtParser

func NewLogfmtParser() *LogfmtParser

NewLogfmtParser creates a parser that can extract labels from a logfmt log line. Each keyval is extracted into a respective label.

func (*LogfmtParser) Process

func (l *LogfmtParser) Process(line []byte, lbs *LabelsBuilder) ([]byte, bool)

type NumericLabelFilter

type NumericLabelFilter struct {
	Name  string
	Value float64
	Type  LabelFilterType
}

func NewNumericLabelFilter

func NewNumericLabelFilter(t LabelFilterType, name string, v float64) *NumericLabelFilter

NewNumericLabelFilter creates a new label filterer which parses float64 string representation (5.2) from the value of the named label and compares it with the given f value.

func (*NumericLabelFilter) Process

func (n *NumericLabelFilter) Process(line []byte, lbs *LabelsBuilder) ([]byte, bool)

func (*NumericLabelFilter) String

func (n *NumericLabelFilter) String() string

type Pipeline

type Pipeline interface {
	Process(line []byte, lbs labels.Labels) ([]byte, labels.Labels, bool)
}

Pipeline transform and filter log lines and labels.

func NewPipeline

func NewPipeline(stages []Stage) Pipeline

type RegexpParser

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

func NewRegexpParser

func NewRegexpParser(re string) (*RegexpParser, error)

NewRegexpParser creates a new log stage that can extract labels from a log line using a regex expression. The regex expression must contains at least one named match. If the regex doesn't match the line is not filtered out.

func (*RegexpParser) Process

func (r *RegexpParser) Process(line []byte, lbs *LabelsBuilder) ([]byte, bool)

type SampleExtractor

type SampleExtractor interface {
	Process(line []byte, lbs labels.Labels) (float64, labels.Labels, bool)
}

SampleExtractor extracts sample for a log line.

func LabelExtractorWithStages

func LabelExtractorWithStages(
	labelName, conversion string,
	groups []string, without bool, noLabels bool,
	preStages []Stage,
	postFilter Stage,
) (SampleExtractor, error)

LabelExtractorWithStages creates a SampleExtractor that will extract metrics from a labels. A set of log stage is executed before the conversion. A Filtering stage is executed after the conversion allowing to remove sample containing the __error__ label.

func LineExtractorWithStages added in v1.7.0

func LineExtractorWithStages(ex LineExtractor, stages []Stage, groups []string, without bool, noLabels bool) (SampleExtractor, error)

LineExtractorWithStages creates a SampleExtractor from a LineExtractor. Multiple log stages are run before converting the log line.

type SampleExtractorFunc added in v1.7.0

type SampleExtractorFunc func(line []byte, lbs labels.Labels) (float64, labels.Labels, bool)

func (SampleExtractorFunc) Process added in v1.7.0

func (fn SampleExtractorFunc) Process(line []byte, lbs labels.Labels) (float64, labels.Labels, bool)

type Stage

type Stage interface {
	Process(line []byte, lbs *LabelsBuilder) ([]byte, bool)
}

Stage is a single step of a Pipeline.

func ReduceStages

func ReduceStages(stages []Stage) Stage

ReduceStages reduces multiple stages into one.

type StageFunc

type StageFunc func(line []byte, lbs *LabelsBuilder) ([]byte, bool)

func (StageFunc) Process

func (fn StageFunc) Process(line []byte, lbs *LabelsBuilder) ([]byte, bool)

type StringLabelFilter

type StringLabelFilter struct {
	*labels.Matcher
}

func NewStringLabelFilter

func NewStringLabelFilter(m *labels.Matcher) *StringLabelFilter

NewStringLabelFilter creates a new label filterer which compares string label. This is the only LabelFilterer that can filter out the __error__ label. Unlike other LabelFilterer which apply conversion, if the label name doesn't exist it is compared with an empty value.

func (*StringLabelFilter) Process

func (s *StringLabelFilter) Process(line []byte, lbs *LabelsBuilder) ([]byte, bool)

Directories

Path Synopsis
Adapted from https://github.com/go-logfmt/logfmt/ but []byte as parameter instead Original license is MIT.
Adapted from https://github.com/go-logfmt/logfmt/ but []byte as parameter instead Original license is MIT.

Jump to

Keyboard shortcuts

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