Struct promql::Vector

source ·
pub struct Vector {
    pub labels: Vec<LabelMatch>,
    pub range: Option<f32>,
    pub offset: Option<f32>,
}
Expand description

This struct represents both instant and range vectors.

Note that there’s no field for metric name: not only it is optional (as in {instance="localhost", job="foo"}), metric names can actually be matched using special label called __name__ (e.g. {__name__=~"megaexporter_.+"}), so it only makes sense to parse label names into the corresponding label filter, like so:

use promql::*;
use promql::LabelMatchOp::*; // Eq
use nom::IResult;

assert_eq!(
	parse("foo{bar='baz'}".as_bytes(), &Default::default()),
	Ok(Node::Vector(Vector {
		labels: vec![
			// this is the filter for the metric name 'foo'
			LabelMatch { name: "__name__".to_string(), op: Eq, value: b"foo".to_vec(), },
			// here go all the other filters
			LabelMatch { name: "bar".to_string(),      op: Eq, value: b"baz".to_vec(), },
		],
		range: None, offset: None,
	}))
);

Fields§

§labels: Vec<LabelMatch>

Set of label filters

§range: Option<f32>

Range for range vectors, in seconds, e.g. Some(300.) for [5m]

§offset: Option<f32>

Offset in seconds, e.g. Some(3600.) for offset 1h

Trait Implementations§

source§

impl Debug for Vector

source§

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

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

impl PartialEq for Vector

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl StructuralPartialEq for Vector

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<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, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.