labels

package
v0.53.0 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2024 License: Apache-2.0 Imports: 13 Imported by: 969

Documentation

Index

Constants

View Source
const (
	MetricName   = "__name__"
	AlertName    = "alertname"
	BucketLabel  = "le"
	InstanceName = "instance"
)

Variables

This section is empty.

Functions

func Compare

func Compare(a, b Labels) int

Compare compares the two label sets. The result will be 0 if a==b, <0 if a < b, and >0 if a > b.

func Equal

func Equal(ls, o Labels) bool

Equal returns whether the two label sets are equal.

func StableHash added in v0.51.0

func StableHash(ls Labels) uint64

StableHash is a labels hashing implementation which is guaranteed to not change over time. This function should be used whenever labels hashing backward compatibility must be guaranteed.

Types

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

Builder allows modifying Labels.

func NewBuilder

func NewBuilder(base Labels) *Builder

NewBuilder returns a new LabelsBuilder.

func NewBuilderWithSymbolTable added in v0.51.0

func NewBuilderWithSymbolTable(_ *SymbolTable) *Builder

NewBuilderWithSymbolTable creates a Builder, for api parity with dedupelabels.

func (*Builder) Del

func (b *Builder) Del(ns ...string) *Builder

Del deletes the label of the given name.

func (*Builder) Get added in v0.43.0

func (b *Builder) Get(n string) string

func (*Builder) Keep added in v0.37.0

func (b *Builder) Keep(ns ...string) *Builder

Keep removes all labels from the base except those with the given names.

func (*Builder) Labels

func (b *Builder) Labels() Labels

Labels returns the labels from the builder. If no modifications were made, the original labels are returned.

func (*Builder) Range added in v0.43.0

func (b *Builder) Range(f func(l Label))

Range calls f on each label in the Builder.

func (*Builder) Reset

func (b *Builder) Reset(base Labels)

Reset clears all current state for the builder.

func (*Builder) Set

func (b *Builder) Set(n, v string) *Builder

Set the name/value pair as a label. A value of "" means delete that label.

type FastRegexMatcher

type FastRegexMatcher struct {
	// contains filtered or unexported fields
}

func NewFastRegexMatcher

func NewFastRegexMatcher(v string) (*FastRegexMatcher, error)

func (*FastRegexMatcher) GetRegexString

func (m *FastRegexMatcher) GetRegexString() string

func (*FastRegexMatcher) IsOptimized added in v0.52.0

func (m *FastRegexMatcher) IsOptimized() bool

IsOptimized returns true if any fast-path optimization is applied to the regex matcher.

func (*FastRegexMatcher) MatchString

func (m *FastRegexMatcher) MatchString(s string) bool

func (*FastRegexMatcher) SetMatches added in v0.52.0

func (m *FastRegexMatcher) SetMatches() []string

type Label

type Label struct {
	Name, Value string
}

Label is a key/value pair of strings.

type Labels

type Labels []Label

Labels is a sorted set of labels. Order has to be guaranteed upon instantiation.

func EmptyLabels added in v0.39.0

func EmptyLabels() Labels

EmptyLabels returns n empty Labels value, for convenience.

func FromMap

func FromMap(m map[string]string) Labels

FromMap returns new sorted Labels from the given map.

func FromStrings

func FromStrings(ss ...string) Labels

FromStrings creates new labels from pairs of strings.

func New

func New(ls ...Label) Labels

New returns a sorted Labels from the given labels. The caller has to guarantee that all label names are unique.

func ReadLabels

func ReadLabels(fn string, n int) ([]Labels, error)

ReadLabels reads up to n label sets in a JSON formatted file fn. It is mostly useful to load testing data.

func (Labels) Bytes

func (ls Labels) Bytes(buf []byte) []byte

Bytes returns ls as a byte slice. It uses an byte invalid character as a separator and so should not be used for printing.

func (Labels) BytesWithLabels added in v0.37.0

func (ls Labels) BytesWithLabels(buf []byte, names ...string) []byte

BytesWithLabels is just as Bytes(), but only for labels matching names. 'names' have to be sorted in ascending order.

func (Labels) BytesWithoutLabels added in v0.37.0

func (ls Labels) BytesWithoutLabels(buf []byte, names ...string) []byte

BytesWithoutLabels is just as Bytes(), but only for labels not matching names. 'names' have to be sorted in ascending order.

func (Labels) Copy

func (ls Labels) Copy() Labels

Copy returns a copy of the labels.

func (*Labels) CopyFrom added in v0.42.0

func (ls *Labels) CopyFrom(b Labels)

Copy labels from b on top of whatever was in ls previously, reusing memory or expanding if needed.

func (Labels) DropMetricName added in v0.50.0

func (ls Labels) DropMetricName() Labels

DropMetricName returns Labels with "__name__" removed.

func (Labels) Get

func (ls Labels) Get(name string) string

Get returns the value for the label with the given name. Returns an empty string if the label doesn't exist.

func (Labels) Has

func (ls Labels) Has(name string) bool

Has returns true if the label with the given name is present.

func (Labels) HasDuplicateLabelNames

func (ls Labels) HasDuplicateLabelNames() (string, bool)

HasDuplicateLabelNames returns whether ls has duplicate label names. It assumes that the labelset is sorted.

func (Labels) Hash

func (ls Labels) Hash() uint64

Hash returns a hash value for the label set. Note: the result is not guaranteed to be consistent across different runs of Prometheus.

func (Labels) HashForLabels

func (ls Labels) HashForLabels(b []byte, names ...string) (uint64, []byte)

HashForLabels returns a hash value for the labels matching the provided names. 'names' have to be sorted in ascending order.

func (Labels) HashWithoutLabels

func (ls Labels) HashWithoutLabels(b []byte, names ...string) (uint64, []byte)

HashWithoutLabels returns a hash value for all labels except those matching the provided names. 'names' have to be sorted in ascending order.

func (*Labels) InternStrings added in v0.42.0

func (ls *Labels) InternStrings(intern func(string) string)

InternStrings calls intern on every string value inside ls, replacing them with what it returns.

func (Labels) IsEmpty added in v0.42.0

func (ls Labels) IsEmpty() bool

IsEmpty returns true if ls represents an empty set of labels.

func (Labels) IsValid added in v0.41.0

func (ls Labels) IsValid() bool

IsValid checks if the metric name or label names are valid.

func (Labels) Len

func (ls Labels) Len() int

func (Labels) Less

func (ls Labels) Less(i, j int) bool

func (Labels) Map

func (ls Labels) Map() map[string]string

Map returns a string map of the labels.

func (Labels) MarshalJSON

func (ls Labels) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (Labels) MarshalYAML

func (ls Labels) MarshalYAML() (interface{}, error)

MarshalYAML implements yaml.Marshaler.

func (Labels) MatchLabels

func (ls Labels) MatchLabels(on bool, names ...string) Labels

MatchLabels returns a subset of Labels that matches/does not match with the provided label names based on the 'on' boolean. If on is set to true, it returns the subset of labels that match with the provided label names and its inverse when 'on' is set to false.

func (Labels) Range added in v0.42.0

func (ls Labels) Range(f func(l Label))

Range calls f on each label.

func (Labels) ReleaseStrings added in v0.42.0

func (ls Labels) ReleaseStrings(release func(string))

ReleaseStrings calls release on every string value inside ls.

func (Labels) String

func (ls Labels) String() string

func (Labels) Swap

func (ls Labels) Swap(i, j int)

func (*Labels) UnmarshalJSON

func (ls *Labels) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (*Labels) UnmarshalYAML

func (ls *Labels) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements yaml.Unmarshaler.

func (Labels) Validate added in v0.42.0

func (ls Labels) Validate(f func(l Label) error) error

Validate calls f on each label. If f returns a non-nil error, then it returns that error cancelling the iteration.

func (Labels) WithoutEmpty

func (ls Labels) WithoutEmpty() Labels

WithoutEmpty returns the labelset without empty labels. May return the same labelset.

type MatchType

type MatchType int

MatchType is an enum for label matching types.

const (
	MatchEqual MatchType = iota
	MatchNotEqual
	MatchRegexp
	MatchNotRegexp
)

Possible MatchTypes.

func (MatchType) String

func (m MatchType) String() string

type Matcher

type Matcher struct {
	Type  MatchType
	Name  string
	Value string
	// contains filtered or unexported fields
}

Matcher models the matching of a label.

func MustNewMatcher

func MustNewMatcher(mt MatchType, name, val string) *Matcher

MustNewMatcher panics on error - only for use in tests!

func NewMatcher

func NewMatcher(t MatchType, n, v string) (*Matcher, error)

NewMatcher returns a matcher object.

func (*Matcher) GetRegexString

func (m *Matcher) GetRegexString() string

GetRegexString returns the regex string.

func (*Matcher) Inverse

func (m *Matcher) Inverse() (*Matcher, error)

Inverse returns a matcher that matches the opposite.

func (*Matcher) IsRegexOptimized added in v0.52.0

func (m *Matcher) IsRegexOptimized() bool

IsRegexOptimized returns whether regex is optimized.

func (*Matcher) Matches

func (m *Matcher) Matches(s string) bool

Matches returns whether the matcher matches the given string value.

func (*Matcher) Prefix added in v0.52.0

func (m *Matcher) Prefix() string

Prefix returns the required prefix of the value to match, if possible. It will be empty if it's an equality matcher or if the prefix can't be determined.

func (*Matcher) SetMatches added in v0.52.0

func (m *Matcher) SetMatches() []string

SetMatches returns a set of equality matchers for the current regex matchers if possible. For examples the regexp `a(b|f)` will returns "ab" and "af". Returns nil if we can't replace the regexp by only equality matchers.

func (*Matcher) String

func (m *Matcher) String() string

type ScratchBuilder added in v0.42.0

type ScratchBuilder struct {
	// contains filtered or unexported fields
}

ScratchBuilder allows efficient construction of a Labels from scratch.

func NewScratchBuilder added in v0.42.0

func NewScratchBuilder(n int) ScratchBuilder

NewScratchBuilder creates a ScratchBuilder initialized for Labels with n entries.

func NewScratchBuilderWithSymbolTable added in v0.51.0

func NewScratchBuilderWithSymbolTable(_ *SymbolTable, n int) ScratchBuilder

NewScratchBuilderWithSymbolTable creates a ScratchBuilder, for api parity with dedupelabels.

func (*ScratchBuilder) Add added in v0.42.0

func (b *ScratchBuilder) Add(name, value string)

Add a name/value pair. Note if you Add the same name twice you will get a duplicate label, which is invalid.

func (*ScratchBuilder) Assign added in v0.42.0

func (b *ScratchBuilder) Assign(ls Labels)

Assign is for when you already have a Labels which you want this ScratchBuilder to return.

func (*ScratchBuilder) Labels added in v0.42.0

func (b *ScratchBuilder) Labels() Labels

Return the name/value pairs added so far as a Labels object. Note: if you want them sorted, call Sort() first.

func (*ScratchBuilder) Overwrite added in v0.44.0

func (b *ScratchBuilder) Overwrite(ls *Labels)

Write the newly-built Labels out to ls. Callers must ensure that there are no other references to ls, or any strings fetched from it.

func (*ScratchBuilder) Reset added in v0.42.0

func (b *ScratchBuilder) Reset()

func (*ScratchBuilder) SetSymbolTable added in v0.51.0

func (b *ScratchBuilder) SetSymbolTable(_ *SymbolTable)

func (*ScratchBuilder) Sort added in v0.42.0

func (b *ScratchBuilder) Sort()

Sort the labels added so far by name.

func (*ScratchBuilder) UnsafeAddBytes added in v0.49.0

func (b *ScratchBuilder) UnsafeAddBytes(name, value []byte)

Add a name/value pair, using []byte instead of string. The '-tags stringlabels' version of this function is unsafe, hence the name. This version is safe - it copies the strings immediately - but we keep the same name so everything compiles.

type Selector

type Selector []*Matcher

Selector holds constraints for matching against a label set.

func (Selector) Matches

func (s Selector) Matches(labels Labels) bool

Matches returns whether the labels satisfy all matchers.

type Slice

type Slice []Labels

Slice is a sortable slice of label sets.

func (Slice) Len

func (s Slice) Len() int

func (Slice) Less

func (s Slice) Less(i, j int) bool

func (Slice) Swap

func (s Slice) Swap(i, j int)

type StringMatcher added in v0.52.0

type StringMatcher interface {
	Matches(s string) bool
}

StringMatcher is a matcher that matches a string in place of a regular expression.

type SymbolTable added in v0.51.0

type SymbolTable struct{}

Symbol-table is no-op, just for api parity with dedupelabels.

func NewSymbolTable added in v0.51.0

func NewSymbolTable() *SymbolTable

func (*SymbolTable) Len added in v0.51.0

func (t *SymbolTable) Len() int

Jump to

Keyboard shortcuts

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