Help us shape the future of Go! Take the 2026 Go Developer Survey

query

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package query parses LogQL strings and provides pipeline types that process log entries through Loki-compatible log and metric pipelines.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LogPipeline

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

LogPipeline processes log entries through a parsed LogQL log selector.

func LogQL

func LogQL(query string) (*LogPipeline, error)

LogQL parses a LogQL log selector query and returns a LogPipeline.

func (*LogPipeline) Matchers

func (lp *LogPipeline) Matchers() []*labels.Matcher

Matchers returns the stream selectors from the parsed query.

func (*LogPipeline) Process

func (lp *LogPipeline) Process(entry model.Entry) (model.Entry, bool)

Process feeds a single log entry through the pipeline and returns the processed entry and whether it matched the selector and pipeline filters.

type MetricPipeline

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

MetricPipeline processes log entries through a parsed LogQL metric query, extracting numeric samples from matching entries.

func MetricQL

func MetricQL(query string) (*MetricPipeline, error)

MetricQL parses a LogQL metric query and returns a MetricPipeline.

func (*MetricPipeline) EvaluateLiteral

func (mp *MetricPipeline) EvaluateLiteral() (float64, error)

EvaluateLiteral evaluates a metric expression that has no real stream selector (e.g. vector(1)+vector(1)) and returns the resulting scalar value.

func (*MetricPipeline) HasRealSelector

func (mp *MetricPipeline) HasRealSelector() bool

HasRealSelector reports whether the metric query contains at least one non-empty stream selector. Expressions like vector(1)+vector(1) have no real selectors and should be evaluated as literals rather than matched against journal entries.

func (*MetricPipeline) Matchers

func (mp *MetricPipeline) Matchers() []*labels.Matcher

Matchers returns the stream selectors from the parsed metric query.

func (*MetricPipeline) Process

func (mp *MetricPipeline) Process(entry model.Entry) ([]float64, bool)

Process feeds a single log entry through the metric pipeline and returns the extracted sample values and whether the entry matched the selector. Each extractor produces its own set of samples; results are concatenated.

func (*MetricPipeline) Range

func (mp *MetricPipeline) Range() time.Duration

Range returns the range duration from the metric query's range selector (e.g., the `5m` in `count_over_time({job="sshd"}[5m])`). Recursively unwraps wrapper expressions (VectorAggregationExpr, BinOpExpr) to find the innermost RangeAggregationExpr. Returns 0 if the expression does not contain a range selector.

Jump to

Keyboard shortcuts

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