-
Notifications
You must be signed in to change notification settings - Fork 54
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
tedge-mapper-c8y sync with tedge-agent #2050
tedge-mapper-c8y sync with tedge-agent #2050
Conversation
Codecov Report
Additional details and impacted files
|
// Send the init messages | ||
if !self.tedge_agent_status && check_tedge_agent_status(&message) { | ||
self.tedge_agent_status = true; | ||
self.create_tedge_agent_supported_ops().await?; | ||
self.send_out_sw_list_request_to_agent().await?; | ||
} | ||
|
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.
As I had expressed earlier, I still feel that this code better belongs in the converter
for the following reasons, which I couldn't convey better in the other PR:
- All the other MQTT messages are already handled there. So it'd be better to keep everything at one place so that it's easier to mange.
- Since there's already a
process_health_status_message
function in the converter, this block would have been a better fit there, than here. - That
converter
already has code to handle the software list and stuff like that as well. So, you could reuse quite a lot of that directly from there than introducing newer functions likesend_out_sw_list_request_to_agent
here that callsself.converter.get_software_list_message()
anyway. - Not to corrupt the actor further with state fields like
ops_dir
andtedge_agent_status
fields as these are just details. Even for theops_dir
, it could be read from theC8yMapperConfig
that's already passed toCumulocityConverter::new()
.
So, I'd still strongly recommend that we keep the actor clean, just with the message routing logic and push all the message processing details into the converter.
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.
Sure, moved the code into the converter.
const TEDGE_HEALTH_UP_PAYLOAD: &str = r#""status":"up""#; | ||
const TEDGE_HEALTH_DOWN_PAYLOAD: &str = r#""status":"down""#; | ||
|
||
pub fn check_tedge_agent_status(message: &Message) -> bool { |
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] Not sure if this logic really deserved a module of its own. Could have been just a function in the converter
.
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.
moved this also into converter
payload.contains(TEDGE_HEALTH_UP_PAYLOAD) | ||
|| payload.contains(TEDGE_HEALTH_DOWN_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.
If the point is to make sure that the payload parses well as well, why not just parse it using serde into a struct similar to HealthStatus
as done in service_monitor.rs
? This payload check is a bit fragile as even the addition of an extra space between the key and value would break it.
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.
done
...tFramework/tests/cumulocity/supported_operations/mapper-publishing-agent-supported-ops.robot
Show resolved
Hide resolved
@@ -50,6 +51,8 @@ pub struct C8yMapperActor { | |||
messages: SimpleMessageBox<C8yMapperInput, C8yMapperOutput>, | |||
mqtt_publisher: LoggingSender<MqttMessage>, | |||
timer_sender: LoggingSender<SyncStart>, | |||
ops_dir: PathBuf, | |||
tedge_agent_status: bool, |
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 understand that you added this flag to prevent the mapper from repeatedly sending the software list request to the agent every time its status changes. But, may be it's a good thing. What if the agent restarted with a new set of sm-plugins loaded. In that case, it might be better to send the software list request to the agent every time it says it's "up".
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.
You mean send the software list
request only when the status is up
?
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.
Yeah, send the software list request every time we receive an up
status. Then, we don't even need this flag.
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.
But the plan was to send if tedge-agent
is up at least once. i.e up/down any message on health
topic.
pub pid: Option<u64>, | ||
pub status: Option<String>, |
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.
Why Option
? A health status should definitely have both these fields, right?
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.
These topics are open, anything can be published. So, to be safer, if there is no status in the health message then it will not fail.
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.
Yeah there is the possibility of anyone publishing anything on that topic. But, as the mapper, it should only parse the well-formed health status messages with a valid pid
and status
fields. Any other malformed messages should just be ignored, without crashing the mapper.
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.
Yes, right. I did make it String.
Agent gets the software list request once it comes up | ||
Execute Command sudo systemctl stop tedge-agent | ||
# wait till health status down | ||
Should Have MQTT Messages tedge/health/tedge-agent |
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 don't know if this API behaviour changed recently, but earlier this was checking the MQTT message trace right from the point where the device started up and will check for a message with the given topic anywhere in that trace. But, here I believe you wanted to check if the health status was generated after the tedge-agent
was shutdown. For that, you need to pass the date_from
parameter as well. You need to pass the message_contains
or message_pattern
args as well to make sure that the status value is 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.
Added timestamp
to check the specific
messages.
Should Have MQTT Messages tedge/health/tedge-agent | ||
# now there should be a new list request | ||
Should Have MQTT Messages tedge/commands/req/software/list | ||
# agent must process the list request and send response | ||
Should Have MQTT Messages tedge/commands/res/software/list |
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.
Same comment as above, regarding the usage of date_from
and message_contains
parameters.
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.
Refactored to add the timestamp and check for the specific message
Robot Results
Passed Tests
|
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.
Besides my comments, I really agree with Albin's comments (where I put 👍 )
# wait till list request is pushed out | ||
Should Have MQTT Messages tedge/commands/req/software/list | ||
# stop mapper and remove the supported operations | ||
Execute Command sudo systemctl stop tedge-mapper-c8y |
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.
You can use Stop Service
key instead of Execute Command
. (Also for restart, start, ...)
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.
Yes, done.
# wait till list request is pushed out | ||
Should Have MQTT Messages tedge/commands/req/software/list |
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.
Why do you need this step?
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.
Refactored. I was thinking just to make sure the list
command is issued upon starting tedge-mapper-c8y
. Now its moved to the second test and not required here anymore. This one tests the creation of operation files and publishing of operations.
ThinEdgeIO.start Service tedge-mapper-c8y | ||
Should Have MQTT Messages tedge/health/tedge-mapper-c8y message_contains=up date_from=${timestamp} | ||
# After receiving the health status `up` from tege-agent, the mapper creates supported operations and will publish to c8y | ||
Should Have MQTT Messages tedge/health/tedge-agent message_contains=up |
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.
Should Have MQTT Messages tedge/health/tedge-agent message_contains=up | |
Should Have MQTT Messages tedge/health/tedge-agent message_contains=up date_from=${timestamp} |
Signed-off-by: Pradeep Kumar K J <pkj@softwareag.com>
445387e
to
ccdfa9b
Compare
Proposed changes
Problem:
When the
tedge-mapper-c8y
starts, it will publish thetedge-agent
supported operation to c8y and also sends asoftware list
request totedge-agent
. If thetedge-agent
is not up, then thesoftware list request
will be lost.Proposed solution:
tedge-agent
status (either up or down)c8y_SoftwareUpdate
&c8y_Restart
supported operations filesAdded an integration test as well
Types of changes
Paste Link to the issue
#1201
#1731
Checklist
cargo fmt
as mentioned in CODING_GUIDELINEScargo clippy
as mentioned in CODING_GUIDELINESFurther comments