utils

package
v0.76.1 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindPosition added in v0.71.0

func FindPosition(expr string, within posrange.PositionRange, fn string) posrange.PositionRange

FIXME sum() on ().

func GetQueryFragment added in v0.71.0

func GetQueryFragment(expr string, pos posrange.PositionRange) string

func HasVectorSelector added in v0.4.1

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

func MostOuterOperation added in v0.74.0

func MostOuterOperation[T promParser.Node](s Source) (T, bool)

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 DeadInfo added in v0.74.0

type DeadInfo struct {
	Reason   string
	Fragment posrange.PositionRange
}

type Join added in v0.71.0

type Join struct {
	On          []string
	Ignoring    []string
	AddedLabels []string
	Src         Source              // The source we're joining with.
	Op          promParser.ItemType // The binary operation used for this join.
	Depth       int                 // Zero if this is a direct join, non-zero otherwise. sum(foo * bar) would be in-direct join.
}

type LabelPromiseType added in v0.74.0

type LabelPromiseType uint8
const (
	ImpossibleLabel LabelPromiseType = iota
	PossibleLabel
	GuaranteedLabel
)

func (LabelPromiseType) MarshalYAML added in v0.74.0

func (lpt LabelPromiseType) MarshalYAML() (any, error)

Used for test snapshots.

type LabelTransform added in v0.74.0

type LabelTransform struct {
	Reason   string
	Kind     LabelPromiseType
	Fragment posrange.PositionRange
}

type ReturnInfo added in v0.74.0

type ReturnInfo struct {
	LogicalExpr    string
	ValuePosition  posrange.PositionRange
	ReturnedNumber float64 // If AlwaysReturns=true this is the number that's returned
	AlwaysReturns  bool    // True if this source always returns results.
	KnownReturn    bool    // True if we always know the return value.
	IsReturnBool   bool    // True if this source uses the 'bool' modifier.
}

type Source added in v0.67.0

type Source struct {
	Labels        map[string]LabelTransform
	DeadInfo      *DeadInfo
	Returns       promParser.ValueType
	Operations    SourceOperations
	Joins         []Join   // Any other sources this source joins with.
	Unless        []Unless // Any other sources this source is suppressed by.
	ReturnInfo    ReturnInfo
	Position      posrange.PositionRange
	Type          SourceType
	FixedLabels   bool // Labels are fixed and only allowed labels can be present.
	IsConditional bool // True if this source is guarded by 'foo > 5' or other condition.
}

func LabelsSource added in v0.67.0

func LabelsSource(expr string, node promParser.Node) (src []Source)

func (Source) CanHaveLabel added in v0.71.0

func (s Source) CanHaveLabel(name string) bool

func (Source) LabelExcludeReason added in v0.71.0

func (s Source) LabelExcludeReason(name string) (string, posrange.PositionRange)

func (Source) Operation added in v0.67.0

func (s Source) Operation() string

func (Source) TransformedLabels added in v0.74.0

func (s Source) TransformedLabels(kinds ...LabelPromiseType) []string

func (Source) WalkSources added in v0.71.0

func (s Source) WalkSources(fn Visitor)

type SourceOperation added in v0.74.0

type SourceOperation struct {
	Node      promParser.Node
	Operation string
	Arguments []string
}

func (SourceOperation) MarshalYAML added in v0.74.0

func (so SourceOperation) MarshalYAML() (any, error)

Used for test snapshots.

type SourceOperations added in v0.74.0

type SourceOperations []SourceOperation

type SourceType added in v0.67.0

type SourceType uint8
const (
	UnknownSource SourceType = iota
	NumberSource
	StringSource
	SelectorSource
	FuncSource
	AggregateSource
)

func (SourceType) MarshalYAML added in v0.74.0

func (st SourceType) MarshalYAML() (any, error)

Used for test snapshots.

type Unless added in v0.74.1

type Unless struct {
	On       []string
	Ignoring []string
	Src      Source
}

type Visitor added in v0.71.0

type Visitor func(s Source, j *Join, u *Unless)

Jump to

Keyboard shortcuts

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