logql

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2020 License: Apache-2.0 Imports: 27 Imported by: 91

Documentation

Index

Constants

View Source
const (
	OpTypeSum           = "sum"
	OpTypeAvg           = "avg"
	OpTypeMax           = "max"
	OpTypeMin           = "min"
	OpTypeCount         = "count"
	OpTypeStddev        = "stddev"
	OpTypeStdvar        = "stdvar"
	OpTypeBottomK       = "bottomk"
	OpTypeTopK          = "topk"
	OpTypeCountOverTime = "count_over_time"
	OpTypeRate          = "rate"

	// binops - logical/set
	OpTypeOr     = "or"
	OpTypeAnd    = "and"
	OpTypeUnless = "unless"

	// binops - operations
	OpTypeAdd = "+"
	OpTypeSub = "-"
	OpTypeMul = "*"
	OpTypeDiv = "/"
	OpTypeMod = "%"
	OpTypePow = "^"
)
View Source
const (
	QueryTypeMetric  = "metric"
	QueryTypeFilter  = "filter"
	QueryTypeLimited = "limited"
)
View Source
const ADD = 57382
View Source
const AND = 57380
View Source
const AVG = 57371
View Source
const BOTTOMK = 57377
View Source
const BY = 57366
View Source
const CLOSE_BRACE = 57357
View Source
const CLOSE_BRACKET = 57359
View Source
const CLOSE_PARENTHESIS = 57365
View Source
const COMMA = 57360
View Source
const COUNT = 57374
View Source
const COUNT_OVER_TIME = 57368
View Source
const DIV = 57385
View Source
const DOT = 57361
View Source
const DURATION = 57349
View Source
const EQ = 57352
View Source
const IDENTIFIER = 57346
View Source
const LABELS = 57351
View Source
const MATCHERS = 57350
View Source
const MAX = 57372
View Source
const MIN = 57373
View Source
const MOD = 57386
View Source
const MUL = 57384
View Source
const NEQ = 57353
View Source
const NRE = 57355
View Source
const NUMBER = 57348
View Source
const OPEN_BRACE = 57356
View Source
const OPEN_BRACKET = 57358
View Source
const OPEN_PARENTHESIS = 57364
View Source
const OR = 57379
View Source
const PIPE_EXACT = 57363
View Source
const PIPE_MATCH = 57362
View Source
const POW = 57387
View Source
const RATE = 57369
View Source
const RE = 57354
View Source
const STDDEV = 57375
View Source
const STDVAR = 57376
View Source
const STRING = 57347
View Source
const SUB = 57383
View Source
const SUM = 57370
View Source
const TOPK = 57378
View Source
const UNLESS = 57381
View Source
const ValueTypeStreams = "streams"

ValueTypeStreams promql.ValueType for log streams

View Source
const WITHOUT = 57367

Variables

This section is empty.

Functions

func IsLogicalBinOp added in v1.4.0

func IsLogicalBinOp(op string) bool

IsLogicalBinOp tests whether an operation is a logical/set binary operation

func IsParseError added in v1.4.0

func IsParseError(err error) bool

IsParseError returns true if the err is a ast parsing error.

func ParseMatchers

func ParseMatchers(input string) ([]*labels.Matcher, error)

ParseMatchers parses a string and returns labels matchers, if the expression contains anything else it will return an error.

func PopulateMatrixFromScalar added in v1.4.0

func PopulateMatrixFromScalar(data promql.Scalar, params LiteralParams) promql.Matrix

func QueryType added in v1.4.0

func QueryType(query string) (string, error)

func RecordMetrics added in v1.4.0

func RecordMetrics(ctx context.Context, p Params, status string, stats stats.Result)

Types

type Engine added in v0.4.0

type Engine interface {
	NewRangeQuery(qs string, start, end time.Time, step time.Duration, direction logproto.Direction, limit uint32) Query
	NewInstantQuery(qs string, ts time.Time, direction logproto.Direction, limit uint32) Query
}

Engine interface used to construct queries

func NewEngine added in v0.4.0

func NewEngine(opts EngineOpts, q Querier) Engine

NewEngine creates a new LogQL engine.

type EngineOpts added in v0.4.0

type EngineOpts struct {
	// Timeout for queries execution
	Timeout time.Duration `yaml:"timeout"`
	// MaxLookBackPeriod is the maximum amount of time to look back for log lines.
	// only used for instant log queries.
	MaxLookBackPeriod time.Duration `yaml:"max_look_back_period"`
}

EngineOpts is the list of options to use with the LogQL query engine.

type Evaluator added in v1.4.0

type Evaluator interface {
	// Evaluator returns a StepEvaluator for a given SampleExpr
	Evaluator(context.Context, SampleExpr, Params) (StepEvaluator, error)
	// Iterator returns the iter.EntryIterator for a given LogSelectorExpr
	Iterator(context.Context, LogSelectorExpr, Params) (iter.EntryIterator, error)
}

Evaluator is an interface for iterating over data at different nodes in the AST

type Expr

type Expr interface {
	fmt.Stringer
	// contains filtered or unexported methods
}

Expr is the root expression which can be a SampleExpr or LogSelectorExpr

func ParseExpr

func ParseExpr(input string) (expr Expr, err error)

ParseExpr parses a string and returns an Expr.

type LineFilter added in v1.4.0

type LineFilter interface {
	Filter(line []byte) bool
}

LineFilter is a interface to filter log lines.

type LineFilterFunc added in v1.4.0

type LineFilterFunc func(line []byte) bool

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

func (LineFilterFunc) Filter added in v1.4.0

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

type LiteralParams added in v1.4.0

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

LiteralParams impls Params

func (LiteralParams) Direction added in v1.4.0

func (p LiteralParams) Direction() logproto.Direction

Direction impls Params

func (LiteralParams) End added in v1.4.0

func (p LiteralParams) End() time.Time

End impls Params

func (LiteralParams) Limit added in v1.4.0

func (p LiteralParams) Limit() uint32

Limit impls Params

func (LiteralParams) Query added in v1.4.0

func (p LiteralParams) Query() string

String impls Params

func (LiteralParams) Start added in v1.4.0

func (p LiteralParams) Start() time.Time

Start impls Params

func (LiteralParams) Step added in v1.4.0

func (p LiteralParams) Step() time.Duration

Step impls Params

type LogSelectorExpr added in v0.4.0

type LogSelectorExpr interface {
	Filter() (LineFilter, error)
	Matchers() []*labels.Matcher
	Expr
}

LogSelectorExpr is a LogQL expression filtering and returning logs.

func NewFilterExpr

func NewFilterExpr(left LogSelectorExpr, ty labels.MatchType, match string) LogSelectorExpr

NewFilterExpr wraps an existing Expr with a next filter expression.

func ParseLogSelector added in v0.4.0

func ParseLogSelector(input string) (LogSelectorExpr, error)

ParseLogSelector parses a log selector expression `{app="foo"} |= "filter"`

type Params added in v1.4.0

type Params interface {
	Query() string
	Start() time.Time
	End() time.Time
	Step() time.Duration
	Limit() uint32
	Direction() logproto.Direction
}

Params details the parameters associated with a loki request

type ParseError

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

ParseError is what is returned when we failed to parse.

func (ParseError) Error

func (p ParseError) Error() string

type Querier

type Querier interface {
	Select(context.Context, SelectParams) (iter.EntryIterator, error)
}

Querier allows a LogQL expression to fetch an EntryIterator for a set of matchers and filters

type QuerierFunc

type QuerierFunc func(context.Context, SelectParams) (iter.EntryIterator, error)

QuerierFunc implements Querier.

func (QuerierFunc) Select added in v0.4.0

Select implements Querier.

type Query added in v0.4.0

type Query interface {
	// Exec processes the query.
	Exec(ctx context.Context) (Result, error)
}

Query is a LogQL query to be executed.

type QueryRangeType added in v1.4.0

type QueryRangeType string
var (
	InstantType QueryRangeType = "instant"
	RangeType   QueryRangeType = "range"
)

func GetRangeType added in v1.4.0

func GetRangeType(q Params) QueryRangeType

GetRangeType returns whether a query is an instant query or range query

type RangeVectorAggregator added in v0.4.0

type RangeVectorAggregator func(int64, []promql.Point) float64

RangeVectorAggregator aggregates samples for a given range of samples. It receives the current milliseconds timestamp and the list of point within the range.

type RangeVectorIterator added in v0.4.0

type RangeVectorIterator interface {
	Next() bool
	At(aggregator RangeVectorAggregator) (int64, promql.Vector)
	Close() error
}

RangeVectorIterator iterates through a range of samples. To fetch the current vector use `At` with a `RangeVectorAggregator`.

type Result added in v1.4.0

type Result struct {
	Data       promql.Value
	Statistics stats.Result
}

Result is the result of a query execution.

type SampleExpr added in v0.4.0

type SampleExpr interface {
	// Selector is the LogQL selector to apply when retrieving logs.
	Selector() LogSelectorExpr
	Expr
}

SampleExpr is a LogQL expression filtering logs and returning metric samples.

type SelectParams added in v0.4.0

type SelectParams struct {
	*logproto.QueryRequest
}

SelectParams specifies parameters passed to data selections.

func (SelectParams) LogSelector added in v0.4.0

func (s SelectParams) LogSelector() (LogSelectorExpr, error)

LogSelector returns the LogSelectorExpr from the SelectParams. The `LogSelectorExpr` can then returns all matchers and filters to use for that request.

type StepEvaluator added in v0.4.0

type StepEvaluator interface {
	// while Next returns a promql.Value, the only acceptable types are Scalar and Vector.
	Next() (bool, int64, promql.Vector)
	// Close all resources used.
	Close() error
}

StepEvaluator evaluate a single step of a query.

type Streams added in v0.4.0

type Streams []*logproto.Stream

Streams is promql.Value

func (Streams) String added in v0.4.0

func (Streams) String() string

String implements `promql.Value`

func (Streams) Type added in v0.4.0

func (Streams) Type() promql.ValueType

Type implements `promql.Value`

Directories

Path Synopsis
log
logfmt Module
Package marshal converts internal objects to loghttp model objects.
Package marshal converts internal objects to loghttp model objects.
legacy
Package marshal converts internal objects to loghttp model objects.
Package marshal converts internal objects to loghttp model objects.
Package stats provides primitives for recording metrics across the query path.
Package stats provides primitives for recording metrics across the query path.
syntax module

Jump to

Keyboard shortcuts

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