promql

package
v2.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package promql provides utilities for parsing and rewriting PromQL queries.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OuterAggregator

func OuterAggregator(query string) (string, bool)

OuterAggregator returns the name of the outermost PromQL aggregation operator in query (lowercased), and true if one was found. The remainder of the query string is unchanged; this function only inspects the prefix.

Examples:

OuterAggregator("sum(rate(http_requests_total[5m]))")        → "sum", true
OuterAggregator("avg by (region) (requests)")               → "avg", true
OuterAggregator("http_requests_total{job=\"api\"}")          → "",    false
OuterAggregator("avg_over_time(cpu[5m])")                   → "",    false  (function, not aggregator)

func ReplaceOuterAggregator

func ReplaceOuterAggregator(query, aggregator, replacement string) string

ReplaceOuterAggregator substitutes the outermost aggregator keyword in query with replacement, preserving the rest of the query verbatim. aggregator must match the lowercased aggregator as returned by OuterAggregator.

Example:

ReplaceOuterAggregator("avg by (r) (errors)", "avg", "sum") → "sum by (r) (errors)"

Types

type AggregationGrouping added in v2.0.3

type AggregationGrouping struct {
	Labels  []string
	Without bool
}

type RankAggregation added in v2.0.3

type RankAggregation struct {
	Operator       string
	K              int
	InnerQuery     string
	Grouping       AggregationGrouping
	SortSet        bool
	SortDescending bool
}

func ParseRankAggregation added in v2.0.3

func ParseRankAggregation(query string) (RankAggregation, bool)

Jump to

Keyboard shortcuts

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