traceqlengine

package
v0.11.0 Latest Latest
Warning

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

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

Documentation

Overview

Package traceqlengine implements TraceQL evaluation engine.

Index

Constants

This section is empty.

Variables

View Source
var NopProcessor = &nopProcessor{}

NopProcessor is a processor that does nothing.

Functions

func ReduceExpr

func ReduceExpr(expr traceql.TypedExpr) traceql.TypedExpr

ReduceExpr evaluates constant expressions and simplifies expression.

Types

type AggregateEvalauter

type AggregateEvalauter[A Aggregator] struct {
	Agg A
}

AggregateEvalauter evaluates aggregation expression.

func (*AggregateEvalauter[A]) Eval

Eval implemenets Evaluater.

type Aggregator

type Aggregator interface {
	Aggregate(set Spanset) float64
}

Aggregator is an aggregation expression.

type AttributeEvaluater

type AttributeEvaluater struct {
	Name string
}

AttributeEvaluater evaluates attribute selector.

func (*AttributeEvaluater) Eval

Eval implemenets Evaluater.

type AvgAgg

type AvgAgg struct {
	Sum SumAgg
}

AvgAgg is `avg(...)` aggregator.

func (AvgAgg) Aggregate

func (agg AvgAgg) Aggregate(set Spanset) float64

Aggregate implements Aggregator.

type BinaryEvaluater

type BinaryEvaluater struct {
	Left  Evaluater
	Op    BinaryOp
	Right Evaluater
}

BinaryEvaluater is a binary operation Evaluater.

func (*BinaryEvaluater) Eval

Eval implemenets Evaluater.

type BinaryExpr

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

BinaryExpr merges two pipelines.

func (*BinaryExpr) Process

func (f *BinaryExpr) Process(sets []Spanset) ([]Spanset, error)

Process implements Processor.

type BinaryOp

type BinaryOp func(a, b traceql.Static) traceql.Static

BinaryOp is a binary operation.

type BinarySpansetExpr

type BinarySpansetExpr struct {
	Left  Processor
	Op    SpansetOp
	Right Processor
}

BinarySpansetExpr merges two spansets.

func (*BinarySpansetExpr) Process

func (f *BinarySpansetExpr) Process(sets []Spanset) (output []Spanset, _ error)

Process implements Processor.

type CountAgg

type CountAgg struct{}

CountAgg is a `count()` aggregator.

func (CountAgg) Aggregate

func (CountAgg) Aggregate(set Spanset) float64

Aggregate implements Aggregator.

type Engine

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

Engine is a TraceQL evaluation engine.

func NewEngine

func NewEngine(querier Querier, opts Options) *Engine

NewEngine creates new Engine.

func (*Engine) Eval

func (e *Engine) Eval(ctx context.Context, query string, params EvalParams) (traces *tempoapi.Traces, rerr error)

Eval parses and evaluates query.

type EvalParams

type EvalParams struct {
	// Trace duration to search, optional.
	MinDuration time.Duration
	MaxDuration time.Duration
	// Time range to search, optional.
	Start otelstorage.Timestamp
	End   otelstorage.Timestamp
	Limit int
}

EvalParams sets evaluation parameters.

type EvaluateCtx

type EvaluateCtx struct {
	Set Spanset
}

EvaluateCtx is evaluation context.

type Evaluater

type Evaluater interface {
	Eval(span tracestorage.Span, ctx EvaluateCtx) traceql.Static
}

Evaluater evaluates TraceQL expression.

type MaxAgg

type MaxAgg struct {
	By Evaluater
}

MaxAgg is `max(...)` aggregator.

func (MaxAgg) Aggregate

func (agg MaxAgg) Aggregate(set Spanset) (r float64)

Aggregate implements Aggregator.

type MemoryQuerier

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

MemoryQuerier is a simple in-memory querier, used for tests.

func (*MemoryQuerier) Add

func (q *MemoryQuerier) Add(span tracestorage.Span)

Add adds span to data set.

NOTE: There is no synchronization. Do not call this function concurrently with other methods.

func (*MemoryQuerier) SelectSpansets

SelectSpansets get spansets from storage.

type MinAgg

type MinAgg struct {
	By Evaluater
}

MinAgg is `min(...)` aggregator.

func (MinAgg) Aggregate

func (agg MinAgg) Aggregate(set Spanset) (r float64)

Aggregate implements Aggregator.

type NegEvaluater

type NegEvaluater struct {
	Sub Evaluater
}

NegEvaluater is a unary negation operation Evaluater.

func (*NegEvaluater) Eval

func (e *NegEvaluater) Eval(span tracestorage.Span, ctx EvaluateCtx) (r traceql.Static)

Eval implemenets Evaluater.

type NotEvaluater

type NotEvaluater struct {
	Sub Evaluater
}

NotEvaluater is a unary NOT operation Evaluater.

func (*NotEvaluater) Eval

func (e *NotEvaluater) Eval(span tracestorage.Span, ctx EvaluateCtx) (r traceql.Static)

Eval implemenets Evaluater.

type Options

type Options struct {
	// TracerProvider provides OpenTelemetry tracer for this engine.
	TracerProvider trace.TracerProvider
}

Options sets Engine options.

type ParentEvaluater

type ParentEvaluater struct{}

ParentEvaluater evaluates `parent` property.

func (*ParentEvaluater) Eval

Eval implemenets Evaluater.

type Pipeline

type Pipeline struct {
	Stages []Processor
}

Pipeline is a multi-stage processor.

func (*Pipeline) Process

func (p *Pipeline) Process(sets []Spanset) (_ []Spanset, err error)

Process implements Processor.

type Processor

type Processor interface {
	Process(sets []Spanset) ([]Spanset, error)
}

Processor is a log record processor.

func BuildBinaryExpr

func BuildBinaryExpr(expr *traceql.BinaryExpr) (Processor, error)

BuildBinaryExpr builds a new binary expression processor.

func BuildExpr

func BuildExpr(expr traceql.Expr) (Processor, error)

BuildExpr builds given TraceQL expression.

func BuildPipeline

func BuildPipeline(stages ...traceql.PipelineStage) (Processor, error)

BuildPipeline builds a new Pipeline.

type Querier

type Querier interface {
	// SelectSpansets get spansets from storage.
	SelectSpansets(ctx context.Context, params SelectSpansetsParams) (iterators.Iterator[Trace], error)
}

Querier does queries to storage.

type ResourceAttributeEvaluater

type ResourceAttributeEvaluater struct {
	Name string
}

ResourceAttributeEvaluater evaluates resource attribute selector.

func (*ResourceAttributeEvaluater) Eval

Eval implemenets Evaluater.

type RootServiceNameEvaluater

type RootServiceNameEvaluater struct{}

RootServiceNameEvaluater evaluates `rootServiceName` property.

func (*RootServiceNameEvaluater) Eval

Eval implemenets Evaluater.

type RootSpanNameEvaluater

type RootSpanNameEvaluater struct{}

RootSpanNameEvaluater evaluates `rootName` property.

func (*RootSpanNameEvaluater) Eval

Eval implemenets Evaluater.

type ScalarFilter

type ScalarFilter struct {
	Eval Evaluater
}

ScalarFilter filters Scalars by field expression.

func (*ScalarFilter) Process

func (f *ScalarFilter) Process(sets []Spanset) (result []Spanset, _ error)

Process implements Processor.

type SelectSpansetsParams

type SelectSpansetsParams struct {
	Op       traceql.SpansetOp // OpAnd, OpOr
	Matchers []SpanMatcher

	// Time range to query, optional.
	Start, End otelstorage.Timestamp

	// Trace duration, querier should ignore field, if it is zero.
	// TODO(tdakkota): probably, we can put it as SpanMatcher with traceDuration attribute
	//	but it would not work properly with OpOr.
	MinDuration time.Duration
	MaxDuration time.Duration

	Limit int
}

SelectSpansetsParams is a storage query params.

type SpanAttributeEvaluater

type SpanAttributeEvaluater struct {
	Name string
}

SpanAttributeEvaluater evaluates Span attribute selector.

func (*SpanAttributeEvaluater) Eval

Eval implemenets Evaluater.

type SpanDurationEvalauter

type SpanDurationEvalauter struct{}

SpanDurationEvalauter evaluates `duration` property.

func (*SpanDurationEvalauter) Eval

Eval implemenets Evaluater.

type SpanKindEvaluater

type SpanKindEvaluater struct{}

SpanKindEvaluater evaluates `kind` property.

func (*SpanKindEvaluater) Eval

Eval implemenets Evaluater.

type SpanMatcher

type SpanMatcher struct {
	Attribute traceql.Attribute
	Op        traceql.BinaryOp // could be zero, look for spans with such attribute
	Static    traceql.Static
}

SpanMatcher defines span predicate to select.

type SpanNameEvaluater

type SpanNameEvaluater struct{}

SpanNameEvaluater evaluates `name` property.

func (*SpanNameEvaluater) Eval

Eval implemenets Evaluater.

type SpanStatusEvaluater

type SpanStatusEvaluater struct{}

SpanStatusEvaluater evaluates `status` property.

func (*SpanStatusEvaluater) Eval

Eval implemenets Evaluater.

type Spanset

type Spanset struct {
	TraceID otelstorage.TraceID
	Spans   []tracestorage.Span

	Start           time.Time
	RootSpanName    string
	RootServiceName string
	TraceDuration   time.Duration
}

Spanset is a set of spans.

type SpansetFilter

type SpansetFilter struct {
	Eval Evaluater
}

SpansetFilter filters spansets by field expression.

func (*SpansetFilter) Process

func (f *SpansetFilter) Process(sets []Spanset) (result []Spanset, _ error)

Process implements Processor.

type SpansetOp

type SpansetOp func(a, b []Spanset) ([]tracestorage.Span, error)

SpansetOp merges two spansets.

type StaticEvaluater

type StaticEvaluater struct {
	Val traceql.Static
}

StaticEvaluater is a Evaluater returning a static value.

func (*StaticEvaluater) Eval

Eval implemenets Evaluater.

type SumAgg

type SumAgg struct {
	By Evaluater
}

SumAgg is `sum(...)` aggregator.

func (SumAgg) Aggregate

func (agg SumAgg) Aggregate(set Spanset) (r float64)

Aggregate implements Aggregator.

type Trace

type Trace struct {
	TraceID otelstorage.TraceID
	Spans   []tracestorage.Span
}

Trace is set of span grouped by trace ID.

type TraceDurationEvaluater

type TraceDurationEvaluater struct{}

TraceDurationEvaluater evaluates `traceDuration“ property.

func (*TraceDurationEvaluater) Eval

Eval implemenets Evaluater.

type UnsupportedError

type UnsupportedError struct {
	Msg string
}

UnsupportedError is an error that reports unsupported expressions.

func (*UnsupportedError) Error

func (e *UnsupportedError) Error() string

Error implements error.

Jump to

Keyboard shortcuts

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