logql

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package logql contains LogQL parser and AST definitions.

Index

Constants

View Source
const (
	// ErrorLabel is a specific label for LogQL errors.
	ErrorLabel = "__error__"
	// ErrorDetailsLabel is a specific label for LogQL error details.
	ErrorDetailsLabel = "__error_details__"
)

Variables

This section is empty.

Functions

func IsValidLabel

func IsValidLabel(s string, allowDot bool) error

IsValidLabel validates label name.

Types

type BinOp

type BinOp int

BinOp defines binary operation.

const (
	// Logical ops.
	OpAnd BinOp = iota + 1
	OpOr
	OpUnless
	// Math ops.
	OpAdd
	OpSub
	OpMul
	OpDiv
	OpMod
	OpPow
	// Comparison ops.
	OpEq
	OpNotEq
	OpRe
	OpNotRe
	OpGt
	OpGte
	OpLt
	OpLte
)

func (BinOp) IsLogic

func (op BinOp) IsLogic() bool

IsLogic returns whether operation is logical.

func (BinOp) String

func (op BinOp) String() string

String implements fmt.Stringer.

type BinOpExpr

type BinOpExpr struct {
	Left     Expr
	Op       BinOp
	Modifier BinOpModifier
	Right    Expr
}

BinOpExpr defines a binary operation between two Expr.

type BinOpModifier

type BinOpModifier struct {
	Op         string // on, ignoring
	OpLabels   []Label
	Group      string // "", "left", "right"
	Include    []Label
	ReturnBool bool
}

BinOpModifier defines BinOpExpr modifier.

FIXME(tdakkota): this feature is not well documented.

type BytesFilter

type BytesFilter struct {
	Label Label
	Op    BinOp // OpEq, OpNotEq, OpLt, OpLte, OpGt, OpGte
	Value uint64
}

BytesFilter is a byte size filtering predicate (`size > 10gb`).

type DecolorizeExpr

type DecolorizeExpr struct{}

DecolorizeExpr decolorizes log line.

type DistinctFilter

type DistinctFilter struct {
	Labels []Label
}

DistinctFilter filters out lines with duplicate label values.

FIXME(tdakkota): this stage is undocumented.

type DropLabelsExpr

type DropLabelsExpr struct {
	Labels   []Label
	Matchers []LabelMatcher
}

DropLabelsExpr drops given labels in a pipeline (i.e. deny list).

type DurationFilter

type DurationFilter struct {
	Label Label
	Op    BinOp // OpEq, OpNotEq, OpLt, OpLte, OpGt, OpGte
	Value time.Duration
}

DurationFilter is a duration filtering predicate (`elapsed > 10s`).

type Expr

type Expr interface {
	// contains filtered or unexported methods
}

Expr is a root LogQL expression.

func Parse

func Parse(s string, opts ParseOptions) (Expr, error)

Parse parses LogQL query from string.

func UnparenExpr

func UnparenExpr(e Expr) Expr

UnparenExpr recursively extracts expression from parentheses.

type Grouping

type Grouping struct {
	Labels  []Label
	Without bool
}

Grouping is a grouping clause.

type IPFilter

type IPFilter struct {
	Label Label
	Op    BinOp // OpEq, OpNotEq
	Value string
}

IPFilter is a IP filtering predicate (`addr == ip("127.0.0.1")`).

type JSONExpressionParser

type JSONExpressionParser struct {
	// Labels is a set of labels to extract.
	Labels []Label
	// Exprs is a set of extraction expressions.
	Exprs []LabelExtractionExpr
}

JSONExpressionParser extracts and filters labels from JSON.

type KeepLabelsExpr

type KeepLabelsExpr struct {
	Labels   []Label
	Matchers []LabelMatcher
}

KeepLabelsExpr drops any label except given in a pipeline (i.e. allow list).

type Label

type Label string

Label is a LogQL identifier.

type LabelExtractionExpr

type LabelExtractionExpr struct {
	Label Label
	Expr  string
}

LabelExtractionExpr defines label value to extract.

type LabelFilter

type LabelFilter struct {
	Pred LabelPredicate
}

LabelFilter filters records by predicate.

type LabelFormatExpr

type LabelFormatExpr struct {
	// FIXME(tdakkota): use map[K][]V?
	Labels []RenameLabel
	Values []LabelTemplate
}

LabelFormatExpr renames, modifies or add labels.

type LabelMatcher

type LabelMatcher struct {
	Label Label
	Op    BinOp          // OpEq, OpNotEq, OpRe, OpNotRe
	Value string         // Equals to value or to unparsed regexp
	Re    *regexp.Regexp // Equals to nil, if Op is not OpRe or OpNotRe
}

LabelMatcher is label matching predicate.

type LabelPredicate

type LabelPredicate interface {
	// contains filtered or unexported methods
}

LabelPredicate is a label predicate.

type LabelPredicateBinOp

type LabelPredicateBinOp struct {
	Left  LabelPredicate
	Op    BinOp // OpAnd, OpOr
	Right LabelPredicate
}

LabelPredicateBinOp defines a logical operation between predicates.

type LabelPredicateParen

type LabelPredicateParen struct {
	X LabelPredicate
}

LabelPredicateParen is a prediacte within parenthesis.

FIXME(tdakkota): are we really need it?

type LabelReplaceExpr

type LabelReplaceExpr struct {
	Expr        MetricExpr
	DstLabel    string
	Replacement string
	SrcLabel    string
	Regex       string
	Re          *regexp.Regexp // Compiled Regex
}

LabelReplaceExpr is a PromQL `label_replace` function.

type LabelTemplate

type LabelTemplate struct {
	Label    Label
	Template string
}

LabelTemplate sets value for a label.

type LineFilter

type LineFilter struct {
	Op    BinOp          // OpEq, OpNotEq, OpRe, OpNotRe
	Value string         // Equals to value or to unparsed regexp
	Re    *regexp.Regexp // Equals to nil, if Op is not OpRe or OpNotRe
	IP    bool           // true, if this line filter is IP filter.
}

LineFilter is a line filter (`|=`, `!=`, `=~`, `!~`).

type LineFormat

type LineFormat struct {
	Template string
}

LineFormat formats log record using Go template.

type LiteralExpr

type LiteralExpr struct {
	Value float64
}

LiteralExpr is a literal expression.

func ReduceBinOp

func ReduceBinOp(b *BinOpExpr) (_ *LiteralExpr, err error)

ReduceBinOp recursively precomputes literal expression.

If expression is not constant, returns nil.

type LogExpr

type LogExpr struct {
	Sel      Selector
	Pipeline []PipelineStage
}

LogExpr is a log query expression.

See https://grafana.com/docs/loki/latest/logql/log_queries/

type LogRangeExpr

type LogRangeExpr struct {
	Sel      Selector
	Range    time.Duration
	Pipeline []PipelineStage
	Unwrap   *UnwrapExpr
	Offset   *OffsetExpr
}

LogRangeExpr is a log range aggregation expression.

See https://grafana.com/docs/loki/latest/logql/metric_queries/#log-range-aggregations.

type LogfmtExpressionParser

type LogfmtExpressionParser struct {
	// Labels is a set of labels to extract.
	Labels []Label
	// Exprs is a set of extraction expressions.
	Exprs []LabelExtractionExpr
}

LogfmtExpressionParser extracts and filters labels from Logfmt.

type MetricExpr

type MetricExpr interface {
	Expr
	// contains filtered or unexported methods
}

MetricExpr is a metric query expression.

See https://grafana.com/docs/loki/latest/logql/metric_queries/.

type NumberFilter

type NumberFilter struct {
	Label Label
	Op    BinOp // OpEq, OpNotEq, OpLt, OpLte, OpGt, OpGte
	// FIXME(tdakkota): add integer field?
	Value float64
}

NumberFilter is a number filtering predicate (`status >= 400`).

type OffsetExpr

type OffsetExpr struct {
	Duration time.Duration
}

OffsetExpr defines aggregation time offset.

type ParenExpr

type ParenExpr struct {
	X Expr
}

ParenExpr is parenthesized Expr.

type ParseOptions

type ParseOptions struct {
	// AllowDots allows dots in identifiers.
	AllowDots bool
}

ParseOptions is LogQL parser options.

type PatternLabelParser

type PatternLabelParser struct {
	Pattern string
}

PatternLabelParser extracts labels using log pattern.

See https://grafana.com/docs/loki/latest/logql/log_queries/#pattern.

type PipelineStage

type PipelineStage interface {
	// contains filtered or unexported methods
}

PipelineStage is a LogQL pipeline stage.

type RangeAggregationExpr

type RangeAggregationExpr struct {
	Op        RangeOp
	Range     LogRangeExpr
	Parameter *float64
	Grouping  *Grouping
}

RangeAggregationExpr is a range aggregation expression.

type RangeOp

type RangeOp int

RangeOp defines range aggregation operation.

const (
	RangeOpCount RangeOp = iota + 1
	RangeOpRate
	RangeOpRateCounter
	RangeOpBytes
	RangeOpBytesRate
	RangeOpAvg
	RangeOpSum
	RangeOpMin
	RangeOpMax
	RangeOpStdvar
	RangeOpStddev
	RangeOpQuantile
	RangeOpFirst
	RangeOpLast
	RangeOpAbsent
)

func (RangeOp) String

func (op RangeOp) String() string

String implements fmt.Stringer.

type RegexpLabelParser

type RegexpLabelParser struct {
	Regexp  *regexp.Regexp
	Mapping map[int]Label
}

RegexpLabelParser extracts labels using regexp capture groups.

type RenameLabel

type RenameLabel struct {
	Label Label
	To    Label
}

RenameLabel renames label.

type Selector

type Selector struct {
	Matchers []LabelMatcher
}

Selector is a labels selector.

func ParseSelector

func ParseSelector(s string, opts ParseOptions) (sel Selector, _ error)

ParseSelector parses label selector from string.

type UnpackLabelParser

type UnpackLabelParser struct{}

UnpackLabelParser unpacks data from promtail.

See https://grafana.com/docs/loki/latest/logql/log_queries/#unpack.

type UnwrapExpr

type UnwrapExpr struct {
	Op      string
	Label   Label
	Filters []LabelMatcher
}

UnwrapExpr sets labels to perform aggregation.

See https://grafana.com/docs/loki/latest/logql/metric_queries/#unwrapped-range-aggregations.

type VectorAggregationExpr

type VectorAggregationExpr struct {
	Op        VectorOp
	Expr      MetricExpr
	Parameter *int
	Grouping  *Grouping
}

VectorAggregationExpr is a vector aggregation expression.

type VectorExpr

type VectorExpr struct {
	Value float64
}

VectorExpr is a vector expression.

type VectorOp

type VectorOp int

VectorOp defines vector aggregation operation.

const (
	VectorOpSum VectorOp = iota + 1
	VectorOpAvg
	VectorOpCount
	VectorOpMax
	VectorOpMin
	VectorOpStddev
	VectorOpStdvar
	VectorOpBottomk
	VectorOpTopk
	VectorOpSort
	VectorOpSortDesc
)

func (VectorOp) String

func (op VectorOp) String() string

String implements fmt.Stringer.

Directories

Path Synopsis
Package lexer contains LogQL lexer.
Package lexer contains LogQL lexer.
Package logqlengine implements LogQL evaluation engine.
Package logqlengine implements LogQL evaluation engine.

Jump to

Keyboard shortcuts

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