mirror of
https://codeberg.org/icewind/prometheus-edge-detector.git
synced 2026-06-03 17:34:06 +02:00
0.3.0
This commit is contained in:
parent
a6e23761a9
commit
6de6e7dc3a
3 changed files with 23 additions and 17 deletions
|
|
@ -1,11 +1,12 @@
|
|||
[package]
|
||||
name = "prometheus-edge-detector"
|
||||
version = "0.2.0"
|
||||
version = "0.3.0"
|
||||
authors = ["Robin Appelman <robin@icewind.nl>"]
|
||||
edition = "2018"
|
||||
description = "Find the most recent rising or dropping edge from a prometheus query"
|
||||
license = "MIT OR Apache-2.0"
|
||||
repository = "https://github.com/icewind1991/prometheus-edge-detector"
|
||||
rust-version = "1.63.0"
|
||||
|
||||
[dependencies]
|
||||
tokio = { version = "1.36", features = ["time"] }
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
};
|
||||
in rec {
|
||||
devShells.default = pkgs.mkShell {
|
||||
nativeBuildInputs = with pkgs; [cargo rustc clippy bacon cargo-edit cargo-msrv pkg-config openssl];
|
||||
nativeBuildInputs = with pkgs; [cargo rustc clippy bacon cargo-edit cargo-semver-checks pkg-config openssl];
|
||||
};
|
||||
});
|
||||
}
|
||||
|
|
|
|||
33
src/lib.rs
33
src/lib.rs
|
|
@ -6,6 +6,7 @@ use std::time::SystemTime;
|
|||
use tokio::time::Duration;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
#[non_exhaustive]
|
||||
pub enum Error {
|
||||
#[error("Network error: {0}")]
|
||||
Network(reqwest::Error),
|
||||
|
|
@ -13,21 +14,25 @@ pub enum Error {
|
|||
MalformedResponse(reqwest::Error),
|
||||
#[error("Data point is not an integer: {0}")]
|
||||
NonNumericDataPoint(String),
|
||||
#[error("Prometheus returned an error for the query")]
|
||||
PrometheusError
|
||||
#[error("Prometheus returned a {error_type} error for the query: {error}")]
|
||||
PrometheusError{
|
||||
error_type: String,
|
||||
error: String,
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
#[serde(tag = "status")]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum QueryResultStatus {
|
||||
Success,
|
||||
Error,
|
||||
enum QueryResult {
|
||||
Success {
|
||||
data: QueryResultData
|
||||
},
|
||||
Error {
|
||||
#[serde(rename = "errorType")]
|
||||
error_type: String,
|
||||
error: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
struct QueryResult {
|
||||
status: QueryResultStatus,
|
||||
data: QueryResultData,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
|
|
@ -36,7 +41,7 @@ enum QueryResultDataType {
|
|||
Matrix,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
#[derive(Debug, Clone, Deserialize, Default)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct QueryResultData {
|
||||
result: Vec<QueryResultDataResult>,
|
||||
|
|
@ -73,9 +78,9 @@ async fn query_prometheus(
|
|||
.await
|
||||
.map_err(Error::MalformedResponse)?;
|
||||
|
||||
match result.status {
|
||||
QueryResultStatus::Success => Ok(result.data),
|
||||
QueryResultStatus::Error => Err(Error::PrometheusError),
|
||||
match result {
|
||||
QueryResult::Success{data} => Ok(data),
|
||||
QueryResult::Error {error, error_type} => Err(Error::PrometheusError{error_type, error}),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue