-
Notifications
You must be signed in to change notification settings - Fork 55
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
Initial follow up tasks for built-in bridge #2810
Initial follow up tasks for built-in bridge #2810
Conversation
@@ -341,6 +341,10 @@ impl CumulocityConverter { | |||
let ancestors_external_ids = | |||
self.entity_store.ancestors_external_ids(entity_topic_id)?; | |||
|
|||
if entity_topic_id.is_bridge_health_topic() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm very confused as to why I needed to make this change twice to actually get the bridge to not appear in c8y. Both converter.rs
and service_monitor.rs
appear to publish status messages for services, with converter.rs
doing it relatively cleanly, while service_monitor.rs
is publishing both down
& up
messages when a service starts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The purposes are different:
service_monitor.rs
is really about telling to c8y that a service is up or down.converter.rs
register the services in c8y before any message is sent about these services. They are initialized with an up status - but this is somehow unrelated.
Now that the status messages sent for the bridge are correctly parsed as for any other service, we have to explicitly add an exception to not register the bridge as a service.
Before your change the bridge status message were not correctly parsed leading to an error lost in the log with .context("Could not create service creation message")?;
.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files
|
Robot Results
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm okay with these changes except for the added timeout causing the mapper to start even if the bridge is not established.
&& (payload == MQTT_BRIDGE_UP_PAYLOAD | ||
|| payload == MQTT_BRIDGE_DOWN_PAYLOAD | ||
|| is_valid_status_payload(payload)) | ||
} | ||
Err(_err) => false, | ||
} | ||
} | ||
|
||
#[derive(serde::Deserialize)] | ||
struct HealthStatus<'a> { | ||
status: &'a str, | ||
} | ||
|
||
fn is_valid_status_payload(payload: &str) -> bool { | ||
serde_json::from_str::<HealthStatus>(payload) | ||
.map_or(false, |h| h.status == "up" || h.status == "down") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[minor] I would move into tedge_api
this logic to accept 0
| 1
| status = up
| status = down
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I'm removing the check for bridge health, then this more complicated logic isn't required, so unless we need it for some other reason you know of, I'll undo this change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checking that the bridge has been initialized before sending registration messages to c8y is required for a very new thin-edge device. If the c8y mapper starts before the bridge and even before the c8y.url is provided (as this is the case for a generic image of thin-edge), then the mapper must wait for the bridge to be initialized - otherwise all the registration messages are lost.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this logic is required - but can be simplified by simply checking that at least one message has been received on this topic - whatever the payload.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just saw 4ef0fcd and I'm okay with it.
log_if_bridge_not_detected.abort(); | ||
info!("Cumulocity bridge is established, mapper is starting"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having a background error printing task, that is aborted on the happy path, is more than unusual!
But that's not my main point.
I wonder, why introducing a timeout that was not present before?
Actually:
- with the mosquitto bridge, the c8y mapper must wait for the bridge to be established (up or down it doesn't matter) otherwise all the init messages sent on the
c8y/#
topics will be lost (as there is no persisted subscriber). - with the built-in bridge, the c8y mapper can directly send the init messages, since there is one subscriber to the
c8y/#
topics (the mapper itself).
To make things simple, I would only take care of the case where awaiting the bridge is required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The timeout doesn't change the behaviour of the waiting logic; it exists purely so the mapper can log that it's totally not functional because the bridge doesn't exist (and I couldn't think of a better way to notify than just "if nothing has happened after a certain amount of time, something is broken"). I didn't consider it too deeply as I was mostly concerned with "this bit of code that's critically breaking the mapper didn't tell me it existed" and that taking a while to debug. I agree that this isn't necessary though, and I should just skip it if c8y.bridge.built_in
is true
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't consider it too deeply as I was mostly concerned with "this bit of code that's critically breaking the mapper didn't tell me it existed" and that taking a while to debug.
That's true that some logging is required as the mapper is doing nothing this the bride is connected.
I should just skip it if
c8y.bridge.built_in
istrue
.
Yes, if this is actually simpler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just saw 4ef0fcd and I'm okay with it.
@@ -341,6 +341,10 @@ impl CumulocityConverter { | |||
let ancestors_external_ids = | |||
self.entity_store.ancestors_external_ids(entity_topic_id)?; | |||
|
|||
if entity_topic_id.is_bridge_health_topic() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The purposes are different:
service_monitor.rs
is really about telling to c8y that a service is up or down.converter.rs
register the services in c8y before any message is sent about these services. They are initialized with an up status - but this is somehow unrelated.
Now that the status messages sent for the bridge are correctly parsed as for any other service, we have to explicitly add an exception to not register the bridge as a service.
Before your change the bridge status message were not correctly parsed leading to an error lost in the log with .context("Could not create service creation message")?;
.
// 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") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR might be the opportunity to resolve this FIXME.
a10952c
to
4ef0fcd
Compare
c415dba
to
7c85bdc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved
a442e21
to
449ebb7
Compare
Signed-off-by: James Rhodes <[email protected]>
Signed-off-by: James Rhodes <[email protected]>
Signed-off-by: James Rhodes <[email protected]>
This allows `tedge cert create` to assign the correct certificate owner, allowing new devices to use the built-in bridge. Signed-off-by: James Rhodes <[email protected]>
Signed-off-by: James Rhodes <[email protected]>
449ebb7
to
2ada77d
Compare
Proposed changes
These are some of the changes discussed in #2794, specifically:
tedge connect c8y
so new devices connect successfullyTypes of changes
Paste Link to the issue
Checklist
cargo fmt
as mentioned in CODING_GUIDELINEScargo clippy
as mentioned in CODING_GUIDELINESFurther comments