Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
mquery
Manage
Activity
Members
Labels
Plan
Issues
1
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Subconscious Compute (Open)
mquery
Commits
1c76c52e
Commit
1c76c52e
authored
1 year ago
by
Maaz Ahmed
Browse files
Options
Downloads
Patches
Plain Diff
doc: update and add missing docs
parent
07d5d5e7
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/lib.rs
+21
-4
21 additions, 4 deletions
src/lib.rs
src/query/mod.rs
+8
-0
8 additions, 0 deletions
src/query/mod.rs
with
29 additions
and
4 deletions
src/lib.rs
+
21
−
4
View file @
1c76c52e
//! 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
{}
}
This diff is collapsed.
Click to expand it.
src/query/mod.rs
+
8
−
0
View file @
1c76c52e
//! 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
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment