logql_parser

package
v4.1.2 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2025 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LogQLLexerDefinition = lexer.MustSimple(LogQLLexerRulesV2)
View Source
var LogQLLexerRulesV2 = []lexer.SimpleRule{
	{Name: "Ocb", Pattern: `\{`},
	{Name: "Ccb", Pattern: `\}`},

	{Name: "Ob", Pattern: `\(`},
	{Name: "Cb", Pattern: `\)`},

	{Name: "Osb", Pattern: `\[`},
	{Name: "Csb", Pattern: `\]`},

	{Name: "Ge", Pattern: `>=`},
	{Name: "Le", Pattern: `<=`},
	{Name: "Gt", Pattern: `>`},
	{Name: "Lt", Pattern: `<`},
	{Name: "Deq", Pattern: `==`},

	{Name: "Comma", Pattern: `,`},

	{Name: "Neq", Pattern: `!=`},
	{Name: "Re", Pattern: `=~`},
	{Name: "Nre", Pattern: `!~`},
	{Name: "Eq", Pattern: `=`},

	{Name: "PipeLineFilter", Pattern: `(\|=|\|~|\|>)`},
	{Name: "Pipe", Pattern: `\|`},
	{Name: "Dot", Pattern: `\.`},

	{Name: "Macros_function", Pattern: `_[a-zA-Z0-9_]+`},
	{Name: "Label_name", Pattern: `[a-zA-Z_][a-zA-Z0-9_]*`},
	{Name: "Quoted_string", Pattern: `"([^"\\]|\\.)*"`},
	{Name: "Ticked_string", Pattern: "`([^`\\\\]|\\\\.)*`"},

	{Name: "Integer", Pattern: "[0-9]+"},

	{Name: "space", Pattern: `\s+`},
}

Functions

func FindFirst

func FindFirst[T any](node any) *T

Types

type AggOperator

type AggOperator struct {
	Fn                string       `@("sum"|"min"|"max"|"avg"|"stddev"|"stdvar"|"count") `
	ByOrWithoutPrefix *ByOrWithout `@@?`
	LRAOrUnwrap       LRAOrUnwrap  `"(" @@ ")" `
	ByOrWithoutSuffix *ByOrWithout `@@?`
	Comparison        *Comparison  `@@?`
}

func (AggOperator) String

func (l AggOperator) String() string

type ByOrWithout

type ByOrWithout struct {
	Fn     string      `@("by"|"without") `
	Labels []LabelName `"(" @@ ("," @@)* ")" `
}

func (ByOrWithout) LabelNames

func (l ByOrWithout) LabelNames() []string

func (ByOrWithout) String

func (l ByOrWithout) String() string

type Comparison

type Comparison struct {
	Fn  string `@("=="|"!="|">"|">="|"<"|"<=") `
	Val string `@(Integer "."? Integer*)`
}

func (Comparison) String

func (l Comparison) String() string

type Drop

type Drop struct {
	Fn     string      `@("drop")`
	Params []DropParam `@@? ("," @@)*`
}

func (*Drop) String

func (d *Drop) String() string

type DropParam

type DropParam struct {
	Label LabelName     `@@`
	Val   *QuotedString `("=" @@)?`
}

func (*DropParam) String

func (d *DropParam) String() string
type Head struct {
	ComplexHead *LabelFilter       `"(" @@ ")"`
	SimpleHead  *SimpleLabelFilter `|@@`
}

func (*Head) String

func (h *Head) String() string

type LRAOrUnwrap

type LRAOrUnwrap struct {
	Fn string `` /* 216-byte string literal not displayed */

	ByOrWithoutPrefix *ByOrWithout `( @@)?`
	StrSel            StrSelector  `"(" @@ `
	Time              string       `"[" @Integer `
	TimeUnit          string       `@("ns"|"us"|"ms"|"s"|"m"|"h") "]" `
	Offset            *Offset      `("offset" @@)? ")" `
	ByOrWithoutSuffix *ByOrWithout `@@?`
	Comparison        *Comparison  `@@?`
}

func (LRAOrUnwrap) String

func (l LRAOrUnwrap) String() string

type LabelFilter

type LabelFilter struct {
	Head Head         `@@`
	Op   string       `(@("and"|"or"))?`
	Tail *LabelFilter `@@?`
}

func (*LabelFilter) String

func (l *LabelFilter) String() string

type LabelFormat

type LabelFormat struct {
	LabelFormatOps []LabelFormatOp `"label_format" @@ ("," @@ )*`
}

func (*LabelFormat) String

func (l *LabelFormat) String() string

type LabelFormatOp

type LabelFormatOp struct {
	Label    LabelName     `@@ "=" `
	LabelVal *LabelName    `(@@`
	ConstVal *QuotedString `|@@)`
}

func (*LabelFormatOp) String

func (l *LabelFormatOp) String() string

type LabelName

type LabelName struct {
	Name string `@(Macros_function|Label_name)`
}

func (LabelName) String

func (l LabelName) String() string

type LineFilter

type LineFilter struct {
	Fn  string       `@("|="|"!="|"|~"|"!~"|"|>")`
	Val QuotedString `@@`
}

func (*LineFilter) String

func (l *LineFilter) String() string

type LineFormat

type LineFormat struct {
	Val QuotedString `"line_format" @@ `
}

func (*LineFormat) String

func (f *LineFormat) String() string

type LogQLScript

type LogQLScript struct {
	StrSelector      *StrSelector      `@@`
	LRAOrUnwrap      *LRAOrUnwrap      `| @@`
	AggOperator      *AggOperator      `| @@`
	Macros           *MacrosOp         `| @@`
	TopK             *TopK             `| @@`
	QuantileOverTime *QuantileOverTime `| @@`
}

func Parse

func Parse(str string) (*LogQLScript, error)

func ParseSeries

func ParseSeries(str string) (*LogQLScript, error)

func (LogQLScript) String

func (l LogQLScript) String() string

type MacrosOp

type MacrosOp struct {
	Name   string         `@Macros_function`
	Params []QuotedString `"(" @@? ("," @@)* ")"`
}

func (MacrosOp) String

func (l MacrosOp) String() string

type Offset

type Offset struct {
	Time     string `@Integer `
	TimeUnit string `@("ns"|"us"|"ms"|"s"|"m"|"h")`
}

func (Offset) Duration

func (l Offset) Duration() (time.Duration, error)

func (Offset) String

func (l Offset) String() string

type Parser

type Parser struct {
	Fn           string        `@("json"|"logfmt"|"regexp")`
	ParserParams []ParserParam `@@? ("," @@)*`
}

func (*Parser) String

func (p *Parser) String() string

type ParserParam

type ParserParam struct {
	Label *LabelName   `(@@ "=" )?`
	Val   QuotedString `@@`
}

func (*ParserParam) String

func (p *ParserParam) String() string

type QuantileOverTime

type QuantileOverTime struct {
	Fn                string       `@"quantile_over_time" `
	ByOrWithoutPrefix *ByOrWithout `@@?`
	Param             string       `"(" @(Integer+ "."? Integer*) "," `
	StrSel            StrSelector  `@@`
	Time              string       `"[" @Integer `
	TimeUnit          string       `@("ns"|"us"|"ms"|"s"|"m"|"h") "]" ")" `
	ByOrWithoutSuffix *ByOrWithout `@@?`
	Comparison        *Comparison  `@@?`
}

func (QuantileOverTime) String

func (l QuantileOverTime) String() string

type QuotedString

type QuotedString struct {
	Str string `@(Quoted_string|Ticked_string) `
}

func (QuotedString) String

func (q QuotedString) String() string

func (*QuotedString) Unquote

func (q *QuotedString) Unquote() (string, error)

type SimpleLabelFilter

type SimpleLabelFilter struct {
	Label  LabelName     `@@`
	Fn     string        `@("="|"!="|"!~"|"=="|">="|">"|"<="|"<"|"=~")`
	StrVal *QuotedString `(@@`
	NumVal string        `| @(Integer "."? Integer*))`
}

func (*SimpleLabelFilter) String

func (s *SimpleLabelFilter) String() string

type StrSelCmd

type StrSelCmd struct {
	Label LabelName    `@@`
	Op    string       `@("="|"!="|"=~"|"!~")`
	Val   QuotedString `@@`
}

type StrSelector

type StrSelector struct {
	StrSelCmds []StrSelCmd           `"{" @@? ("," @@ )* "}" `
	Pipelines  []StrSelectorPipeline `@@*`
}

func (StrSelector) String

func (l StrSelector) String() string

type StrSelectorPipeline

type StrSelectorPipeline struct {
	LineFilter  *LineFilter  `@@ `
	LabelFilter *LabelFilter `| "|" @@ `
	Parser      *Parser      `| "|" @@ `
	LineFormat  *LineFormat  `| "|" @@ `
	LabelFormat *LabelFormat `| "|" @@ `
	Unwrap      *Unwrap      `| "|" @@ `
	Drop        *Drop        `| "|" @@ `
}

func (*StrSelectorPipeline) String

func (s *StrSelectorPipeline) String() string

type TopK

type TopK struct {
	Fn               string            `@("topk"|"bottomk")`
	Param            string            `"(" @(Integer+ "."? Integer*) "," `
	LRAOrUnwrap      *LRAOrUnwrap      `(@@`
	AggOperator      *AggOperator      `| @@`
	QuantileOverTime *QuantileOverTime `| @@)")"`
	Comparison       *Comparison       `@@?`
}

func (TopK) String

func (l TopK) String() string

type Unwrap

type Unwrap struct {
	Fn    string    `@("unwrap"|"unwrap_value")`
	Label LabelName ` @@?`
}

func (*Unwrap) String

func (u *Unwrap) String() string

Jump to

Keyboard shortcuts

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