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

Combine message box receivers #1738

Merged
merged 2 commits into from
Mar 6, 2023

Conversation

jmshark
Copy link
Contributor

@jmshark jmshark commented Feb 20, 2023

Proposed changes

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Improvement (general improvements like code refactoring that doesn't explicitly fix a bug or add any new functionality)
  • Documentation Update (if none of the other choices apply)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Paste Link to the issue


Checklist

  • I have read the CONTRIBUTING doc
  • I have signed the CLA (in all commits with git commit -s)
  • I ran cargo fmt as mentioned in CODING_GUIDELINES
  • I used cargo clippy as mentioned in CODING_GUIDELINES
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Further comments

Copy link
Contributor

@didier-wenzek didier-wenzek left a comment

Choose a reason for hiding this comment

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

This is going in the direction I was expecting.

crates/core/tedge_actors/src/message_boxes.rs Outdated Show resolved Hide resolved
crates/core/tedge_actors/src/message_boxes.rs Outdated Show resolved Hide resolved
crates/core/tedge_actors/src/message_boxes.rs Outdated Show resolved Hide resolved
// TODO: rename
#[async_trait]
trait Foo<Input> {
async fn a(&mut self) -> Result<Option<Input>, RuntimeRequest>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
async fn a(&mut self) -> Result<Option<Input>, RuntimeRequest>;
async fn try_recv(&mut self) -> Result<Option<WrappedInput>, ChannelError>;

Else how will we propagate any channel specific errors? For those actors not wanting to handle the RuntimeRequest, the c variant is already there. So, I don't see any issues in this being wrapped.

Copy link
Contributor Author

@jmshark jmshark Feb 22, 2023

Choose a reason for hiding this comment

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

The point of this fn is the ergonomics of handling the RuntimeRequests as err. So I think Result<_, Either<ChannelError, RuntimeRequest> might be better.

CombineReceiver never produces Channel errors so I guess there's some message box impl where this would be useful, could you point me to an example where this would be useful?

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay I just noticed that the recv method does not return any ChannelError but only an Option. It was only send that returns ChannelError. I guess any errors while recving from a channel is implicitly mapped into Option:None instead of returning that error. So, this signature is fine.

crates/core/tedge_actors/src/message_boxes.rs Outdated Show resolved Hide resolved
crates/core/tedge_actors/src/message_boxes.rs Show resolved Hide resolved
@jmshark jmshark force-pushed the impr/combine-mailbox-receiver branch 2 times, most recently from 7acabfc to 25cfaf1 Compare February 28, 2023 00:06
@jmshark jmshark temporarily deployed to Test Pull Request February 28, 2023 00:13 — with GitHub Actions Inactive
@github-actions
Copy link
Contributor

github-actions bot commented Feb 28, 2023

Robot Results

✅ Passed ❌ Failed ⏭️ Skipped Total Pass %
140 0 5 140 100

Passed Tests

Name ⏱️ Duration Suite
Define Child device 1 ID 0.008 s C8Y Child Alarms Rpi
Normal case when the child device does not exist on c8y cloud 4.9 s C8Y Child Alarms Rpi
Normal case when the child device already exists 1.017 s C8Y Child Alarms Rpi
Reconciliation when the new alarm message arrives, restart the mapper 1.455 s C8Y Child Alarms Rpi
Reconciliation when the alarm that is cleared 5.452 s C8Y Child Alarms Rpi
Prerequisite Parent 17.756 s Child Conf Mgmt Plugin
Prerequisite Child 0.402 s Child Conf Mgmt Plugin
Child device bootstrapping 14.275 s Child Conf Mgmt Plugin
Snapshot from device 21.916 s Child Conf Mgmt Plugin
Child device config update 19.022 s Child Conf Mgmt Plugin
Configuration types should be detected on file change (without restarting service) 45.316 s Inotify Crate
Child devices support sending simple measurements 48.133 s Child Device Telemetry
Child devices support sending custom measurements 43.818 s Child Device Telemetry
Child devices support sending custom events 37.086 s Child Device Telemetry
Child devices support sending custom events overriding the type 31.343 s Child Device Telemetry
Child devices support sending custom alarms #1699 33.247 s Child Device Telemetry
Child devices support sending inventory data via c8y topic 23.78 s Child Device Telemetry
Main device support sending inventory data via c8y topic 24.849 s Child Device Telemetry
Successful firmware operation 61.319 s Firmware Operation
Install with empty firmware name 48.517 s Firmware Operation
Supports restarting the device 75.267 s Restart Device
Update tedge version from previous using Cumulocity 44.404 s Tedge Self Update
Successful shell command with output 4.497 s Shell Operation
Check Successful shell command with literal double quotes output 3.742 s Shell Operation
Execute multiline shell command 3.479 s Shell Operation
Failed shell command 3.489 s Shell Operation
Software list should be populated during startup 50.328 s Software
Install software via Cumulocity 60.047 s Software
Software list should only show currently installed software and not candidates 36.359 s Software
Stop tedge-agent service 0.256 s Log Path Config
Customize the log path 0.086 s Log Path Config
Initialize tedge-agent 0.168 s Log Path Config
Check created folders 0.074 s Log Path Config
Remove created custom folders 0.099 s Log Path Config
Install latest via script (from current branch) 31.647 s Install Tedge
Install specific version via script (from current branch) 23.183 s Install Tedge
Install latest tedge via script (from main branch) 20.229 s Install Tedge
Support starting and stopping services 37.8 s Service-Control
Supports a reconnect 43.621 s Test-Commands
Supports disconnect then connect 44.508 s Test-Commands
Update unknown setting 27.22 s Test-Commands
Update known setting 22.9 s Test-Commands
Stop c8y-configuration-plugin 0.145 s Health C8Y-Configuration-Plugin
Update the service file 0.122 s Health C8Y-Configuration-Plugin
Reload systemd files 0.512 s Health C8Y-Configuration-Plugin
Start c8y-configuration-plugin 0.155 s Health C8Y-Configuration-Plugin
Start watchdog service 10.211 s Health C8Y-Configuration-Plugin
Check PID of c8y-configuration-plugin 0.173 s Health C8Y-Configuration-Plugin
Kill the PID 0.127 s Health C8Y-Configuration-Plugin
Recheck PID of c8y-configuration-plugin 2.23 s Health C8Y-Configuration-Plugin
Compare PID change 0.018 s Health C8Y-Configuration-Plugin
Stop watchdog service 0.182 s Health C8Y-Configuration-Plugin
Remove entry from service file 0.085 s Health C8Y-Configuration-Plugin
Stop c8y-log-plugin 0.275 s Health C8Y-Log-Plugin
Update the service file 0.224 s Health C8Y-Log-Plugin
Reload systemd files 0.773 s Health C8Y-Log-Plugin
Start c8y-log-plugin 0.23 s Health C8Y-Log-Plugin
Start watchdog service 10.377 s Health C8Y-Log-Plugin
Check PID of c8y-log-plugin 0.068 s Health C8Y-Log-Plugin
Kill the PID 0.072 s Health C8Y-Log-Plugin
Recheck PID of c8y-log-plugin 2.107 s Health C8Y-Log-Plugin
Compare PID change 0 s Health C8Y-Log-Plugin
Stop watchdog service 0.058 s Health C8Y-Log-Plugin
Remove entry from service file 0.056 s Health C8Y-Log-Plugin
Stop tedge-mapper 0.211 s Health Tedge Mapper C8Y
Update the service file 0.294 s Health Tedge Mapper C8Y
Reload systemd files 1.043 s Health Tedge Mapper C8Y
Start tedge-mapper 0.227 s Health Tedge Mapper C8Y
Start watchdog service 10.347 s Health Tedge Mapper C8Y
Check PID of tedge-mapper 0.057 s Health Tedge Mapper C8Y
Kill the PID 0.058 s Health Tedge Mapper C8Y
Recheck PID of tedge-mapper 2.122 s Health Tedge Mapper C8Y
Compare PID change 0.001 s Health Tedge Mapper C8Y
Stop watchdog service 0.062 s Health Tedge Mapper C8Y
Remove entry from service file 0.054 s Health Tedge Mapper C8Y
Stop tedge-agent 0.3 s Health Tedge-Agent
Update the service file 0.148 s Health Tedge-Agent
Reload systemd files 0.289 s Health Tedge-Agent
Start tedge-agent 0.118 s Health Tedge-Agent
Start watchdog service 10.201 s Health Tedge-Agent
Check PID of tedge-mapper 0.088 s Health Tedge-Agent
Kill the PID 0.11 s Health Tedge-Agent
Recheck PID of tedge-agent 2.259 s Health Tedge-Agent
Compare PID change 0 s Health Tedge-Agent
Stop watchdog service 0.184 s Health Tedge-Agent
Remove entry from service file 0.185 s Health Tedge-Agent
Stop tedge-mapper-az 0.165 s Health Tedge-Mapper-Az
Update the service file 0.16 s Health Tedge-Mapper-Az
Reload systemd files 0.645 s Health Tedge-Mapper-Az
Start tedge-mapper-az 0.173 s Health Tedge-Mapper-Az
Start watchdog service 10.18 s Health Tedge-Mapper-Az
Check PID of tedge-mapper-az 0.064 s Health Tedge-Mapper-Az
Kill the PID 0.101 s Health Tedge-Mapper-Az
Recheck PID of tedge-agent 2.185 s Health Tedge-Mapper-Az
Compare PID change 0.001 s Health Tedge-Mapper-Az
Stop watchdog service 0.148 s Health Tedge-Mapper-Az
Remove entry from service file 0.096 s Health Tedge-Mapper-Az
Stop tedge-mapper-collectd 0.2 s Health Tedge-Mapper-Collectd
Update the service file 0.119 s Health Tedge-Mapper-Collectd
Reload systemd files 0.648 s Health Tedge-Mapper-Collectd
Start tedge-mapper-collectd 0.235 s Health Tedge-Mapper-Collectd
Start watchdog service 10.205 s Health Tedge-Mapper-Collectd
Check PID of tedge-mapper-collectd 0.061 s Health Tedge-Mapper-Collectd
Kill the PID 0.088 s Health Tedge-Mapper-Collectd
Recheck PID of tedge-mapper-collectd 2.161 s Health Tedge-Mapper-Collectd
Compare PID change 0.001 s Health Tedge-Mapper-Collectd
Stop watchdog service 0.188 s Health Tedge-Mapper-Collectd
Remove entry from service file 0.188 s Health Tedge-Mapper-Collectd
c8y-log-plugin health status 5.428 s MQTT health endpoints
c8y-configuration-plugin health status 5.702 s MQTT health endpoints
Wrong package name 0.101 s Improve Tedge Apt Plugin Error Messages
Wrong version 0.118 s Improve Tedge Apt Plugin Error Messages
Wrong type 0.291 s Improve Tedge Apt Plugin Error Messages
tedge_connect_test_positive 0.474 s Tedge Connect Test
tedge_connect_test_negative 0.556 s Tedge Connect Test
tedge_connect_test_sm_services 7.932 s Tedge Connect Test
tedge_disconnect_test_sm_services 0.818 s Tedge Connect Test
Install thin-edge.io 11.282 s Call Tedge
call tedge -V 0.104 s Call Tedge
call tedge -h 0.068 s Call Tedge
call tedge -h -V 0.123 s Call Tedge
call tedge help 0.08 s Call Tedge
tedge config list 0.106 s Call Tedge Config List
tedge config list --all 0.1 s Call Tedge Config List
set/unset device.type 0.615 s Call Tedge Config List
set/unset device.key.path 0.719 s Call Tedge Config List
set/unset device.cert.path 0.548 s Call Tedge Config List
set/unset c8y.root.cert.path 0.479 s Call Tedge Config List
set/unset c8y.smartrest.templates 0.367 s Call Tedge Config List
set/unset az.root.cert.path 0.378 s Call Tedge Config List
set/unset az.mapper.timestamp 0.35 s Call Tedge Config List
set/unset mqtt.bind_address 0.269 s Call Tedge Config List
set/unset mqtt.port 0.359 s Call Tedge Config List
set/unset tmp.path 0.384 s Call Tedge Config List
set/unset logs.path 0.237 s Call Tedge Config List
set/unset run.path 0.251 s Call Tedge Config List
Get Put Delete 3.605 s Http File Transfer Api
Set keys should return value on stdout 0.066 s Tedge Config Get
Unset keys should not return anything on stdout and warnings on stderr 0.129 s Tedge Config Get
Invalid keys should not return anything on stdout and warnings on stderr 0.129 s Tedge Config Get

crates/core/tedge_actors/src/message_boxes.rs Show resolved Hide resolved
crates/core/tedge_actors/src/message_boxes.rs Show resolved Hide resolved
Comment on lines 190 to 191
// TODO: Should be removed
pub async fn recv(&mut self) -> Option<Input> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not remove it now as we have impl<I,O> ReceiveMessages<I> for SimpleMessageBox<I,O>


pub struct CombinedReceiver<Input> {
name: String,
logging_is_on: bool,
Copy link
Contributor

Choose a reason for hiding this comment

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

For logging, we need to go away from this logging_is_on stuff. This has been done in a hurry - my bad.

With this new trait ReceiveMessage it will nicer to have LoggingReceiver that owns an inner receiver and logs the messages.

Comment on lines 304 to 305
self.logging_is_on = on;
self.receiver.logging_is_on = on;
Copy link
Contributor

Choose a reason for hiding this comment

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

I see no point to have this twice. This has to be refactor anyway.

Comment on lines 420 to 435
#[async_trait]
impl ReceiveMessages<ConfigInput> for ConfigManagerMessageBox {
async fn try_recv(&mut self) -> Result<Option<ConfigInput>, RuntimeRequest> {
self.input_receiver.try_recv().await
}

async fn recv_message(&mut self) -> Option<WrappedInput<ConfigInput>> {
self.input_receiver.recv_message().await
}

async fn recv(&mut self) -> Option<ConfigInput> {
self.input_receiver.recv().await
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Having to repeat ourselves, here, is a sign that this actor should use a SimpleMessageBox.

Signed-off-by: Sharkey <james.sharkey@softwareag.com>
@jmshark jmshark force-pushed the impr/combine-mailbox-receiver branch from c85302a to d55f262 Compare March 6, 2023 11:38
@jmshark jmshark temporarily deployed to Test Pull Request March 6, 2023 11:45 — with GitHub Actions Inactive
Copy link
Contributor

@didier-wenzek didier-wenzek left a comment

Choose a reason for hiding this comment

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

Approved - with some minor remarks and follow up tasks.

Comment on lines -131 to -132
// FIXME: If I add the RuntimeRequests here and if the channel we use to send messages is dropped then we will get an ChannelError::SendError
// FIXME: but I don't think we shouldn't return this error if the message box has a shutdown message for us
Copy link
Contributor

Choose a reason for hiding this comment

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

I would not bother too much for that. Definitely not for this example, but even for most actors. That said, handling correct termination during shutdown can be tricky when some actor expect other peers to say up a bit longer.

crates/core/tedge_actors/src/message_boxes.rs Show resolved Hide resolved
crates/core/tedge_actors/src/message_boxes.rs Show resolved Hide resolved

/// Returns [Some] message the next time a message is received. Returns [None] if
/// both of the underlying channels are closed.
/// Returning [RuntimeRequest] takes priority over messages.
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment has to be updated as currently returning None on RuntimeRequest.


async fn recv(&mut self) -> Option<Input> {
self.input_receiver.recv().await.map(|message| {
self.log_input(&message);
Copy link
Contributor

Choose a reason for hiding this comment

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

Okay for now - as this keeps the current behavior.

However, as a follow up PR, we will need to log whatever the recv method. The simpler will be to use a LoggingReceiver which wraps a CombinedReceiver, implements ReceiveMessages and logs received messages.

Comment on lines +44 to +46
let (publish_sender, publish_receiver) = channel(10);
let (signal_sender, signal_receiver) = channel(10);
let input_receiver = CombinedReceiver::new(publish_receiver, signal_receiver);
Copy link
Contributor

Choose a reason for hiding this comment

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

An improvement could be to add a CombinedSender type along a chanel() that create a sender, receiver pair.

This combined sender will have to impl RuntimeRequestSink to ease the implementation of specific actor builders.

@jmshark jmshark force-pushed the impr/combine-mailbox-receiver branch from d55f262 to 9e75197 Compare March 6, 2023 13:55
@jmshark jmshark marked this pull request as ready for review March 6, 2023 14:18
@jmshark jmshark force-pushed the impr/combine-mailbox-receiver branch from 9e75197 to e042ad1 Compare March 6, 2023 14:25
@jmshark jmshark temporarily deployed to Test Pull Request March 6, 2023 14:33 — with GitHub Actions Inactive
@jmshark jmshark merged commit 4fed03d into thin-edge:main Mar 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants