Documentation
¶
Index ¶
- Constants
- func FindFuncNamePosition(expr string, within posrange.PositionRange, fn string) posrange.PositionRange
- func FindFuncPosition(expr string, within posrange.PositionRange, fn string, ...) posrange.PositionRange
- func FindMatcherPos(expr string, within posrange.PositionRange, m *labels.Matcher) posrange.PositionRange
- func GetQueryFragment(expr string, pos posrange.PositionRange) string
- func MostOuterOperation[T promParser.Node](s *Source) (T, bool)
- func ResetFeatures()
- func SetFeatures(f *Features)
- type DeadInfo
- type DeadLabel
- type DeadLabelKind
- type FeatureRequirement
- type FeatureVersion
- type Features
- type Fill
- type Join
- type LabelPromiseType
- type LabelTransform
- type Operation
- type Operations
- type PrometheusVersion
- type RangeSelectorMode
- type ReturnInfo
- type Source
- type Type
- type Unless
- type Visitor
Constants ¶
const ( FeatureExperimentalFunctions = "promql-experimental-functions" FeatureDurationExpr = "promql-duration-expr" FeatureExtendedRangeSelectors = "promql-extended-range-selectors" FeatureBinopFillModifiers = "promql-binop-fill-modifiers" )
Variables ¶
This section is empty.
Functions ¶
func FindFuncNamePosition ¶
func FindFuncNamePosition(expr string, within posrange.PositionRange, fn string) posrange.PositionRange
FindFuncNamePosition returns the position of fn inside the within fragment, matching fn case-insensitively only when it is followed by '(' (ignoring whitespace), so "by" matches "by (...)" but not "bytes".
func FindFuncPosition ¶
func FindFuncPosition(expr string, within posrange.PositionRange, fn string, outside []posrange.PositionRange) posrange.PositionRange
FindFuncPosition returns the position of the whole `fn(...)` call inside the within fragment, from fn up to its closing ')'. When within spans more than one call, outside lists ranges the match must fall within, which lets callers pick the right `fn(...)` when the same keyword appears on both sides.
func FindMatcherPos ¶ added in v0.85.0
func FindMatcherPos(expr string, within posrange.PositionRange, m *labels.Matcher) posrange.PositionRange
FindMatcherPos locates 'name op "value"' (e.g. job=~"foo") in the expression fragment and returns the position spanning from "name" through the closing quote, with End exclusive (one past the closing quote) to match the other position functions and GetQueryFragment.
func GetQueryFragment ¶
func GetQueryFragment(expr string, pos posrange.PositionRange) string
func MostOuterOperation ¶
func MostOuterOperation[T promParser.Node](s *Source) (T, bool)
func ResetFeatures ¶ added in v0.80.0
func ResetFeatures()
ResetFeatures restores the package-level feature registry to the built-in defaults. Call this in test cleanup.
func SetFeatures ¶ added in v0.80.0
func SetFeatures(f *Features)
SetFeatures replaces the package-level feature registry. Intended for use in tests to inject fake features.
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 FeatureRequirement ¶ added in v0.80.0
type FeatureRequirement struct {
Feature string `yaml:"feature"`
Name string `yaml:"name"`
Fragments []posrange.PositionRange `yaml:"fragments"`
}
type FeatureVersion ¶ added in v0.80.0
type FeatureVersion struct {
Flag string
MinVersion PrometheusVersion
StableVersion PrometheusVersion
}
func LookupFeatureVersion ¶ added in v0.80.0
func LookupFeatureVersion(name string) (FeatureVersion, bool)
LookupFeatureVersion returns the FeatureVersion for a given feature element name from the default registry, if it exists.
type Features ¶ added in v0.80.0
type Features struct {
// contains filtered or unexported fields
}
Features is a registry of PromQL features that require feature flags. It maps feature element names to their version and flag requirements. Use the package-level default via LookupFeatureVersion, or create a custom registry in tests via NewFeatures and SetFeatures.
func NewFeatures ¶ added in v0.80.0
func NewFeatures() *Features
NewFeatures creates an empty feature registry.
func (*Features) Lookup ¶ added in v0.80.0
func (f *Features) Lookup(name string) (FeatureVersion, bool)
Lookup returns the FeatureVersion for a given feature element name, if registered.
func (*Features) Register ¶ added in v0.80.0
func (f *Features) Register(name string, fv FeatureVersion)
Register adds a feature to the registry.
type Join ¶
type Join struct {
Fill *Fill // Fill values for unmatched series (binop fill modifiers).
DeadInfo *DeadInfo
Src *Source // The source we're joining with.
DeadLabels []DeadLabel // Per-pairing dead labels from checkJoinedLabels/checkIncludedLabels.
MatchingLabels []string
AddedLabels []string
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
}
func (Join) MarshalYAML ¶ added in v0.80.0
Used for test snapshots.
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 ¶
Used for test snapshots.
type Operations ¶
type Operations []Operation
type PrometheusVersion ¶ added in v0.80.0
func ParseVersion ¶ added in v0.80.0
func ParseVersion(s string) (PrometheusVersion, error)
ParseVersion parses a Prometheus version string like "2.49.0" or "3.5.0-rc.1" into a PrometheusVersion.
func (PrometheusVersion) IsLessThan ¶ added in v0.80.0
func (v PrometheusVersion) IsLessThan(other PrometheusVersion) bool
func (PrometheusVersion) IsZero ¶ added in v0.80.0
func (v PrometheusVersion) IsZero() bool
func (PrometheusVersion) String ¶ added in v0.80.0
func (v PrometheusVersion) String() string
type RangeSelectorMode ¶ added in v0.80.0
type RangeSelectorMode uint8
const ( RangeSelectorDefault RangeSelectorMode = iota RangeSelectorAnchored // VectorSelector uses the anchored modifier. RangeSelectorSmoothed // VectorSelector uses the smoothed modifier. )
func (RangeSelectorMode) MarshalYAML ¶ added in v0.80.0
func (rsm RangeSelectorMode) MarshalYAML() (any, error)
Used for test snapshots.
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"`
// Any other sources used indirectly, not contributing labels.
Indirect []*Source `yaml:"indirect,omitempty"`
NeedsFeatures []FeatureRequirement `yaml:"needsFeatures,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"`
RangeSelectorMode RangeSelectorMode `yaml:"rangeSelectorMode,omitempty"`
}
func LabelsSource ¶
func LabelsSource(expr string, node promParser.Node) (src []*Source)
func (Source) CanHaveLabel ¶
func (Source) LabelExcludeReason ¶
func (s Source) LabelExcludeReason(name string) (string, posrange.PositionRange)
func (Source) TransformedLabels ¶
func (s Source) TransformedLabels(kinds ...LabelPromiseType) []string
func (*Source) WalkSources ¶
type Unless ¶
func (Unless) MarshalYAML ¶ added in v0.85.0
Used for test snapshots.