pub struct LabelMatcher {
pub name: String,
pub match_type: MatchType,
pub value: String,
}Expand description
A label matcher: name <op> value.
The fields are public so a caller can build one in a struct literal; the
constructors are shorthand. matches compiles a regex on every call, so a
loop over many values should go through
IndexReader::postings_for_matchers, which compiles once.
Fields§
§name: StringLabel name to test. An empty name with an empty value is the “all series” key.
match_type: MatchTypeComparison to apply.
value: StringValue (or regular expression) to compare against.
Implementations§
Source§impl LabelMatcher
impl LabelMatcher
Sourcepub fn new(
name: impl Into<String>,
match_type: MatchType,
value: impl Into<String>,
) -> Self
pub fn new( name: impl Into<String>, match_type: MatchType, value: impl Into<String>, ) -> Self
Builds a matcher from its parts.
Sourcepub fn is_all_postings_key(&self) -> bool
pub fn is_all_postings_key(&self) -> bool
True for the “all series” matcher ({""=""}, the empty key).
Sourcepub fn inverted(&self) -> LabelMatcher
pub fn inverted(&self) -> LabelMatcher
The matcher with the opposite match type, same name and value.
Used by the planner to reuse the positive/inverse postings paths.
Sourcepub fn matches(&self, value: &str) -> Result<bool>
pub fn matches(&self, value: &str) -> Result<bool>
Tests one label value.
A missing label must be passed as "", which is how Prometheus models
absence. Returns an error for a regex matcher whose expression does not
compile, or when the crate is built without the regex feature.
Sourcepub fn matches_empty(&self) -> Result<bool>
pub fn matches_empty(&self) -> Result<bool>
Tests the empty string: “would this matcher select a series that does not have the label?”.