Skip to content
Snippets Groups Projects
Commit 1c76c52e authored by Maaz Ahmed's avatar Maaz Ahmed
Browse files

doc: update and add missing docs

parent 07d5d5e7
No related branches found
No related tags found
No related merge requests found
//! A wrapper around prometheus_http_query with additional features for ease of use
//!
//! All HTTP requests are made using the `reqwest` client
#![doc = include_str!("../README.md")]
pub mod query;
......@@ -55,13 +53,18 @@ impl QueryManager {
self
}
/// Set HTTP method to use to send queries to the server
/// Set HTTP method to use to send queries to the server (default: `Get`)
pub fn method(&mut self, method: Method) -> &mut Self {
self.method = method;
self
}
/// Send a query to the Prometheus server and retreived deserialized data
///
/// This method accepts any type that implements the `IntoQuery` trait.
/// The trait is implemented for `&str`, `String`, `&String`, and __mquery's__
/// internal types such as [`query::Metric`], [`query::Scalar`] and others that result
/// from the query builder API.
pub async fn query<Q: IntoQuery>(&self, query: Q) -> Result<PromqlResult, Error> {
let mut builder = self.client.query(query.into_query().as_ref());
if let Some((name, val)) = self.auth.get_header() {
......@@ -77,6 +80,11 @@ impl QueryManager {
}
/// Send a ranged query to the Prometheus server and retreived deserialized data
///
/// This method accepts any type that implements the `IntoQuery` trait.
/// The trait is implemented for `&str`, `String`, `&String`, and __mquery's__
/// internal types such as [`query::Metric`], [`query::Scalar`] and others that result
/// from the query builder API.
pub async fn query_range<Q: IntoQuery>(
&self,
query: Q,
......@@ -101,6 +109,9 @@ impl QueryManager {
}
// TODO: Add support for basic auth as well
/// Authentication method
///
/// Used in [`QueryManager::auth`] to set the authentication type
#[derive(Default, Clone, Debug)]
pub enum Auth {
#[default]
......@@ -125,6 +136,10 @@ impl Auth {
}
}
/// HTTP method to use to send queries
///
/// This is used by the [`QueryManager::method`] method to set the HTTP
/// method used to send queries to the server.
#[derive(Clone, Copy, Debug, Default)]
pub enum Method {
#[default]
......@@ -132,6 +147,8 @@ pub enum Method {
Post,
}
// Private trait used to seal other traits to disallow users from implementing
// them directly
pub(crate) mod seal {
pub(crate) trait Sealed {}
}
//! The query builder API
//!
//! [`Metric`] and [`Scalar`] are the basic types used for building queries.
//! For building complex queries involving operators, see module [`ops`].
use std::fmt::Display;
use crate::seal::Sealed;
......@@ -50,6 +55,9 @@ pub struct Metric<'a> {
impl<'a> Metric<'a> {
/// Create a new metric with a metric name (for example `total_http_requests`)
///
/// A metric can be constructed with an empty string as well, however, it's important to
/// have at least one label matcher present for the query to be valid.
pub fn new(name: &'a str) -> Self {
Self {
name,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment