promql

package
v0.55.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 Imports: 18 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package promql is an optional adapter that bridges the storage fetch contract (query/fetch) to the Prometheus storage.Queryable interface. It does not own a PromQL engine: the embedder (e.g. go-faster/oteldb, which already has PromQL/LogQL/TraceQL engines) drives its own promql.Engine over the Queryable this package returns. The storage library proper stops at the fetch seam and stays language- and Prometheus-free; this package is the only one importing github.com/prometheus/prometheus, and importing it is opt-in.

Condition extraction lives here: matchers use canonical text, with absent labels matched as empty strings. Internal labels hidden by projection are checked in this adapter alone.

Index

Constants

This section is empty.

Variables

View Source
var AmbiguousRollupWarning = fmt.Errorf(
	"%w: result left out downsampled data rolled up with a different aggregation; "+
		"storage nodes run different downsampling policies for this tenant",
	annotations.PromQLWarning,
)

AmbiguousRollupWarning is the PromQL warning annotation a Select attaches when a returned series is fetch.Batch.AmbiguousRollup: at some timestamp it held downsample representatives rolled up with different aggregations, and the result carries one aggregation's and leaves the others out.

View Source
var SampledWarning = fmt.Errorf(
	"%w: result computed over weighted series (lossy-sampled or rolled up); per-sample counts and sums "+
		"undercount the rows behind each point, and rates over rolled-up series are approximate",
	annotations.PromQLWarning,
)

SampledWarning is the PromQL warning annotation a Select attaches when at least one returned series carries weights (a fetch.Batch.ScaleFactors entry above 1): a lossy-sampled row standing for the rows sampling dropped, or an Avg downsample representative standing for its bucket's samples. The Prometheus engine surfaces it in the query result's warnings. The adapter cannot tell the two kinds apart, so the warning claims nothing is exact: count_over_time, sum_over_time and any operator that treats each point as an independent event undercount the rows the weights stand for, and rate, increase, resets and other reset-sensitive functions are approximate over an Avg rollup, whose points are bucket means rather than counter values. Only a sampling weight leaves the rate of a cumulative counter intact.

Functions

func MatchesAll added in v0.9.0

func MatchesAll(lset labels.Labels, ms []*labels.Matcher) bool

MatchesAll reports whether a series' labels satisfy every matcher, treating an absent label as the empty string (Prometheus semantics). It is the post-fetch re-check companion to PushableMatchers: exported so an embedder's pushdown path re-checks the full matcher set the same way Queryable does.

func PromLabels added in v0.9.0

func PromLabels(s signal.Series) labels.Labels

PromLabels projects a storage series identity to a Prometheus label set: every resource, scope, and (folded) point attribute becomes a label, with the internal reserved labels (except __name__) hidden. Scope name/version are exposed under the otel.scope.* keys, the same labels the head indexes.

PromLabels is exported so an embedder can render a signal.Series (e.g. the identity carried alongside an github.com/oteldb/storage.Storage.AggregateMetrics result) as PromQL labels without duplicating this projection.

func PushableMatchers added in v0.9.0

func PushableMatchers(ms []*labels.Matcher) []fetch.Matcher

PushableMatchers lowers visible-label matchers, including absent and negated predicates. Hidden internal labels remain subject to MatchesAll after projection.

Types

type LabelCache added in v0.24.0

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

LabelCache memoizes a series identity's projected Prometheus label set. The projection is a pure function of the content-addressed signal.SeriesID, so a cached entry is always valid; the cache is bounded by series cardinality (the same set Prometheus keeps resident). It is safe for concurrent use and may be shared across a Queryable's queriers and — via NewQueryableWithCache — across successive Queryables over the engine's lifetime.

func NewLabelCache added in v0.24.0

func NewLabelCache() *LabelCache

NewLabelCache returns an empty LabelCache ready to share across queries.

func (*LabelCache) Len added in v0.24.0

func (c *LabelCache) Len() int

Len reports the number of interned series projections. It lets an embedder observe the cache's resident size (e.g. to expose a metric or decide when to swap in a fresh cache on series churn).

type Queryable

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

Queryable adapts a fetch.Fetcher (one tenant's engine) to the Prometheus storage.Queryable interface for a single tenant.

func NewQueryable

func NewQueryable(fetcher fetch.Fetcher, tenant signal.TenantID) *Queryable

NewQueryable returns a Prometheus storage.Queryable backed by fetcher for the given tenant. A single Queryable reused across queries (the embedder's per-tenant adapter) memoizes label projections, so repeated queries pay the projection cost once per series.

Each call allocates a fresh LabelCache. An embedder that takes a new fetcher per query (to observe the latest head) but wants label projections interned across the engine's lifetime should hold a LabelCache itself and use NewQueryableWithCache.

func NewQueryableWithCache added in v0.24.0

func NewQueryableWithCache(fetcher fetch.Fetcher, tenant signal.TenantID, cache *LabelCache) *Queryable

NewQueryableWithCache is NewQueryable with an explicit, caller-owned LabelCache. The cache is keyed by content-addressed signal.SeriesID, so an entry is valid for the life of the series and may be shared across Queryables built over different fetchers of the same engine — letting the embedder intern label projections for the engine's lifetime rather than per query. The cache is safe for concurrent use.

func (*Queryable) Querier

func (q *Queryable) Querier(mint, maxt int64) (storage.Querier, error)

Querier returns a querier over [mint, maxt] (Prometheus milliseconds).

func (*Queryable) QuerierWithScope added in v0.37.0

func (q *Queryable) QuerierWithScope(mint, maxt int64, scope *fetch.Scope) (storage.Querier, error)

QuerierWithScope is Queryable.Querier bound to a caller-supplied fetch.Scope, for an embedder whose logical query spans more than this querier — its own reads plus the ones it makes here. Sharing the scope is what keeps admission from treating those as unrelated queries and blocking the caller against its own reservation.

type WeightedSeries added in v0.45.0

type WeightedSeries interface {
	ScaleFactors() []float64
}

WeightedSeries is implemented by every series a Queryable returns. ScaleFactors returns the per-sample weights in the iterator's sample order, or nil when every weight is 1. A chunkenc.Iterator has no weight channel, so the adapter never folds the weight into a value (that would scale gauges and cumulative counters, which are correct as stored); an embedder's weight-aware operator reads it here instead.

Jump to

Keyboard shortcuts

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