mirror of
https://git.alemi.dev/dashboard.git
synced 2024-11-14 19:59:18 +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 ActiveModelBehavior for ActiveModel {}
|
||||||
|
|
||||||
impl Model {
|
impl Model {
|
||||||
pub fn extract(&self, value: &serde_json::Value) -> Result<PlotPoint, FetchError> {
|
pub fn extract(&self, value: &serde_json::Value) -> Result<Option<f64>, FetchError> {
|
||||||
let x = Utc::now().timestamp() as f64;
|
Ok(jql::walker(value, self.query.as_str())?.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 })
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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);
|
error!(target: "surveyor", "[{}] Failed setting last_update ({:?}) for source {:?} but successfully fetched '{}', aborting", index, e, source_clone, res);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
let now = Utc::now().timestamp() as f64;
|
||||||
for metric in metrics_snapshot.iter().filter(|x| source_clone.id == x.source_id) {
|
for metric in metrics_snapshot.iter().filter(|x| source_clone.id == x.source_id) {
|
||||||
match metric.extract(&res) {
|
match metric.extract(&res) {
|
||||||
Ok(v) => {
|
// note that Err and None mean different things: Err for broken queries, None for
|
||||||
if let Err(e) = entities::points::Entity::insert(
|
// missing values. Only first one is reported
|
||||||
entities::points::ActiveModel {
|
Ok(value) => {
|
||||||
id: NotSet, metric_id: Set(metric.id), x: Set(v.x), y: Set(v.y),
|
if let Some(v) = value {
|
||||||
}).exec(&db_clone).await {
|
if let Err(e) = entities::points::Entity::insert(
|
||||||
error!(target: "surveyor", "[{}] Could not insert record {:?} : {:?}", index, v, e);
|
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),
|
Err(e) => error!(target: "surveyor", "[{}] Failed extracting '{}' from {}: {:?}", index, metric.name, source_clone.name, e),
|
||||||
|
|
Loading…
Reference in a new issue