Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(#2370): use bridge topic id in service_monitor #2837

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't assume this hardcoded device/main topic id even for the main device since we support overriding device_topic_id via the config. That being said, I'm not fully sure if all tedge components properly respect that config setting yet either. I'm fairly sure that it is still hardcoded in many places.


#[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 {
Comment on lines -31 to +32
Copy link
Contributor

@didier-wenzek didier-wenzek Apr 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this change, the az bridge is not reported as a service on c8y. This could make sense, but is this what we expect?

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