Documentation ¶
Overview ¶
Package logql contains LogQL parser and AST definitions.
Index ¶
- Constants
- func IsValidLabel[S ~string | ~[]byte](s S, allowDot bool) error
- type BinOp
- type BinOpExpr
- type BinOpModifier
- type BytesFilter
- type DecolorizeExpr
- type DistinctFilter
- type DropLabelsExpr
- type DurationFilter
- type Expr
- type Grouping
- type IPFilter
- type JSONExpressionParser
- type KeepLabelsExpr
- type Label
- type LabelExtractionExpr
- type LabelFilter
- type LabelFormatExpr
- type LabelMatcher
- type LabelPredicate
- type LabelPredicateBinOp
- type LabelPredicateParen
- type LabelReplaceExpr
- type LabelTemplate
- type LineFilter
- type LineFilterValue
- type LineFormat
- type LiteralExpr
- type LogExpr
- type LogRangeExpr
- type LogfmtExpressionParser
- type LogfmtFlags
- type MetricExpr
- type NumberFilter
- type OffsetExpr
- type ParenExpr
- type ParseOptions
- type PatternLabelParser
- type PipelineStage
- type RangeAggregationExpr
- type RangeOp
- type RegexpLabelParser
- type RenameLabel
- type Selector
- type UnpackLabelParser
- type UnwrapExpr
- type VectorAggregationExpr
- type VectorExpr
- type VectorOp
Constants ¶
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 ¶
Types ¶
type BinOp ¶
type BinOp int
BinOp defines binary operation.
func (BinOp) IsRightAssoc ¶ added in v0.10.0
IsRightAssoc whether if operator is right-associative.
func (BinOp) Precedence ¶ added in v0.0.8
Precedence returns operator precedence.
type BinOpExpr ¶
type BinOpExpr struct { Left MetricExpr Op BinOp Modifier BinOpModifier Right MetricExpr }
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 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 ¶
UnparenExpr recursively extracts expression from parentheses.
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 LabelExtractionExpr ¶
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 ¶
LabelTemplate sets value for a label.
type LineFilter ¶
type LineFilter struct { Op BinOp // OpEq, OpNotEq, OpRe, OpNotRe, OpPattern, OpNotPattern By LineFilterValue Or []LineFilterValue }
LineFilter is a line filter (`|=`, `!=`, `=~`, `!~`).
type LineFilterValue ¶ added in v0.10.0
type LineFilterValue struct { 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. }
LineFilterValue is a line filter literal to search by.
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.
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 // Flags defines parser flags. Flags LogfmtFlags }
LogfmtExpressionParser extracts and filters labels from Logfmt.
type LogfmtFlags ¶ added in v0.10.0
type LogfmtFlags uint8
LogfmtFlags defines logfmt parser flags.
const ( // LogfmtFlagStrict whether if parser should stop parsing line // if it contains invalid logfmt pairs. LogfmtFlagStrict LogfmtFlags = 1 << iota // LogfmtFlagKeepEmpty whether if parser should add labels with empty values // to the label set. LogfmtFlagKeepEmpty )
func (LogfmtFlags) Has ¶ added in v0.10.0
func (f LogfmtFlags) Has(flag LogfmtFlags) bool
Has whether if flag is enabled.
func (*LogfmtFlags) Set ¶ added in v0.10.0
func (f *LogfmtFlags) Set(flag LogfmtFlags)
Set sets flag.
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 ¶
OffsetExpr defines aggregation time offset.
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 RegexpLabelParser ¶
RegexpLabelParser extracts labels using regexp capture groups.
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.
Source Files ¶
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. |
jsonexpr
Package jsonexpr provides JSON extractor expression parser.
|
Package jsonexpr provides JSON extractor expression parser. |
logqlabels
Package logqlabels contains LogQL label utilities.
|
Package logqlabels contains LogQL label utilities. |
logqlerrors
Package logqlerrors defines LogQL engine errors.
|
Package logqlerrors defines LogQL engine errors. |
logqlmetric
Package logqlmetric provides metric queries implementation.
|
Package logqlmetric provides metric queries implementation. |
logqlpattern
Package logqlpattern contains parser for LogQL `pattern` stage pattern.
|
Package logqlpattern contains parser for LogQL `pattern` stage pattern. |