utils

package
v0.55.0 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HasOuterAggregation

func HasOuterAggregation(node *parser.PromQLNode) (aggs []*promParser.AggregateExpr)

func HasOuterBinaryExpr added in v0.8.0

func HasOuterBinaryExpr(node *parser.PromQLNode) *promParser.BinaryExpr

func HasOuterRate added in v0.28.0

func HasOuterRate(node *parser.PromQLNode) (calls []*promParser.Call)

func HasOuterSum added in v0.41.0

func HasOuterSum(node *parser.PromQLNode) (calls []*promParser.AggregateExpr)

func HasVectorSelector added in v0.4.1

func HasVectorSelector(node *parser.PromQLNode) (vs []*promParser.VectorSelector)

func RemoveConditions added in v0.10.1

func RemoveConditions(source string) promParser.Node

RemoveConditions takes a *valid* PromQL expression and removes any condition from it.

Types

type Node added in v0.55.0

type Node struct {
	Parent *Node
	Expr   parser.Node
	// contains filtered or unexported fields
}

Node is used to turn the parsed PromQL query expression into a tree. This allows us to walk the tree up & down and look for either parents or children of specific type. Which is useful if you, for example, want to check if all vector selectors are wrapped inside function calls etc.

func Tree added in v0.55.0

func Tree(expr parser.Node, parent *Node) Node

Tree takes a parsed PromQL node and turns it into a Node instance with parent and children populated.

func WalkDown added in v0.55.0

func WalkDown[T parser.Node](node *Node) (nodes []*Node)

WalkDown works just like findParents but it walks the tree down, visiting all children. It also starts by checking the node passed to it before walking down the tree.

func WalkUp added in v0.55.0

func WalkUp[T parser.Node](node *Node) (nodes []*Node)

WalkUp allows to iterate a promQLNode node looking for parents of specific type. Prometheus parser returns interfaces which makes it more difficult to figure out what kind of node we're dealing with, hence this helper takes a type parameter it tries to cast. It starts by checking the node passed to it and then walks up by visiting all parent nodes.

type PromQLFragment added in v0.16.1

type PromQLFragment struct {
	Fragment *parser.PromQLNode
	BinExpr  *promParser.BinaryExpr
}

func HasOuterAbsent added in v0.4.1

func HasOuterAbsent(node *parser.PromQLNode) (calls []PromQLFragment)

Jump to

Keyboard shortcuts

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