query

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetFunctionSuggestions

func GetFunctionSuggestions() []string

GetFunctionSuggestions returns function suggestions for auto-completion

func GetQuerySuggestions

func GetQuerySuggestions(queryStr string, cursorPos int) []string

GetQuerySuggestions returns auto-completion suggestions for a query

func ValidateQuery

func ValidateQuery(queryStr string) error

ValidateQuery validates a Lawrence QL query string

Types

type Aggregation

type Aggregation struct {
	Function string
	Query    Query
	By       []string // group by labels
}

Aggregation represents an aggregation with grouping

func (*Aggregation) Accept

func (a *Aggregation) Accept(visitor QueryVisitor) (interface{}, error)

Accept implements Query interface

type BinaryOp

type BinaryOp struct {
	Left     Query
	Operator BinaryOperator
	Right    Query
}

BinaryOp represents a binary operation between two queries

func (*BinaryOp) Accept

func (b *BinaryOp) Accept(visitor QueryVisitor) (interface{}, error)

Accept implements Query interface

type BinaryOperator

type BinaryOperator string

BinaryOperator represents binary operators

const (
	BinaryOpAdd      BinaryOperator = "+"
	BinaryOpSubtract BinaryOperator = "-"
	BinaryOpMultiply BinaryOperator = "*"
	BinaryOpDivide   BinaryOperator = "/"
	BinaryOpEqual    BinaryOperator = "=="
	BinaryOpNotEqual BinaryOperator = "!="
	BinaryOpLT       BinaryOperator = "<"
	BinaryOpGT       BinaryOperator = ">"
	BinaryOpLTE      BinaryOperator = "<="
	BinaryOpGTE      BinaryOperator = ">="
	BinaryOpAnd      BinaryOperator = "and"
	BinaryOpOr       BinaryOperator = "or"
)

type ExecutionContext

type ExecutionContext struct {
	StartTime *time.Time
	EndTime   *time.Time
	Limit     int
	AgentID   *uuid.UUID
	GroupID   *string
}

ExecutionContext contains context for query execution

type Executor

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

Executor executes Lawrence QL queries

func NewExecutor

func NewExecutor(telemetryService services.TelemetryQueryService, logger *zap.Logger) *Executor

NewExecutor creates a new query executor

func (*Executor) Execute

func (e *Executor) Execute(ctx context.Context, query Query, execCtx *ExecutionContext) ([]QueryResult, *QueryMeta, error)

Execute executes a Lawrence QL query and returns results

type ExecutorVisitor

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

ExecutorVisitor implements QueryVisitor to execute queries

func (*ExecutorVisitor) VisitAggregation

func (v *ExecutorVisitor) VisitAggregation(a *Aggregation) (interface{}, error)

VisitAggregation executes an aggregation query

func (*ExecutorVisitor) VisitBinaryOp

func (v *ExecutorVisitor) VisitBinaryOp(b *BinaryOp) (interface{}, error)

VisitBinaryOp executes a binary operation

func (*ExecutorVisitor) VisitFunctionCall

func (v *ExecutorVisitor) VisitFunctionCall(f *FunctionCall) (interface{}, error)

VisitFunctionCall executes a function call

func (*ExecutorVisitor) VisitTelemetryQuery

func (v *ExecutorVisitor) VisitTelemetryQuery(q *TelemetryQuery) (interface{}, error)

VisitTelemetryQuery executes a telemetry query

type Function

type Function struct {
	Name        string
	Description string
	Apply       func([]QueryResult) (interface{}, error)
}

Function represents a built-in query function

func GetFunction

func GetFunction(name string) (*Function, bool)

GetFunction returns a function by name

func ListFunctions

func ListFunctions() []*Function

ListFunctions returns all available functions

type FunctionCall

type FunctionCall struct {
	Name string
	Args []Query
}

FunctionCall represents a function call on a query

func (*FunctionCall) Accept

func (f *FunctionCall) Accept(visitor QueryVisitor) (interface{}, error)

Accept implements Query interface

type Parser

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

Parser parses Lawrence QL queries into AST

func NewParser

func NewParser(input string) *Parser

NewParser creates a new parser for the given input

func (*Parser) Parse

func (p *Parser) Parse() (Query, error)

Parse parses the input and returns the AST

type Query

type Query interface {
	Accept(visitor QueryVisitor) (interface{}, error)
}

Query represents any Lawrence QL query

type QueryMeta

type QueryMeta struct {
	ExecutionTime time.Duration `json:"execution_time"`
	RowCount      int           `json:"row_count"`
	QueryType     string        `json:"query_type"`
	UsedRollups   bool          `json:"used_rollups"`
}

QueryMeta contains metadata about query execution

type QueryResult

type QueryResult struct {
	Type      TelemetryType          `json:"type"`
	Timestamp time.Time              `json:"timestamp"`
	Labels    map[string]string      `json:"labels"`
	Value     interface{}            `json:"value"`
	Data      map[string]interface{} `json:"data,omitempty"`
}

QueryResult represents the result of a Lawrence QL query

type QueryVisitor

type QueryVisitor interface {
	VisitTelemetryQuery(*TelemetryQuery) (interface{}, error)
	VisitBinaryOp(*BinaryOp) (interface{}, error)
	VisitFunctionCall(*FunctionCall) (interface{}, error)
	VisitAggregation(*Aggregation) (interface{}, error)
}

QueryVisitor defines the visitor pattern for query AST traversal

type Selector

type Selector struct {
	Label    string
	Operator SelectorOperator
	Value    string
}

Selector represents a label selector with operator

func (*Selector) Validate

func (s *Selector) Validate() error

ValidateSelector validates a selector value based on operator

type SelectorOperator

type SelectorOperator string

SelectorOperator represents the type of selector operation

const (
	SelectorOpEqual    SelectorOperator = "="
	SelectorOpNotEqual SelectorOperator = "!="
	SelectorOpRegex    SelectorOperator = "=~"
	SelectorOpNotRegex SelectorOperator = "!~"
)

type TelemetryQuery

type TelemetryQuery struct {
	Type      TelemetryType
	Selectors map[string]*Selector
	Duration  time.Duration
	StartTime *time.Time
	EndTime   *time.Time
	Limit     int
}

TelemetryQuery represents a basic telemetry query

func (*TelemetryQuery) Accept

func (q *TelemetryQuery) Accept(visitor QueryVisitor) (interface{}, error)

Accept implements Query interface

type TelemetryType

type TelemetryType string

TelemetryType represents the type of telemetry data

const (
	TelemetryTypeMetrics TelemetryType = "metrics"
	TelemetryTypeLogs    TelemetryType = "logs"
	TelemetryTypeTraces  TelemetryType = "traces"
)

type Token

type Token struct {
	Type  TokenType
	Value string
	Pos   int
}

Token represents a lexical token

type TokenType

type TokenType int

TokenType represents the type of token

const (
	TokenEOF TokenType = iota
	TokenIdentifier
	TokenString
	TokenNumber
	TokenLBrace   // {
	TokenRBrace   // }
	TokenLBracket // [
	TokenRBracket // ]
	TokenLParen   // (
	TokenRParen   // )
	TokenComma    // ,
	TokenEqual    // =
	TokenNotEqual // !=
	TokenRegex    // =~
	TokenNotRegex // !~
	TokenPlus     // +
	TokenMinus    // -
	TokenMultiply // *
	TokenDivide   // /
	TokenLT       // <
	TokenGT       // >
	TokenLTE      // <=
	TokenGTE      // >=
	TokenAnd      // and
	TokenOr       // or
	TokenBy       // by
	TokenPipe     // |
)

Jump to

Keyboard shortcuts

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