promql

package
v2.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2026 License: Apache-2.0 Imports: 1 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

This section is empty.

Jump to

Keyboard shortcuts

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