Skip to content

Commit

Permalink
fix(#2370): use bridge topic id in service_monitor
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Guzik <[email protected]>
  • Loading branch information
Bravo555 committed Apr 30, 2024
1 parent 0ac3e7e commit 98ccfe7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
6 changes: 0 additions & 6 deletions crates/core/tedge_api/src/mqtt_topics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion crates/extensions/c8y_mapper_ext/src/converter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![]);
}

Expand Down
2 changes: 2 additions & 0 deletions crates/extensions/c8y_mapper_ext/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 10 additions & 1 deletion crates/extensions/c8y_mapper_ext/src/service_monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![];
}

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 98ccfe7

Please sign in to comment.