pub struct Labels { /* private fields */ }Expand description
An immutable set of key-value label pairs.
Implementations§
Source§impl Labels
impl Labels
pub fn empty() -> Self
pub fn of(key: impl Into<String>, value: impl Into<String>) -> Self
pub fn with(&self, key: impl Into<String>, value: impl Into<String>) -> Self
pub fn extend(&self, child: &Labels) -> Labels
pub fn get(&self, key: &str) -> Option<&str>
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn iter(&self) -> impl Iterator<Item = (&str, &str)>
pub fn to_prometheus(&self) -> String
pub fn to_dotted(&self) -> String
Sourcepub fn identity_hash(&self) -> u64
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")andLabels::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 distinctmetric_instancerows 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.
Sourcepub fn sorted_pairs(&self) -> Vec<(&str, &str)>
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.
Sourcepub fn to_canonical_spec(&self, metric_name: &str) -> String
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→\nliteral.
Trait Implementations§
impl Eq for Labels
impl StructuralPartialEq for Labels
Auto Trait Implementations§
impl Freeze for Labels
impl RefUnwindSafe for Labels
impl Send for Labels
impl Sync for Labels
impl Unpin for Labels
impl UnsafeUnpin for Labels
impl UnwindSafe for Labels
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.