model

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// AlertNameLabel is the name of the label containing the an alert's name.
	AlertNameLabel = "alertname"

	// ExportedLabelPrefix is the prefix to prepend to the label names present in
	// exported metrics if a label of the same name is added by the server.
	ExportedLabelPrefix = "exported_"

	// MetricNameLabel is the label name indicating the metric name of a
	// timeseries.
	MetricNameLabel = "__name__"

	// SchemeLabel is the name of the label that holds the scheme on which to
	// scrape a target.
	SchemeLabel = "__scheme__"

	// AddressLabel is the name of the label that holds the address of
	// a scrape target.
	AddressLabel = "__address__"

	// MetricsPathLabel is the name of the label that holds the path on which to
	// scrape a target.
	MetricsPathLabel = "__metrics_path__"

	// ReservedLabelPrefix is a prefix which is not legal in user-supplied
	// label names.
	ReservedLabelPrefix = "__"

	// MetaLabelPrefix is a prefix for labels that provide meta information.
	// Labels with this prefix are used for intermediate label processing and
	// will not be attached to time series.
	MetaLabelPrefix = "__meta_"

	// TmpLabelPrefix is a prefix for temporary labels as part of relabelling.
	// Labels with this prefix are used for intermediate label processing and
	// will not be attached to time series. This is reserved for use in
	// Prometheus configuration files by users.
	TmpLabelPrefix = "__tmp_"

	// ParamLabelPrefix is a prefix for labels that provide URL parameters
	// used to scrape a target.
	ParamLabelPrefix = "__param_"

	// JobLabel is the label name indicating the job from which a timeseries
	// was scraped.
	JobLabel = "job"

	// InstanceLabel is the label name used for the instance label.
	InstanceLabel = "instance"

	// BucketLabel is used for the label that defines the upper bound of a
	// bucket of a histogram ("le" -> "less or equal").
	BucketLabel = "le"

	// QuantileLabel is used for the label that defines the quantile in a
	// summary.
	QuantileLabel = "quantile"
)
View Source
const SeparatorByte byte = 255

SeparatorByte is a byte that cannot occur in valid UTF-8 sequences and is used to separate label names, label values, and other strings from each other when calculating their combined hash value (aka signature aka fingerprint).

Variables

View Source
var LabelNameRE = regexp.MustCompile("^[a-zA-Z_][a-zA-Z0-9_]*$")

LabelNameRE is a regular expression matching valid label names. Note that the IsValid method of LabelName performs the same check but faster than a match with this regular expression.

View Source
var (
	// MetricNameRE is a regular expression matching valid metric
	// names. Note that the IsValidMetricName function performs the same
	// check but faster than a match with this regular expression.
	MetricNameRE = regexp.MustCompile(`^[a-zA-Z_:][a-zA-Z0-9_:]*$`)
)

Functions

func IsValidMetricName

func IsValidMetricName(n LabelValue) bool

IsValidMetricName returns true iff name matches the pattern of MetricNameRE. This function, however, does not use MetricNameRE for the check but a much faster hardcoded implementation.

func LabelsToSignature

func LabelsToSignature(labels map[string]string) uint64

LabelsToSignature returns a quasi-unique signature (i.e., fingerprint) for a given label set. (Collisions are possible but unlikely if the number of label sets the function is applied to is small.)

func SignatureForLabels

func SignatureForLabels(m Metric, labels ...LabelName) uint64

SignatureForLabels works like LabelsToSignature but takes a Metric as parameter (rather than a label map) and only includes the labels with the specified LabelNames into the signature calculation. The labels passed in will be sorted by this function.

func SignatureWithoutLabels

func SignatureWithoutLabels(m Metric, labels map[LabelName]struct{}) uint64

SignatureWithoutLabels works like LabelsToSignature but takes a Metric as parameter (rather than a label map) and excludes the labels with any of the specified LabelNames from the signature calculation.

Types

type Fingerprint

type Fingerprint uint64

Fingerprint provides a hash-capable representation of a Metric. For our purposes, FNV-1A 64-bit is used.

func FingerprintFromString

func FingerprintFromString(s string) (Fingerprint, error)

FingerprintFromString transforms a string representation into a Fingerprint.

func ParseFingerprint

func ParseFingerprint(s string) (Fingerprint, error)

ParseFingerprint parses the input string into a fingerprint.

func (Fingerprint) String

func (f Fingerprint) String() string

type FingerprintSet

type FingerprintSet map[Fingerprint]struct{}

FingerprintSet is a set of Fingerprints.

func (FingerprintSet) Equal

func (s FingerprintSet) Equal(o FingerprintSet) bool

Equal returns true if both sets contain the same elements (and not more).

func (FingerprintSet) Intersection

func (s FingerprintSet) Intersection(o FingerprintSet) FingerprintSet

Intersection returns the elements contained in both sets.

type Fingerprints

type Fingerprints []Fingerprint

Fingerprints represents a collection of Fingerprint subject to a given natural sorting scheme. It implements sort.Interface.

func (Fingerprints) Len

func (f Fingerprints) Len() int

Len implements sort.Interface.

func (Fingerprints) Less

func (f Fingerprints) Less(i, j int) bool

Less implements sort.Interface.

func (Fingerprints) Swap

func (f Fingerprints) Swap(i, j int)

Swap implements sort.Interface.

type LabelName

type LabelName string

A LabelName is a key for a LabelSet or Metric. It has a value associated therewith.

func (LabelName) IsValid

func (ln LabelName) IsValid() bool

IsValid is true iff the label name matches the pattern of LabelNameRE. This method, however, does not use LabelNameRE for the check but a much faster hardcoded implementation.

func (*LabelName) UnmarshalJSON

func (ln *LabelName) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (*LabelName) UnmarshalYAML

func (ln *LabelName) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface.

type LabelNames

type LabelNames []LabelName

LabelNames is a sortable LabelName slice. In implements sort.Interface.

func (LabelNames) Len

func (l LabelNames) Len() int

func (LabelNames) Less

func (l LabelNames) Less(i, j int) bool

func (LabelNames) String

func (l LabelNames) String() string

func (LabelNames) Swap

func (l LabelNames) Swap(i, j int)

type LabelPair

type LabelPair struct {
	Name  LabelName
	Value LabelValue
}

LabelPair pairs a name with a value.

type LabelPairs

type LabelPairs []*LabelPair

LabelPairs is a sortable slice of LabelPair pointers. It implements sort.Interface.

func (LabelPairs) Len

func (l LabelPairs) Len() int

func (LabelPairs) Less

func (l LabelPairs) Less(i, j int) bool

func (LabelPairs) Swap

func (l LabelPairs) Swap(i, j int)

type LabelSet

type LabelSet map[LabelName]LabelValue

A LabelSet is a collection of LabelName and LabelValue pairs. The LabelSet may be fully-qualified down to the point where it may resolve to a single Metric in the data store or not. All operations that occur within the realm of a LabelSet can emit a vector of Metric entities to which the LabelSet may match.

func (LabelSet) Before

func (ls LabelSet) Before(o LabelSet) bool

Before compares the metrics, using the following criteria:

If m has fewer labels than o, it is before o. If it has more, it is not.

If the number of labels is the same, the superset of all label names is sorted alphanumerically. The first differing label pair found in that order determines the outcome: If the label does not exist at all in m, then m is before o, and vice versa. Otherwise the label value is compared alphanumerically.

If m and o are equal, the method returns false.

func (LabelSet) Clone

func (ls LabelSet) Clone() LabelSet

Clone returns a copy of the label set.

func (LabelSet) Equal

func (ls LabelSet) Equal(o LabelSet) bool

Equal returns true iff both label sets have exactly the same key/value pairs.

func (LabelSet) FastFingerprint

func (ls LabelSet) FastFingerprint() Fingerprint

FastFingerprint returns the LabelSet's Fingerprint calculated by a faster hashing algorithm, which is, however, more susceptible to hash collisions.

func (LabelSet) Fingerprint

func (ls LabelSet) Fingerprint() Fingerprint

Fingerprint returns the LabelSet's fingerprint.

func (LabelSet) Merge

func (l LabelSet) Merge(other LabelSet) LabelSet

Merge is a helper function to non-destructively merge two label sets.

func (LabelSet) String

func (l LabelSet) String() string

func (*LabelSet) UnmarshalJSON

func (l *LabelSet) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (LabelSet) Validate

func (ls LabelSet) Validate() error

Validate checks whether all names and values in the label set are valid.

type LabelValue

type LabelValue string

A LabelValue is an associated value for a LabelName.

func (LabelValue) IsValid

func (lv LabelValue) IsValid() bool

IsValid returns true iff the string is a valid UTF8.

type LabelValues

type LabelValues []LabelValue

LabelValues is a sortable LabelValue slice. It implements sort.Interface.

func (LabelValues) Len

func (l LabelValues) Len() int

func (LabelValues) Less

func (l LabelValues) Less(i, j int) bool

func (LabelValues) Swap

func (l LabelValues) Swap(i, j int)

type Metric

type Metric LabelSet

A Metric is similar to a LabelSet, but the key difference is that a Metric is a singleton and refers to one and only one stream of samples.

func (Metric) Before

func (m Metric) Before(o Metric) bool

Before compares the metrics' underlying label sets.

func (Metric) Clone

func (m Metric) Clone() Metric

Clone returns a copy of the Metric.

func (Metric) Equal

func (m Metric) Equal(o Metric) bool

Equal compares the metrics.

func (Metric) FastFingerprint

func (m Metric) FastFingerprint() Fingerprint

FastFingerprint returns a Metric's Fingerprint calculated by a faster hashing algorithm, which is, however, more susceptible to hash collisions.

func (Metric) Fingerprint

func (m Metric) Fingerprint() Fingerprint

Fingerprint returns a Metric's Fingerprint.

func (Metric) String

func (m Metric) String() string

Jump to

Keyboard shortcuts

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