summaryrefslogtreecommitdiffstats
path: root/crates/core/tedge_mapper/src
diff options
context:
space:
mode:
authorAlbin Suresh <albin.suresh@softwareag.com>2022-05-27 16:59:53 +0530
committerAlbin Suresh <albin.suresh@softwareag.com>2022-05-27 16:59:53 +0530
commita10c6c119899a8a9b36884e4e93e3f6bd873d793 (patch)
tree40bfb9f047545b7a4ece09e05f6cba2dab41bb35 /crates/core/tedge_mapper/src
parente3775e430d3109081d3926ab4e7b13b05e1c2741 (diff)
Fix watchdog health check with timestamp validation
Diffstat (limited to 'crates/core/tedge_mapper/src')
-rw-r--r--crates/core/tedge_mapper/src/collectd/monitor.rs4
-rw-r--r--crates/core/tedge_mapper/src/core/mapper.rs7
2 files changed, 8 insertions, 3 deletions
diff --git a/crates/core/tedge_mapper/src/collectd/monitor.rs b/crates/core/tedge_mapper/src/collectd/monitor.rs
index f927f887..61de30a5 100644
--- a/crates/core/tedge_mapper/src/collectd/monitor.rs
+++ b/crates/core/tedge_mapper/src/collectd/monitor.rs
@@ -3,6 +3,7 @@ use std::process;
use batcher::{BatchConfigBuilder, BatchDriver, BatchDriverInput, BatchDriverOutput, Batcher};
use mqtt_channel::{Connection, Message, QoS, SinkExt, StreamExt, Topic, TopicFilter};
use serde_json::json;
+use time::OffsetDateTime;
use tracing::{error, info, instrument};
use super::{batcher::MessageBatch, collectd::CollectdMessage, error::DeviceMonitorError};
@@ -109,7 +110,8 @@ impl DeviceMonitor {
if health_check_topics.accept(&message) {
let health_status = json!({
"status": "up",
- "pid": process::id()
+ "pid": process::id(),
+ "time": OffsetDateTime::now_utc().unix_timestamp()
})
.to_string();
let health_message = Message::new(&health_status_topic, health_status);
diff --git a/crates/core/tedge_mapper/src/core/mapper.rs b/crates/core/tedge_mapper/src/core/mapper.rs
index 9309a31e..58a212a1 100644
--- a/crates/core/tedge_mapper/src/core/mapper.rs
+++ b/crates/core/tedge_mapper/src/core/mapper.rs
@@ -7,6 +7,7 @@ use mqtt_channel::{
UnboundedSender,
};
use serde_json::json;
+use time::OffsetDateTime;
use tracing::{error, info, instrument};
const SYNC_WINDOW: Duration = Duration::from_secs(3);
@@ -133,7 +134,8 @@ impl Mapper {
if self.health_check_topics.accept(&message) {
let health_status = json!({
"status": "up",
- "pid": process::id()
+ "pid": process::id(),
+ "time": OffsetDateTime::now_utc().unix_timestamp()
})
.to_string();
let health_message = Message::new(&self.health_status_topic, health_status);
@@ -242,7 +244,7 @@ mod tests {
let common_health_check_topic = "tedge/health-check";
let health_status = broker
.wait_for_response_on_publish(
- &common_health_check_topic,
+ common_health_check_topic,
"",
&health_topic,
Duration::from_secs(1),
@@ -252,6 +254,7 @@ mod tests {
let health_status: Value = serde_json::from_str(health_status.as_str())?;
assert_json_include!(actual: &health_status, expected: json!({"status": "up"}));
assert!(health_status["pid"].is_number());
+ assert!(health_status["time"].is_number());
Ok(())
}