Skip to main content

Labels

Struct Labels 

Source
pub struct Labels { /* private fields */ }
Expand description

An immutable set of key-value label pairs.

Implementations§

Source§

impl Labels

Source

pub fn empty() -> Self

Source

pub fn of(key: impl Into<String>, value: impl Into<String>) -> Self

Source

pub fn with(&self, key: impl Into<String>, value: impl Into<String>) -> Self

Source

pub fn extend(&self, child: &Labels) -> Labels

Source

pub fn get(&self, key: &str) -> Option<&str>

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn iter(&self) -> impl Iterator<Item = (&str, &str)>

Source

pub fn to_prometheus(&self) -> String

Source

pub fn to_dotted(&self) -> String

Source

pub fn identity_hash(&self) -> u64

Content-defined identity hash for this label set.

Stability contract:

  • Order-independent — pairs are sorted by key before hashing, so Labels::of("a","1").with("b","2") and Labels::of("b","2").with("a","1") hash to the same value. Without this, two code paths that construct “the same” label set in different orders create two distinct metric_instance rows in the sqlite sink — a silent double-count on every aggregate query.
  • Uses FNV-1a 64 (defined inline). DefaultHasher (SipHasher13) is deterministic within a Rust version but the std docs explicitly reserve the right to change it — anything that writes a hash to durable storage needs a hasher that we own.
Source

pub fn sorted_pairs(&self) -> Vec<(&str, &str)>

Canonical sorted-by-key view of the pairs, borrowed. Used by reporters that need a stable serialised form (filename, db spec, etc.) so the on-disk identity matches identity_hash.

Source

pub fn to_canonical_spec(&self, metric_name: &str) -> String

Build the OpenMetrics-canonical sample identifier for this label set under the given metric family name — the text form used by Prometheus, OpenMetrics, and VictoriaMetrics for uniquely naming a time series.

Shape: metric_name{key="value",key="value"}

  • Labels are sorted by name (canonical: two label dicts that are equal as a mapping produce equal spec text).
  • __name__ is excluded from the labels block (the metric name is the prefix, per spec); other code paths still see __name__ as a regular label row in the database for query uniformity.
  • Empty label values are dropped (OpenMetrics spec §“Label”: “Empty label values SHOULD be treated as if the label was not present”).
  • Values are escaped per OpenMetrics §“Escaping”: \ → \\, " → \", \n → \n literal.

Trait Implementations§

Source§

impl Clone for Labels

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Labels

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Labels

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for Labels

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Labels

Source§

impl Hash for Labels

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Labels

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Labels

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.