Struct prometheus_http_query::InstantVector[][src]

pub struct InstantVector(pub String);
Expand description

An instant vector expression that can be further operated on with functions/aggregations or passed to a crate::Client in order to evaluate.

Tuple Fields

0: String

Implementations

Add one instant vector to another. Additional modifiers (Match and Group) can be used to alter the matching behaviour between two instant vectors. See the Prometheus reference for details on this topic.

use prometheus_http_query::{Selector, InstantVector, Match, Error};
use std::convert::TryInto;

fn main() -> Result<(), Error> {
    let one: InstantVector = Selector::new()
        .metric("some_metric")?
        .with("some_label", "some_value")
        .try_into()?;

    let two: InstantVector = Selector::new()
        .metric("other_metric")?
        .with("some_label", "some_value")
        .with("other_label", "other_value")
        .try_into()?;

    let new = one.add(two, Some(Match::On(&["some_label"])), None);

    // This would ultimately be the query string posted to the HTTP API.
    let expected = r#"some_metric{some_label="some_value"} + on (some_label) other_metric{some_label="some_value",other_label="other_value"}"#;

    assert_eq!(new.to_string(), expected.to_string());

    Ok(())
}

Subtract one instant vector from another. Additional modifiers (Match and Group) can be used to alter the matching behaviour between two instant vectors. See the Prometheus reference for details on this topic.

use prometheus_http_query::{Selector, InstantVector, Match, Error};
use std::convert::TryInto;

fn main() -> Result<(), Error> {
     let one: InstantVector = Selector::new()
        .metric("some_metric")?
        .with("some_label", "some_value")
        .try_into()?;

    let two: InstantVector = Selector::new()
        .metric("other_metric")?
        .with("some_label", "some_value")
        .with("other_label", "other_value")
        .try_into()?;

    let new = one.subtract(two, Some(Match::Ignoring(&["other_label"])), None);

    // This would ultimately be the query string posted to the HTTP API.
    let expected = r#"some_metric{some_label="some_value"} - ignoring (other_label) other_metric{some_label="some_value",other_label="other_value"}"#;

    assert_eq!(new.to_string(), expected.to_string());

    Ok(())
}

Multiply one instant vector by another. Additional modifiers (Match and Group) can be used to alter the matching behaviour between two instant vectors. See the Prometheus reference for details on this topic.

use prometheus_http_query::{Selector, InstantVector, Match, Error};
use std::convert::TryInto;

fn main() -> Result<(), Error> {
    let one: InstantVector = Selector::new()
        .metric("some_metric")?
        .with("some_label", "some_value")
        .try_into()?;

    let two: InstantVector = Selector::new()
        .metric("other_metric")?
        .with("some_label", "some_value")
        .with("other_label", "other_value")
        .try_into()?;

    let new = one.multiply(two, Some(Match::On(&["some_label"])), None);

    // This would ultimately be the query string posted to the HTTP API.
    let expected = r#"some_metric{some_label="some_value"} * on (some_label) other_metric{some_label="some_value",other_label="other_value"}"#;

    assert_eq!(new.to_string(), expected.to_string());

    Ok(())
}

Divide one instant vector by another. Additional modifiers (Match and Group) can be used to alter the matching behaviour between two instant vectors. See the Prometheus reference for details on this topic.

use prometheus_http_query::{Selector, InstantVector, Match, Error};
use std::convert::TryInto;

fn main() -> Result<(), Error> {
    let one: InstantVector = Selector::new()
        .metric("some_metric")?
        .with("some_label", "some_value")
        .try_into()?;

    let two: InstantVector = Selector::new()
        .metric("other_metric")?
        .with("some_label", "some_value")
        .with("other_label", "other_value")
        .try_into()?;

    let new = one.divide(two, Some(Match::Ignoring(&["other_label"])), None);

    // This would ultimately be the query string posted to the HTTP API.
    let expected = r#"some_metric{some_label="some_value"} / ignoring (other_label) other_metric{some_label="some_value",other_label="other_value"}"#;

    assert_eq!(new.to_string(), expected.to_string());

    Ok(())
}

Divide one instant vector by another with remainder. Additional modifiers (Match and Group) can be used to alter the matching behaviour between two instant vectors. See the Prometheus reference for details on this topic.

use prometheus_http_query::{Selector, InstantVector, Match, Error};
use std::convert::TryInto;

fn main() -> Result<(), Error> {
    let one: InstantVector = Selector::new()
        .metric("some_metric")?
        .with("some_label", "some_value")
        .try_into()?;

    let two: InstantVector = Selector::new()
        .metric("other_metric")?
        .with("some_label", "some_value")
        .with("other_label", "other_value")
        .try_into()?;

    let new = one.modulo(two, Some(Match::Ignoring(&["other_label"])), None);

    // This would ultimately be the query string posted to the HTTP API.
    let expected = r#"some_metric{some_label="some_value"} % ignoring (other_label) other_metric{some_label="some_value",other_label="other_value"}"#;

    assert_eq!(new.to_string(), expected.to_string());

    Ok(())
}

Exponentiate one instant vector by another. Additional modifiers (Match and Group) can be used to alter the matching behaviour between two instant vectors. See the Prometheus reference for details on this topic.

use prometheus_http_query::{Selector, InstantVector, Match, Error};
use std::convert::TryInto;

fn main() -> Result<(), Error> {
    let one: InstantVector = Selector::new()
        .metric("some_metric")?
        .with("some_label", "some_value")
        .try_into()?;

    let two: InstantVector = Selector::new()
        .metric("other_metric")?
        .with("some_label", "some_value")
        .with("other_label", "other_value")
        .try_into()?;

    let new = one.power(two, Some(Match::Ignoring(&["other_label"])), None);

    // This would ultimately be the query string posted to the HTTP API.
    let expected = r#"some_metric{some_label="some_value"} ^ ignoring (other_label) other_metric{some_label="some_value",other_label="other_value"}"#;

    assert_eq!(new.to_string(), expected);

    Ok(())
}

Intersect two vectors so that the result vector consists of all elements of vector1 for which there are matching elements in vector2. See the Prometheus reference for details on this topic.

use prometheus_http_query::{Selector, InstantVector, Error};
use std::convert::TryInto;

fn main() -> Result<(), Error> {
    let one: InstantVector = Selector::new()
        .metric("some_metric")?
        .with("some_label", "some_value")
        .try_into()?;

    let two: InstantVector = Selector::new()
        .metric("other_metric")?
        .with("some_label", "some_value")
        .with("other_label", "other_value")
        .try_into()?;

    let new = one.and(two);

    // This would ultimately be the query string posted to the HTTP API.
    let expected = r#"some_metric{some_label="some_value"} and other_metric{some_label="some_value",other_label="other_value"}"#;

    assert_eq!(new.to_string(), expected.to_string());

    Ok(())
}

Combine two vectors so that the result vector consists of all elements of vector1 and also all elements of vector2 which do not have matching label sets in vector1. See the Prometheus reference for details on this topic.

use prometheus_http_query::{Selector, InstantVector, Error};
use std::convert::TryInto;

fn main() -> Result<(), Error> {
    let one: InstantVector = Selector::new()
        .metric("some_metric")?
        .with("some_label", "some_value")
        .try_into()?;

    let two: InstantVector = Selector::new()
        .metric("other_metric")?
        .with("some_label", "some_value")
        .with("other_label", "other_value")
        .try_into()?;

    let new = one.or(two);

    // This would ultimately be the query string posted to the HTTP API.
    let expected = r#"some_metric{some_label="some_value"} or other_metric{some_label="some_value",other_label="other_value"}"#;

    assert_eq!(new.to_string(), expected.to_string());

    Ok(())
}

Combine two vectors so that the result vector consists only of those elements of vector1 for which there are no matching elements in vector2. See the Prometheus reference for details on this topic.

use prometheus_http_query::{Selector, InstantVector, Error};
use std::convert::TryInto;

fn main() -> Result<(), Error> {
    let one: InstantVector = Selector::new()
        .metric("some_metric")?
        .with("some_label", "some_value")
        .try_into()?;

    let two: InstantVector = Selector::new()
        .metric("other_metric")?
        .with("some_label", "some_value")
        .with("other_label", "other_value")
        .try_into()?;

    let new = one.unless(two);

    // This would ultimately be the query string posted to the HTTP API.
    let expected = r#"some_metric{some_label="some_value"} unless other_metric{some_label="some_value",other_label="other_value"}"#;

    assert_eq!(new.to_string(), expected.to_string());

    Ok(())
}

Apply the == operator to two vectors. Optionally set the bool parameter to modify the query result as per the PromQL documentation. See the Prometheus reference for details on comparison binary operators.

use prometheus_http_query::Selector;
use prometheus_http_query::InstantVector;
use std::convert::TryInto;

fn main() -> Result<(), prometheus_http_query::Error> {
    let one: InstantVector = Selector::new()
        .metric("some_metric")?
        .with("some_label", "some_value")
        .try_into()?;

    let two: InstantVector = Selector::new()
        .metric("other_metric")?
        .with("some_label", "some_value")
        .with("other_label", "other_value")
        .try_into()?;

    let new = one.eq_vector(two, false);

    // This would ultimately be the query string posted to the HTTP API.
    let expected = r#"some_metric{some_label="some_value"} == other_metric{some_label="some_value",other_label="other_value"}"#;

    assert_eq!(new.to_string(), expected.to_string());

    Ok(())
}

Apply the != operator to two vectors. Optionally set the bool parameter to modify the query result as per the PromQL documentation. See the Prometheus reference for details on comparison binary operators.

use prometheus_http_query::Selector;
use prometheus_http_query::InstantVector;
use std::convert::TryInto;

fn main() -> Result<(), prometheus_http_query::Error> {
    let one: InstantVector = Selector::new()
        .metric("some_metric")?
        .with("some_label", "some_value")
        .try_into()?;

    let two: InstantVector = Selector::new()
        .metric("other_metric")?
        .with("some_label", "some_value")
        .with("other_label", "other_value")
        .try_into()?;

    let new = one.ne_vector(two, true);

    // This would ultimately be the query string posted to the HTTP API.
    let expected = r#"some_metric{some_label="some_value"} != bool other_metric{some_label="some_value",other_label="other_value"}"#;

    assert_eq!(new.to_string(), expected.to_string());

    Ok(())
}

Apply the > operator to two vectors. Optionally set the bool parameter to modify the query result as per the PromQL documentation. See the Prometheus reference for details on comparison binary operators.

use prometheus_http_query::Selector;
use prometheus_http_query::InstantVector;
use std::convert::TryInto;

fn main() -> Result<(), prometheus_http_query::Error> {
    let one: InstantVector = Selector::new()
        .metric("some_metric")?
        .with("some_label", "some_value")
        .try_into()?;

    let two: InstantVector = Selector::new()
        .metric("other_metric")?
        .with("some_label", "some_value")
        .with("other_label", "other_value")
        .try_into()?;

    let new = one.gt_vector(two, false);

    // This would ultimately be the query string posted to the HTTP API.
    let expected = r#"some_metric{some_label="some_value"} > other_metric{some_label="some_value",other_label="other_value"}"#;

    assert_eq!(new.to_string(), expected.to_string());

    Ok(())
}

Apply the < operator to two vectors. Optionally set the bool parameter to modify the query result as per the PromQL documentation. See the Prometheus reference for details on comparison binary operators.

use prometheus_http_query::Selector;
use prometheus_http_query::InstantVector;
use std::convert::TryInto;

fn main() -> Result<(), prometheus_http_query::Error> {
    let one: InstantVector = Selector::new()
        .metric("some_metric")?
        .with("some_label", "some_value")
        .try_into()?;

    let two: InstantVector = Selector::new()
        .metric("other_metric")?
        .with("some_label", "some_value")
        .with("other_label", "other_value")
        .try_into()?;

    let new = one.lt_vector(two, false);

    // This would ultimately be the query string posted to the HTTP API.
    let expected = r#"some_metric{some_label="some_value"} < other_metric{some_label="some_value",other_label="other_value"}"#;

    assert_eq!(new.to_string(), expected.to_string());

    Ok(())
}

Apply the >= operator to two vectors. Optionally set the bool parameter to modify the query result as per the PromQL documentation. See the Prometheus reference for details on comparison binary operators.

use prometheus_http_query::Selector;
use prometheus_http_query::InstantVector;
use std::convert::TryInto;

fn main() -> Result<(), prometheus_http_query::Error> {
    let one: InstantVector = Selector::new()
        .metric("some_metric")?
        .with("some_label", "some_value")
        .try_into()?;

    let two: InstantVector = Selector::new()
        .metric("other_metric")?
        .with("some_label", "some_value")
        .with("other_label", "other_value")
        .try_into()?;

    let new = one.ge_vector(two, false);

    // This would ultimately be the query string posted to the HTTP API.
    let expected = r#"some_metric{some_label="some_value"} >= other_metric{some_label="some_value",other_label="other_value"}"#;

    assert_eq!(new.to_string(), expected.to_string());

    Ok(())
}

Apply the <= operator to two vectors. Optionally set the bool parameter to modify the query result as per the PromQL documentation. See the Prometheus reference for details on comparison binary operators.

use prometheus_http_query::Selector;
use prometheus_http_query::InstantVector;
use std::convert::TryInto;

fn main() -> Result<(), prometheus_http_query::Error> {
    let one: InstantVector = Selector::new()
        .metric("some_metric")?
        .with("some_label", "some_value")
        .try_into()?;

    let two: InstantVector = Selector::new()
        .metric("other_metric")?
        .with("some_label", "some_value")
        .with("other_label", "other_value")
        .try_into()?;

    let new = one.le_vector(two, false);

    // This would ultimately be the query string posted to the HTTP API.
    let expected = r#"some_metric{some_label="some_value"} <= other_metric{some_label="some_value",other_label="other_value"}"#;

    assert_eq!(new.to_string(), expected.to_string());

    Ok(())
}

Apply the == operator to a vector and a scalar. Optionally set the bool parameter to modify the query result as per the PromQL documentation. See the Prometheus reference for details on comparison binary operators.

use prometheus_http_query::Selector;
use prometheus_http_query::InstantVector;
use std::convert::TryInto;

fn main() -> Result<(), prometheus_http_query::Error> {
    let one: InstantVector = Selector::new()
        .metric("some_metric")?
        .with("some_label", "some_value")
        .try_into()?;

    let new = one.eq_scalar(8.5, true);

    // This would ultimately be the query string posted to the HTTP API.
    let expected = r#"some_metric{some_label="some_value"} == bool 8.5"#;

    assert_eq!(new.to_string(), expected.to_string());

    Ok(())
}

Apply the != operator to a vector and a scalar. Optionally set the bool parameter to modify the query result as per the PromQL documentation. See the Prometheus reference for details on comparison binary operators.

use prometheus_http_query::Selector;
use prometheus_http_query::InstantVector;
use std::convert::TryInto;

fn main() -> Result<(), prometheus_http_query::Error> {
    let one: InstantVector = Selector::new()
        .metric("some_metric")?
        .with("some_label", "some_value")
        .try_into()?;

    let new = one.ne_scalar(8.5, true);

    // This would ultimately be the query string posted to the HTTP API.
    let expected = r#"some_metric{some_label="some_value"} != bool 8.5"#;

    assert_eq!(new.to_string(), expected.to_string());

    Ok(())
}

Apply the > operator to a vector and a scalar. Optionally set the bool parameter to modify the query result as per the PromQL documentation. See the Prometheus reference for details on comparison binary operators.

use prometheus_http_query::Selector;
use prometheus_http_query::InstantVector;
use std::convert::TryInto;

fn main() -> Result<(), prometheus_http_query::Error> {
    let one: InstantVector = Selector::new()
        .metric("some_metric")?
        .with("some_label", "some_value")
        .try_into()?;

    let new = one.gt_scalar(8.5, false);

    // This would ultimately be the query string posted to the HTTP API.
    let expected = r#"some_metric{some_label="some_value"} > 8.5"#;

    assert_eq!(new.to_string(), expected.to_string());

    Ok(())
}

Apply the < operator to a vector and a scalar. Optionally set the bool parameter to modify the query result as per the PromQL documentation. See the Prometheus reference for details on comparison binary operators.

use prometheus_http_query::Selector;
use prometheus_http_query::InstantVector;
use std::convert::TryInto;

fn main() -> Result<(), prometheus_http_query::Error> {
    let one: InstantVector = Selector::new()
        .metric("some_metric")?
        .with("some_label", "some_value")
        .try_into()?;

    let new = one.lt_scalar(8.5, false);

    // This would ultimately be the query string posted to the HTTP API.
    let expected = r#"some_metric{some_label="some_value"} < 8.5"#;

    assert_eq!(new.to_string(), expected.to_string());

    Ok(())
}

Apply the >= operator to a vector and a scalar. Optionally set the bool parameter to modify the query result as per the PromQL documentation. See the Prometheus reference for details on comparison binary operators.

use prometheus_http_query::Selector;
use prometheus_http_query::InstantVector;
use std::convert::TryInto;

fn main() -> Result<(), prometheus_http_query::Error> {
    let one: InstantVector = Selector::new()
        .metric("some_metric")?
        .with("some_label", "some_value")
        .try_into()?;

    let new = one.ge_scalar(8.5, false);

    // This would ultimately be the query string posted to the HTTP API.
    let expected = r#"some_metric{some_label="some_value"} >= 8.5"#;

    assert_eq!(new.to_string(), expected.to_string());

    Ok(())
}

Apply the <= operator to a vector and a scalar. Optionally set the bool parameter to modify the query result as per the PromQL documentation. See the Prometheus reference for details on comparison binary operators.

use prometheus_http_query::Selector;
use prometheus_http_query::InstantVector;
use std::convert::TryInto;

fn main() -> Result<(), prometheus_http_query::Error> {
    let one: InstantVector = Selector::new()
        .metric("some_metric")?
        .with("some_label", "some_value")
        .try_into()?;

    let new = one.le_scalar(8.5, false);

    // This would ultimately be the query string posted to the HTTP API.
    let expected = r#"some_metric{some_label="some_value"} <= 8.5"#;

    assert_eq!(new.to_string(), expected.to_string());

    Ok(())
}

Trait Implementations

Add a scalar value to every data sample in a vector.

use prometheus_http_query::{Selector, InstantVector, Error};
use std::convert::TryInto;

fn main() -> Result<(), Error> {
    let v: InstantVector = Selector::new()
        .metric("some_metric")?
        .with("some_label", "some_value")
        .try_into()?;

    let v = v + 4.0;

    assert_eq!(v.to_string(), String::from("some_metric{some_label=\"some_value\"} + 4"));

    Ok(())
}

The resulting type after applying the + operator.

Exponentiate each data sample in a vector by a scalar value.

use prometheus_http_query::{Selector, InstantVector, Error};
use std::convert::TryInto;

fn main() -> Result<(), Error> {
    let v: InstantVector = Selector::new()
        .metric("some_metric")?
        .with("some_label", "some_value")
        .try_into()?;

    let v = v ^ 2.0;

    assert_eq!(v.to_string(), String::from("some_metric{some_label=\"some_value\"} ^ 2"));

    Ok(())
}

The resulting type after applying the ^ operator.

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Divide each data sample in a vector by a scalar value.

use prometheus_http_query::{Selector, InstantVector, Error};
use std::convert::TryInto;

fn main() -> Result<(), Error> {
    let v: InstantVector = Selector::new()
        .metric("some_metric")?
        .with("some_label", "some_value")
        .try_into()?;

    let v = v / 2.0;

    assert_eq!(v.to_string(), String::from("some_metric{some_label=\"some_value\"} / 2"));

    Ok(())
}

The resulting type after applying the / operator.

Multiply each data sample in a vector by a scalar value.

use prometheus_http_query::{Selector, InstantVector, Error};
use std::convert::TryInto;

fn main() -> Result<(), Error> {
    let v: InstantVector = Selector::new()
        .metric("some_metric")?
        .with("some_label", "some_value")
        .try_into()?;

    let v = v * 2.0;

    assert_eq!(v.to_string(), String::from("some_metric{some_label=\"some_value\"} * 2"));

    Ok(())
}

The resulting type after applying the * operator.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Divide each data sample in a vector by a scalar value with remainder.

use prometheus_http_query::{Selector, InstantVector, Error};
use std::convert::TryInto;

fn main() -> Result<(), Error> {
    let v: InstantVector = Selector::new()
        .metric("some_metric")?
        .with("some_label", "some_value")
        .try_into()?;

    let v = v % 2.0;

    assert_eq!(v.to_string(), String::from("some_metric{some_label=\"some_value\"} % 2"));

    Ok(())
}

The resulting type after applying the % operator.

Subtract a scalar value from every data sample in a vector.

use prometheus_http_query::{Selector, InstantVector, Error};
use std::convert::TryInto;

fn main() -> Result<(), Error> {
    let v: InstantVector = Selector::new()
        .metric("some_metric")?
        .with("some_label", "some_value")
        .try_into()?;

    let v = v - 4.5;

    assert_eq!(v.to_string(), String::from("some_metric{some_label=\"some_value\"} - 4.5"));

    Ok(())
}

The resulting type after applying the - operator.

Convert a Selector to an InstantVector.

use prometheus_http_query::{Selector, InstantVector, Error};
use std::convert::TryInto;

fn main() -> Result<(), Error> {
    let v: Result<InstantVector, Error> = Selector::new()
        .metric("some_metric")?
        .try_into();

    assert!(v.is_ok());

    Ok(())
}

The type returned in the event of a conversion error.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more