package model
import "github.com/prometheus/common/model"
Package model contains common data structures that are shared across Prometheus components and libraries.
Index ¶
- Constants
- Variables
- func EscapeMetricFamily(v *dto.MetricFamily, scheme EscapingScheme) *dto.MetricFamily
- func EscapeName(name string, scheme EscapingScheme) string
- func IsValidLegacyMetricName(n string) bool
- func IsValidMetricName(n LabelValue) bool
- func LabelsToSignature(labels map[string]string) uint64
- func SignatureForLabels(m Metric, labels ...LabelName) uint64
- func SignatureWithoutLabels(m Metric, labels map[LabelName]struct{}) uint64
- func UnescapeName(name string, scheme EscapingScheme) string
- type Alert
- func (a *Alert) Fingerprint() Fingerprint
- func (a *Alert) Name() string
- func (a *Alert) Resolved() bool
- func (a *Alert) ResolvedAt(ts time.Time) bool
- func (a *Alert) Status() AlertStatus
- func (a *Alert) StatusAt(ts time.Time) AlertStatus
- func (a *Alert) String() string
- func (a *Alert) Validate() error
- type AlertStatus
- type Alerts
- func (as Alerts) HasFiring() bool
- func (as Alerts) HasFiringAt(ts time.Time) bool
- func (as Alerts) Len() int
- func (as Alerts) Less(i, j int) bool
- func (as Alerts) Status() AlertStatus
- func (as Alerts) StatusAt(ts time.Time) AlertStatus
- func (as Alerts) Swap(i, j int)
- type Duration
- func ParseDuration(s string) (Duration, error)
- func (d Duration) MarshalJSON() ([]byte, error)
- func (d *Duration) MarshalText() ([]byte, error)
- func (d Duration) MarshalYAML() (interface{}, error)
- func (d *Duration) Set(s string) error
- func (d Duration) String() string
- func (d *Duration) Type() string
- func (d *Duration) UnmarshalJSON(bytes []byte) error
- func (d *Duration) UnmarshalText(text []byte) error
- func (d *Duration) UnmarshalYAML(unmarshal func(interface{}) error) error
- type EscapingScheme
- type Fingerprint
- func FingerprintFromString(s string) (Fingerprint, error)
- func ParseFingerprint(s string) (Fingerprint, error)
- func (f Fingerprint) String() string
- type FingerprintSet
- func (s FingerprintSet) Equal(o FingerprintSet) bool
- func (s FingerprintSet) Intersection(o FingerprintSet) FingerprintSet
- type Fingerprints
- func (f Fingerprints) Len() int
- func (f Fingerprints) Less(i, j int) bool
- func (f Fingerprints) Swap(i, j int)
- type FloatString
- func (v FloatString) MarshalJSON() ([]byte, error)
- func (v FloatString) String() string
- func (v *FloatString) UnmarshalJSON(b []byte) error
- type HistogramBucket
- func (s *HistogramBucket) Equal(o *HistogramBucket) bool
- func (s HistogramBucket) MarshalJSON() ([]byte, error)
- func (b HistogramBucket) String() string
- func (s *HistogramBucket) UnmarshalJSON(buf []byte) error
- type HistogramBuckets
- type Interval
- type LabelName
- func (ln LabelName) IsValid() bool
- func (ln LabelName) IsValidLegacy() bool
- func (ln *LabelName) UnmarshalJSON(b []byte) error
- func (ln *LabelName) UnmarshalYAML(unmarshal func(interface{}) error) error
- type LabelNames
- func (l LabelNames) Len() int
- func (l LabelNames) Less(i, j int) bool
- func (l LabelNames) String() string
- func (l LabelNames) Swap(i, j int)
- type LabelPair
- type LabelPairs
- func (l LabelPairs) Len() int
- func (l LabelPairs) Less(i, j int) bool
- func (l LabelPairs) Swap(i, j int)
- type LabelSet
- func (ls LabelSet) Before(o LabelSet) bool
- func (ls LabelSet) Clone() LabelSet
- func (ls LabelSet) Equal(o LabelSet) bool
- func (ls LabelSet) FastFingerprint() Fingerprint
- func (ls LabelSet) Fingerprint() Fingerprint
- func (l LabelSet) Merge(other LabelSet) LabelSet
- func (l LabelSet) String() string
- func (l *LabelSet) UnmarshalJSON(b []byte) error
- func (ls LabelSet) Validate() error
- type LabelValue
- type LabelValues
- func (l LabelValues) Len() int
- func (l LabelValues) Less(i, j int) bool
- func (l LabelValues) Swap(i, j int)
- type Matcher
- type Matrix
- func (m Matrix) Len() int
- func (m Matrix) Less(i, j int) bool
- func (mat Matrix) String() string
- func (m Matrix) Swap(i, j int)
- func (Matrix) Type() ValueType
- type Metric
- func (m Metric) Before(o Metric) bool
- func (m Metric) Clone() Metric
- func (m Metric) Equal(o Metric) bool
- func (m Metric) FastFingerprint() Fingerprint
- func (m Metric) Fingerprint() Fingerprint
- func (m Metric) String() string
- type MetricType
- type Sample
- func (s *Sample) Equal(o *Sample) bool
- func (s Sample) MarshalJSON() ([]byte, error)
- func (s Sample) String() string
- func (s *Sample) UnmarshalJSON(b []byte) error
- type SampleHistogram
- type SampleHistogramPair
- func (s *SampleHistogramPair) Equal(o *SampleHistogramPair) bool
- func (s SampleHistogramPair) MarshalJSON() ([]byte, error)
- func (s SampleHistogramPair) String() string
- func (s *SampleHistogramPair) UnmarshalJSON(buf []byte) error
- type SamplePair
- func (s *SamplePair) Equal(o *SamplePair) bool
- func (s SamplePair) MarshalJSON() ([]byte, error)
- func (s SamplePair) String() string
- func (s *SamplePair) UnmarshalJSON(b []byte) error
- type SampleStream
- func (ss SampleStream) MarshalJSON() ([]byte, error)
- func (ss SampleStream) String() string
- func (ss *SampleStream) UnmarshalJSON(b []byte) error
- type SampleValue
- func (v SampleValue) Equal(o SampleValue) bool
- func (v SampleValue) MarshalJSON() ([]byte, error)
- func (v SampleValue) String() string
- func (v *SampleValue) UnmarshalJSON(b []byte) error
- type Samples
- func (s Samples) Equal(o Samples) bool
- func (s Samples) Len() int
- func (s Samples) Less(i, j int) bool
- func (s Samples) Swap(i, j int)
- type Scalar
- func (s Scalar) MarshalJSON() ([]byte, error)
- func (s Scalar) String() string
- func (*Scalar) Type() ValueType
- func (s *Scalar) UnmarshalJSON(b []byte) error
- type Silence
- type String
- func (s String) MarshalJSON() ([]byte, error)
- func (s *String) String() string
- func (*String) Type() ValueType
- func (s *String) UnmarshalJSON(b []byte) error
- type Time
- func Now() Time
- func TimeFromUnix(t int64) Time
- func TimeFromUnixNano(t int64) Time
- func (t Time) Add(d time.Duration) Time
- func (t Time) After(o Time) bool
- func (t Time) Before(o Time) bool
- func (t Time) Equal(o Time) bool
- func (t Time) MarshalJSON() ([]byte, error)
- func (t Time) String() string
- func (t Time) Sub(o Time) time.Duration
- func (t Time) Time() time.Time
- func (t Time) Unix() int64
- func (t Time) UnixNano() int64
- func (t *Time) UnmarshalJSON(b []byte) error
- type ValidationScheme
- type Value
- type ValueType
- func (et ValueType) MarshalJSON() ([]byte, error)
- func (e ValueType) String() string
- func (et *ValueType) UnmarshalJSON(b []byte) error
- type Vector
Constants ¶
const ( // AlertNameLabel is the name of the label containing the 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__" // ScrapeIntervalLabel is the name of the label that holds the scrape interval // used to scrape a target. ScrapeIntervalLabel = "__scrape_interval__" // ScrapeTimeoutLabel is the name of the label that holds the scrape // timeout used to scrape a target. ScrapeTimeoutLabel = "__scrape_timeout__" // 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" )
const ( MetricTypeCounter = MetricType("counter") MetricTypeGauge = MetricType("gauge") MetricTypeHistogram = MetricType("histogram") MetricTypeGaugeHistogram = MetricType("gaugehistogram") MetricTypeSummary = MetricType("summary") MetricTypeInfo = MetricType("info") MetricTypeStateset = MetricType("stateset") MetricTypeUnknown = MetricType("unknown") )
const ( // EscapingKey is the key in an Accept or Content-Type header that defines how // metric and label names that do not conform to the legacy character // requirements should be escaped when being scraped by a legacy prometheus // system. If a system does not explicitly pass an escaping parameter in the // Accept header, the default NameEscapingScheme will be used. EscapingKey = "escaping" // Possible values for Escaping Key: AllowUTF8 = "allow-utf-8" // No escaping required. EscapeUnderscores = "underscores" EscapeDots = "dots" EscapeValues = "values" )
const ( // Earliest is the earliest Time representable. Handy for // initializing a high watermark. Earliest = Time(math.MinInt64) // Latest is the latest Time representable. Handy for initializing // a low watermark. Latest = Time(math.MaxInt64) )
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 ¶
var ( // NameValidationScheme determines the global default method of the name // validation to be used by all calls to IsValidMetricName() and LabelName // IsValid(). // // Deprecated: This variable should not be used and might be removed in the // far future. If you wish to stick to the legacy name validation use // `IsValidLegacyMetricName()` and `LabelName.IsValidLegacy()` methods // instead. This variable is here as an escape hatch for emergency cases, // given the recent change from `LegacyValidation` to `UTF8Validation`, e.g., // to delay UTF-8 migrations in time or aid in debugging unforeseen results of // the change. In such a case, a temporary assignment to `LegacyValidation` // value in the `init()` function in your main.go or so, could be considered. // // Historically we opted for a global variable for feature gating different // validation schemes in operations that were not otherwise easily adjustable // (e.g. Labels yaml unmarshaling). That could have been a mistake, a separate // Labels structure or package might have been a better choice. Given the // change was made and many upgraded the common already, we live this as-is // with this warning and learning for the future. NameValidationScheme = UTF8Validation // NameEscapingScheme defines the default way that names will be escaped when // presented to systems that do not support UTF-8 names. If the Content-Type // "escaping" term is specified, that will override this value. // NameEscapingScheme should not be set to the NoEscaping value. That string // is used in content negotiation to indicate that a system supports UTF-8 and // has that feature enabled. NameEscapingScheme = UnderscoreEscaping )
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.
var MetricNameRE = regexp.MustCompile(`^[a-zA-Z_:][a-zA-Z0-9_:]*$`)
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.
var ZeroSample = Sample{Timestamp: Earliest}
ZeroSample is the pseudo zero-value of Sample used to signal a non-existing sample. It is a Sample with timestamp Earliest, value 0.0, and metric nil. Note that the natural zero value of Sample has a timestamp of 0, which is possible to appear in a real Sample and thus not suitable to signal a non-existing Sample.
var ZeroSamplePair = SamplePair{Timestamp: Earliest}
ZeroSamplePair is the pseudo zero-value of SamplePair used to signal a non-existing sample pair. It is a SamplePair with timestamp Earliest and value 0.0. Note that the natural zero value of SamplePair has a timestamp of 0, which is possible to appear in a real SamplePair and thus not suitable to signal a non-existing SamplePair.
Functions ¶
func EscapeMetricFamily ¶
func EscapeMetricFamily(v *dto.MetricFamily, scheme EscapingScheme) *dto.MetricFamily
EscapeMetricFamily escapes the given metric names and labels with the given escaping scheme. Returns a new object that uses the same pointers to fields when possible and creates new escaped versions so as not to mutate the input.
func EscapeName ¶
func EscapeName(name string, scheme EscapingScheme) string
EscapeName escapes the incoming name according to the provided escaping scheme. Depending on the rules of escaping, this may cause no change in the string that is returned. (Especially NoEscaping, which by definition is a noop). This function does not do any validation of the name.
func IsValidLegacyMetricName ¶
IsValidLegacyMetricName is similar to IsValidMetricName but always uses the legacy validation scheme regardless of the value of NameValidationScheme. This function, however, does not use MetricNameRE for the check but a much faster hardcoded implementation.
func IsValidMetricName ¶
func IsValidMetricName(n LabelValue) bool
IsValidMetricName returns true iff name matches the pattern of MetricNameRE for legacy names, and iff it's valid UTF-8 if the UTF8Validation scheme is selected.
func LabelsToSignature ¶
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 ¶
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 ¶
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.
func UnescapeName ¶
func UnescapeName(name string, scheme EscapingScheme) string
UnescapeName unescapes the incoming name according to the provided escaping scheme if possible. Some schemes are partially or totally non-roundtripable. If any error is enountered, returns the original input.
Types ¶
type Alert ¶
type Alert struct { // Label value pairs for purpose of aggregation, matching, and disposition // dispatching. This must minimally include an "alertname" label. Labels LabelSet `json:"labels"` // Extra key/value information which does not define alert identity. Annotations LabelSet `json:"annotations"` // The known time range for this alert. Both ends are optional. StartsAt time.Time `json:"startsAt,omitempty"` EndsAt time.Time `json:"endsAt,omitempty"` GeneratorURL string `json:"generatorURL"` }
Alert is a generic representation of an alert in the Prometheus eco-system.
func (*Alert) Fingerprint ¶
func (a *Alert) Fingerprint() Fingerprint
Fingerprint returns a unique hash for the alert. It is equivalent to the fingerprint of the alert's label set.
func (*Alert) Name ¶
Name returns the name of the alert. It is equivalent to the "alertname" label.
func (*Alert) Resolved ¶
Resolved returns true iff the activity interval ended in the past.
func (*Alert) ResolvedAt ¶
ResolvedAt returns true iff the activity interval ended before the given timestamp.
func (*Alert) Status ¶
func (a *Alert) Status() AlertStatus
Status returns the status of the alert.
func (*Alert) StatusAt ¶
func (a *Alert) StatusAt(ts time.Time) AlertStatus
StatusAt returns the status of the alert at the given timestamp.
func (*Alert) String ¶
func (*Alert) Validate ¶
Validate checks whether the alert data is inconsistent.
type AlertStatus ¶
type AlertStatus string
const ( AlertFiring AlertStatus = "firing" AlertResolved AlertStatus = "resolved" )
type Alerts ¶
type Alerts []*Alert
Alert is a list of alerts that can be sorted in chronological order.
func (Alerts) HasFiring ¶
HasFiring returns true iff one of the alerts is not resolved.
func (Alerts) HasFiringAt ¶
HasFiringAt returns true iff one of the alerts is not resolved at the time ts.
func (Alerts) Len ¶
func (Alerts) Less ¶
func (Alerts) Status ¶
func (as Alerts) Status() AlertStatus
Status returns StatusFiring iff at least one of the alerts is firing.
func (Alerts) StatusAt ¶
func (as Alerts) StatusAt(ts time.Time) AlertStatus
StatusAt returns StatusFiring iff at least one of the alerts is firing at the time ts.
func (Alerts) Swap ¶
type Duration ¶
Duration wraps time.Duration. It is used to parse the custom duration format from YAML. This type should not propagate beyond the scope of input/output processing.
func ParseDuration ¶
ParseDuration parses a string into a time.Duration, assuming that a year always has 365d, a week always has 7d, and a day always has 24h.
func (Duration) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (*Duration) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface.
func (Duration) MarshalYAML ¶
MarshalYAML implements the yaml.Marshaler interface.
func (*Duration) Set ¶
Set implements pflag/flag.Value
func (Duration) String ¶
func (*Duration) Type ¶
Type implements pflag.Value
func (*Duration) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.
func (*Duration) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface.
func (*Duration) UnmarshalYAML ¶
UnmarshalYAML implements the yaml.Unmarshaler interface.
type EscapingScheme ¶
type EscapingScheme int
const ( // NoEscaping indicates that a name will not be escaped. Unescaped names that // do not conform to the legacy validity check will use a new exposition // format syntax that will be officially standardized in future versions. NoEscaping EscapingScheme = iota // UnderscoreEscaping replaces all legacy-invalid characters with underscores. UnderscoreEscaping // DotsEscaping is similar to UnderscoreEscaping, except that dots are // converted to `_dot_` and pre-existing underscores are converted to `__`. DotsEscaping // ValueEncodingEscaping prepends the name with `U__` and replaces all invalid // characters with the unicode value, surrounded by underscores. Single // underscores are replaced with double underscores. ValueEncodingEscaping )
func ToEscapingScheme ¶
func ToEscapingScheme(s string) (EscapingScheme, error)
func (EscapingScheme) String ¶
func (e EscapingScheme) String() string
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 FloatString ¶
type FloatString float64
func (FloatString) MarshalJSON ¶
func (v FloatString) MarshalJSON() ([]byte, error)
func (FloatString) String ¶
func (v FloatString) String() string
func (*FloatString) UnmarshalJSON ¶
func (v *FloatString) UnmarshalJSON(b []byte) error
type HistogramBucket ¶
type HistogramBucket struct { Boundaries int32 Lower FloatString Upper FloatString Count FloatString }
func (*HistogramBucket) Equal ¶
func (s *HistogramBucket) Equal(o *HistogramBucket) bool
func (HistogramBucket) MarshalJSON ¶
func (s HistogramBucket) MarshalJSON() ([]byte, error)
func (HistogramBucket) String ¶
func (b HistogramBucket) String() string
func (*HistogramBucket) UnmarshalJSON ¶
func (s *HistogramBucket) UnmarshalJSON(buf []byte) error
type HistogramBuckets ¶
type HistogramBuckets []*HistogramBucket
func (HistogramBuckets) Equal ¶
func (s HistogramBuckets) Equal(o HistogramBuckets) bool
type Interval ¶
type Interval struct { Start, End Time }
Interval describes an interval between two timestamps.
type LabelName ¶
type LabelName string
A LabelName is a key for a LabelSet or Metric. It has a value associated therewith.
func (LabelName) IsValid ¶
IsValid returns true iff the name matches the pattern of LabelNameRE when NameValidationScheme is set to LegacyValidation, or valid UTF-8 if NameValidationScheme is set to UTF8Validation.
func (LabelName) IsValidLegacy ¶
IsValidLegacy returns true iff name matches the pattern of LabelNameRE for legacy names. It does not use LabelNameRE for the check but a much faster hardcoded implementation.
func (*LabelName) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.
func (*LabelName) UnmarshalYAML ¶
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 ¶
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 ¶
Clone returns a copy of the label set.
func (LabelSet) Equal ¶
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 ¶
Merge is a helper function to non-destructively merge two label sets.
func (LabelSet) String ¶
String will look like `{foo="bar", more="less"}`. Names are sorted alphabetically.
func (*LabelSet) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.
func (LabelSet) Validate ¶
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 UTF-8.
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 Matcher ¶
type Matcher struct { Name LabelName `json:"name"` Value string `json:"value"` IsRegex bool `json:"isRegex"` }
Matcher describes a matches the value of a given label.
func (*Matcher) UnmarshalJSON ¶
func (*Matcher) Validate ¶
Validate returns true iff all fields of the matcher have valid values.
type Matrix ¶
type Matrix []*SampleStream
Matrix is a list of time series.
func (Matrix) Len ¶
func (Matrix) Less ¶
func (Matrix) String ¶
func (Matrix) Swap ¶
func (Matrix) Type ¶
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 ¶
Before compares the metrics' underlying label sets.
func (Metric) Clone ¶
Clone returns a copy of the Metric.
func (Metric) Equal ¶
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 ¶
type MetricType ¶
type MetricType string
MetricType represents metric type values.
type Sample ¶
type Sample struct { Metric Metric `json:"metric"` Value SampleValue `json:"value"` Timestamp Time `json:"timestamp"` Histogram *SampleHistogram `json:"histogram"` }
Sample is a sample pair associated with a metric. A single sample must either define Value or Histogram but not both. Histogram == nil implies the Value field is used, otherwise it should be ignored.
func (*Sample) Equal ¶
Equal compares first the metrics, then the timestamp, then the value. The semantics of value equality is defined by SampleValue.Equal.
func (Sample) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (Sample) String ¶
func (*Sample) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
type SampleHistogram ¶
type SampleHistogram struct { Count FloatString `json:"count"` Sum FloatString `json:"sum"` Buckets HistogramBuckets `json:"buckets"` }
func (*SampleHistogram) Equal ¶
func (s *SampleHistogram) Equal(o *SampleHistogram) bool
func (SampleHistogram) String ¶
func (s SampleHistogram) String() string
type SampleHistogramPair ¶
type SampleHistogramPair struct { Timestamp Time // Histogram should never be nil, it's only stored as pointer for efficiency. Histogram *SampleHistogram }
func (*SampleHistogramPair) Equal ¶
func (s *SampleHistogramPair) Equal(o *SampleHistogramPair) bool
func (SampleHistogramPair) MarshalJSON ¶
func (s SampleHistogramPair) MarshalJSON() ([]byte, error)
func (SampleHistogramPair) String ¶
func (s SampleHistogramPair) String() string
func (*SampleHistogramPair) UnmarshalJSON ¶
func (s *SampleHistogramPair) UnmarshalJSON(buf []byte) error
type SamplePair ¶
type SamplePair struct { Timestamp Time Value SampleValue }
SamplePair pairs a SampleValue with a Timestamp.
func (*SamplePair) Equal ¶
func (s *SamplePair) Equal(o *SamplePair) bool
Equal returns true if this SamplePair and o have equal Values and equal Timestamps. The semantics of Value equality is defined by SampleValue.Equal.
func (SamplePair) MarshalJSON ¶
func (s SamplePair) MarshalJSON() ([]byte, error)
func (SamplePair) String ¶
func (s SamplePair) String() string
func (*SamplePair) UnmarshalJSON ¶
func (s *SamplePair) UnmarshalJSON(b []byte) error
UnmarshalJSON implements json.Unmarshaler.
type SampleStream ¶
type SampleStream struct { Metric Metric `json:"metric"` Values []SamplePair `json:"values"` Histograms []SampleHistogramPair `json:"histograms"` }
SampleStream is a stream of Values belonging to an attached COWMetric.
func (SampleStream) MarshalJSON ¶
func (ss SampleStream) MarshalJSON() ([]byte, error)
func (SampleStream) String ¶
func (ss SampleStream) String() string
func (*SampleStream) UnmarshalJSON ¶
func (ss *SampleStream) UnmarshalJSON(b []byte) error
type SampleValue ¶
type SampleValue float64
A SampleValue is a representation of a value for a given sample at a given time.
func (SampleValue) Equal ¶
func (v SampleValue) Equal(o SampleValue) bool
Equal returns true if the value of v and o is equal or if both are NaN. Note that v==o is false if both are NaN. If you want the conventional float behavior, use == to compare two SampleValues.
func (SampleValue) MarshalJSON ¶
func (v SampleValue) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler.
func (SampleValue) String ¶
func (v SampleValue) String() string
func (*SampleValue) UnmarshalJSON ¶
func (v *SampleValue) UnmarshalJSON(b []byte) error
UnmarshalJSON implements json.Unmarshaler.
type Samples ¶
type Samples []*Sample
Samples is a sortable Sample slice. It implements sort.Interface.
func (Samples) Equal ¶
Equal compares two sets of samples and returns true if they are equal.
func (Samples) Len ¶
func (Samples) Less ¶
Less compares first the metrics, then the timestamp.
func (Samples) Swap ¶
type Scalar ¶
type Scalar struct { Value SampleValue `json:"value"` Timestamp Time `json:"timestamp"` }
Scalar is a scalar value evaluated at the set timestamp.
func (Scalar) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (Scalar) String ¶
func (*Scalar) Type ¶
func (*Scalar) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
type Silence ¶
type Silence struct { ID uint64 `json:"id,omitempty"` Matchers []*Matcher `json:"matchers"` StartsAt time.Time `json:"startsAt"` EndsAt time.Time `json:"endsAt"` CreatedAt time.Time `json:"createdAt,omitempty"` CreatedBy string `json:"createdBy"` Comment string `json:"comment,omitempty"` }
Silence defines the representation of a silence definition in the Prometheus eco-system.
func (*Silence) Validate ¶
Validate returns true iff all fields of the silence have valid values.
type String ¶
String is a string value evaluated at the set timestamp.
func (String) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (*String) String ¶
func (*String) Type ¶
func (*String) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
type Time ¶
type Time int64
Time is the number of milliseconds since the epoch (1970-01-01 00:00 UTC) excluding leap seconds.
func Now ¶
func Now() Time
Now returns the current time as a Time.
func TimeFromUnix ¶
TimeFromUnix returns the Time equivalent to the Unix Time t provided in seconds.
func TimeFromUnixNano ¶
TimeFromUnixNano returns the Time equivalent to the Unix Time t provided in nanoseconds.
func (Time) Add ¶
Add returns the Time t + d.
func (Time) After ¶
After reports whether the Time t is after o.
func (Time) Before ¶
Before reports whether the Time t is before o.
func (Time) Equal ¶
Equal reports whether two Times represent the same instant.
func (Time) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (Time) String ¶
String returns a string representation of the Time.
func (Time) Sub ¶
Sub returns the Duration t - o.
func (Time) Time ¶
Time returns the time.Time representation of t.
func (Time) Unix ¶
Unix returns t as a Unix time, the number of seconds elapsed since January 1, 1970 UTC.
func (Time) UnixNano ¶
UnixNano returns t as a Unix time, the number of nanoseconds elapsed since January 1, 1970 UTC.
func (*Time) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.
type ValidationScheme ¶
type ValidationScheme int
ValidationScheme is a Go enum for determining how metric and label names will be validated by this library.
const ( // LegacyValidation is a setting that requires that all metric and label names // conform to the original Prometheus character requirements described by // MetricNameRE and LabelNameRE. LegacyValidation ValidationScheme = iota // UTF8Validation only requires that metric and label names be valid UTF-8 // strings. UTF8Validation )
type Value ¶
Value is a generic interface for values resulting from a query evaluation.
type ValueType ¶
type ValueType int
func (ValueType) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (ValueType) String ¶
func (*ValueType) UnmarshalJSON ¶
type Vector ¶
type Vector []*Sample
Vector is basically only an alias for Samples, but the contract is that in a Vector, all Samples have the same timestamp.
func (Vector) Equal ¶
Equal compares two sets of samples and returns true if they are equal.
func (Vector) Len ¶
func (Vector) Less ¶
Less compares first the metrics, then the timestamp.
func (Vector) String ¶
func (Vector) Swap ¶
func (Vector) Type ¶
Source Files ¶
alert.go fingerprinting.go fnv.go labels.go labelset.go labelset_string.go metadata.go metric.go model.go signature.go silence.go time.go value.go value_float.go value_histogram.go value_type.go
- Version
- v0.63.0 (latest)
- Published
- Mar 13, 2025
- Platform
- js/wasm
- Imports
- 14 packages
- Last checked
- 1 day ago –
Tools for package owners.