source

package
v0.79.0 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindArgumentPosition

func FindArgumentPosition(expr string, within posrange.PositionRange, name string) posrange.PositionRange

func FindFuncNamePosition

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

func FindFuncPosition

func FindFuncPosition(expr string, within posrange.PositionRange, fn string, outside []posrange.PositionRange) posrange.PositionRange

func GetQueryFragment

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

func MostOuterOperation

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

Types

type DeadInfo

type DeadInfo struct {
	Reason   string
	Fragment posrange.PositionRange
}

type DeadLabel

type DeadLabel struct {
	Name          string
	Reason        string
	LabelReason   string
	UsageFragment posrange.PositionRange
	LabelFragment posrange.PositionRange
	Kind          DeadLabelKind
}

type DeadLabelKind

type DeadLabelKind uint8
const (
	ImpossibleDeadLabel DeadLabelKind = iota
	OrphanedLabel
	DuplicatedJoin
	UnusedLabel
)

func (DeadLabelKind) String

func (dlk DeadLabelKind) String() string

type Join

type Join struct {
	MatchingLabels []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.
	IsOn           bool
}

type LabelPromiseType

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

func (LabelPromiseType) MarshalYAML

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

Used for test snapshots.

type LabelTransform

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

type Operation

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

func (Operation) MarshalYAML

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

Used for test snapshots.

type Operations

type Operations []Operation

type ReturnInfo

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

type Source struct {
	Labels     map[string]LabelTransform `yaml:"labels,omitempty"`
	DeadInfo   *DeadInfo                 `yaml:"deadInfo,omitempty"`
	DeadLabels []DeadLabel               `yaml:"deadLabels,omitempty"`
	Returns    promParser.ValueType      `yaml:"returns"`
	Operations Operations                `yaml:"operations,omitempty"`
	// Any other sources this source joins with.
	Joins []Join `yaml:"joins,omitempty"`
	// Any other sources this source is suppressed by.
	Unless     []Unless               `yaml:"unless,omitempty"`
	UsedLabels []string               `yaml:"usedLabels,omitempty"`
	ReturnInfo ReturnInfo             `yaml:"returnInfo,omitempty"`
	Position   posrange.PositionRange `yaml:"position"`
	Type       Type                   `yaml:"type"`
	// Labels are fixed and only allowed labels can be present.
	FixedLabels bool `yaml:"fixedLabels,omitempty"`
	// True if this source is guarded by 'foo > 5' or other condition.
	IsConditional bool `yaml:"isConditional,omitempty"`
}

func LabelsSource

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

func (Source) CanHaveLabel

func (s Source) CanHaveLabel(name string) bool

func (Source) LabelExcludeReason

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

func (Source) Operation

func (s Source) Operation() string

func (Source) TransformedLabels

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

func (Source) WalkSources

func (s Source) WalkSources(fn Visitor)

type Type

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

func (Type) MarshalYAML

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

Used for test snapshots.

type Unless

type Unless struct {
	MatchingLabels []string
	Src            Source
	IsOn           bool
}

type Visitor

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