labels

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package labels defines the data model for time-series label pairs.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmptyName     = errors.New("labels: empty label name")
	ErrInvalidUTF8   = errors.New("labels: label contains invalid UTF-8")
	ErrDuplicateName = errors.New("labels: duplicate label name")
)

Functions

func Equal

func Equal(a, b []Label) bool

Equal reports whether two sorted label sets are identical.

func Hash

func Hash(ls []Label) uint64

Hash returns a 64-bit FNV-1a hash of the sorted label set. Labels must be sorted by name before calling.

func Validate

func Validate(ls []Label) error

Validate checks that labels are sorted, non-empty named, valid UTF-8, and have no duplicate names.

Types

type Label

type Label struct {
	Name  string
	Value string
}

Label is a name/value pair identifying a time series.

func FromStrings

func FromStrings(ss ...string) []Label

FromStrings creates a sorted label set from alternating name/value pairs. Panics if an odd number of strings is provided.

func Sort

func Sort(ls []Label) []Label

Sort sorts labels by name in place and returns them.

type MatchType

type MatchType int

MatchType identifies the type of a label matcher.

const (
	MatchEqual MatchType = iota
	MatchNotEqual
	MatchRegexp
	MatchNotRegexp
)

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 matches label values against a pattern.

func MustNewMatcher

func MustNewMatcher(typ MatchType, name, value string) *Matcher

MustNewMatcher is like NewMatcher but panics on error.

func NewMatcher

func NewMatcher(typ MatchType, name, value string) (*Matcher, error)

NewMatcher creates a new Matcher. For regex types, the value is compiled as a full-match regular expression (anchored with ^(?:...)$).

func (*Matcher) Matches

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

Matches reports whether the given label value satisfies this matcher.

func (*Matcher) String

func (m *Matcher) String() string

Jump to

Keyboard shortcuts

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