mirror of
https://git.alemi.dev/dashboard.git
synced 2024-11-22 07:24:52 +01:00
fix: surveyor now distinguishes nulls from errors
This commit is contained in:
parent
35f1675a00
commit
b2eb097585
2 changed files with 13 additions and 12 deletions
|
@ -52,12 +52,8 @@ impl Related<super::panels::Entity> for Entity {
|
|||
impl ActiveModelBehavior for ActiveModel {}
|
||||
|
||||
impl Model {
|
||||
pub fn extract(&self, value: &serde_json::Value) -> Result<PlotPoint, FetchError> {
|
||||
let x = Utc::now().timestamp() as f64;
|
||||
let y = jql::walker(value, self.query.as_str())?
|
||||
.as_f64()
|
||||
.ok_or(FetchError::JQLError("query result is null".to_string()))?;
|
||||
Ok(PlotPoint { x, y })
|
||||
pub fn extract(&self, value: &serde_json::Value) -> Result<Option<f64>, FetchError> {
|
||||
Ok(jql::walker(value, self.query.as_str())?.as_f64())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -74,14 +74,19 @@ pub async fn surveyor_loop(
|
|||
error!(target: "surveyor", "[{}] Failed setting last_update ({:?}) for source {:?} but successfully fetched '{}', aborting", index, e, source_clone, res);
|
||||
return;
|
||||
}
|
||||
let now = Utc::now().timestamp() as f64;
|
||||
for metric in metrics_snapshot.iter().filter(|x| source_clone.id == x.source_id) {
|
||||
match metric.extract(&res) {
|
||||
Ok(v) => {
|
||||
if let Err(e) = entities::points::Entity::insert(
|
||||
entities::points::ActiveModel {
|
||||
id: NotSet, metric_id: Set(metric.id), x: Set(v.x), y: Set(v.y),
|
||||
}).exec(&db_clone).await {
|
||||
error!(target: "surveyor", "[{}] Could not insert record {:?} : {:?}", index, v, e);
|
||||
// note that Err and None mean different things: Err for broken queries, None for
|
||||
// missing values. Only first one is reported
|
||||
Ok(value) => {
|
||||
if let Some(v) = value {
|
||||
if let Err(e) = entities::points::Entity::insert(
|
||||
entities::points::ActiveModel {
|
||||
id: NotSet, metric_id: Set(metric.id), x: Set(now), y: Set(v),
|
||||
}).exec(&db_clone).await {
|
||||
error!(target: "surveyor", "[{}] Could not insert record ({},{}) : {:?}", index, now, v, e);
|
||||
}
|
||||
}
|
||||
},
|
||||
Err(e) => error!(target: "surveyor", "[{}] Failed extracting '{}' from {}: {:?}", index, metric.name, source_clone.name, e),
|
||||
|
|
Loading…
Reference in a new issue