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