From 98ccfe7c2541c99278e8957da9bbefe910559cac Mon Sep 17 00:00:00 2001 From: Marcel Guzik Date: Tue, 30 Apr 2024 10:56:37 +0000 Subject: [PATCH] fix(#2370): use bridge topic id in service_monitor Signed-off-by: Marcel Guzik --- crates/core/tedge_api/src/mqtt_topics.rs | 6 ------ crates/extensions/c8y_mapper_ext/src/converter.rs | 2 +- crates/extensions/c8y_mapper_ext/src/lib.rs | 2 ++ .../extensions/c8y_mapper_ext/src/service_monitor.rs | 11 ++++++++++- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/crates/core/tedge_api/src/mqtt_topics.rs b/crates/core/tedge_api/src/mqtt_topics.rs index 7aa7e0da20d..9c70c0a3e1f 100644 --- a/crates/core/tedge_api/src/mqtt_topics.rs +++ b/crates/core/tedge_api/src/mqtt_topics.rs @@ -390,12 +390,6 @@ impl EntityTopicId { pub fn as_str(&self) -> &str { self.0.as_str() } - - // FIXME: can also match "device/bridge//" or "/device/main/service/my_custom_bridge" - // should match ONLY the single mapper bridge - pub fn is_bridge_health_topic(&self) -> bool { - self.as_str().contains("bridge") - } } /// Contains a topic id of the service itself and the associated device. diff --git a/crates/extensions/c8y_mapper_ext/src/converter.rs b/crates/extensions/c8y_mapper_ext/src/converter.rs index b5747e07966..744d8935438 100644 --- a/crates/extensions/c8y_mapper_ext/src/converter.rs +++ b/crates/extensions/c8y_mapper_ext/src/converter.rs @@ -340,7 +340,7 @@ impl CumulocityConverter { let ancestors_external_ids = self.entity_store.ancestors_external_ids(entity_topic_id)?; - if entity_topic_id.is_bridge_health_topic() { + if entity_topic_id == crate::C8Y_BRIDGE_TOPIC_ID { return Ok(vec![]); } diff --git a/crates/extensions/c8y_mapper_ext/src/lib.rs b/crates/extensions/c8y_mapper_ext/src/lib.rs index ec9efba04c9..c66268da312 100644 --- a/crates/extensions/c8y_mapper_ext/src/lib.rs +++ b/crates/extensions/c8y_mapper_ext/src/lib.rs @@ -14,6 +14,8 @@ pub mod service_monitor; #[cfg(test)] mod tests; +pub(crate) const C8Y_BRIDGE_TOPIC_ID: &str = "device/main/service/mosquitto-c8y-bridge"; + #[derive(Debug, serde::Deserialize)] pub struct Capabilities { log_upload: bool, diff --git a/crates/extensions/c8y_mapper_ext/src/service_monitor.rs b/crates/extensions/c8y_mapper_ext/src/service_monitor.rs index 1a035943ac9..3bfce7ffaa9 100644 --- a/crates/extensions/c8y_mapper_ext/src/service_monitor.rs +++ b/crates/extensions/c8y_mapper_ext/src/service_monitor.rs @@ -28,7 +28,8 @@ pub fn convert_health_status_message( return vec![]; } - if entity.topic_id.is_bridge_health_topic() { + // the bridge itself is not registered as a service, only the mapper + if entity.topic_id == crate::C8Y_BRIDGE_TOPIC_ID { return vec![]; } @@ -128,6 +129,14 @@ mod tests { r#"102,test_device:device:main:service:tedge-mapper-c8y,service,tedge-mapper-c8y,"up""down""#; "service-monitoring-double-quotes-health-message" )] + #[test_case( + "test_device", + "te/device/main/service/my-bridge/status/health", + r#"{"pid":"1234","status":"up"}"#, + "c8y/s/us", + r#"102,test_device:device:main:service:my-bridge,service,my-bridge,up"#; + "service-monitoring-service-with-bridge-in-name" + )] fn translate_health_status_to_c8y_service_monitoring_message( device_name: &str, health_topic: &str,