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

tedge-mapper-c8y service restart is required after a change of supported operation file contents #1959

Merged

Conversation

PradeepKiruvale
Copy link
Contributor

@PradeepKiruvale PradeepKiruvale commented May 9, 2023

Proposed changes

The issue here is, if there is any change to the custom operation file content, then these changes are not reflected in the operation list that is present with the tedge-mapper-c8y. To get it reflected the mapper has to be restarted.
On the code path, on the file change notification, the mapper is wrongly updating the child device operations list.

The proposed fix is

  • Dynamically update/populate the thin-edge device operation list of tedge-mapper-c8y when there is a change in the operation file.

  • Added integration test to verify the fix.

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

#1705

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

Signed-off-by: Pradeep Kumar K J <pradeepkumar.kj@softwareag.com>
Signed-off-by: Pradeep Kumar K J <pradeepkumar.kj@softwareag.com>
@github-actions
Copy link
Contributor

github-actions bot commented May 9, 2023

Robot Results

✅ Passed ❌ Failed ⏭️ Skipped Total Pass %
189 3 5 192 98.44

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 2.689 s C8Y Child Alarms Rpi
Normal case when the child device already exists 1.2770000000000001 s C8Y Child Alarms Rpi
Reconciliation when the new alarm message arrives, restart the mapper 2.685 s C8Y Child Alarms Rpi
Reconciliation when the alarm that is cleared 66.123 s C8Y Child Alarms Rpi
Prerequisite Parent 78.046 s Child Conf Mgmt Plugin
Prerequisite Child 0.351 s Child Conf Mgmt Plugin
Child device bootstrapping 16.887 s Child Conf Mgmt Plugin
Snapshot from device 60.917 s Child Conf Mgmt Plugin
Child device config update 62.141 s Child Conf Mgmt Plugin
Configuration types should be detected on file change (without restarting service) 115.587 s Inotify Crate
Check lock file existence in default folder 2.542 s Lock File
Check PID number in lock file 3.349 s Lock File
Check PID number in lock file after restarting the services 2.342 s Lock File
Check starting same service twice 1.7429999999999999 s Lock File
Switch off lock file creation 2.066 s Lock File
Set configuration when file exists 56.163 s Configuration Operation
Set configuration when file does not exist 6.358 s Configuration Operation
Set configuration with broken url 6.852 s Configuration Operation
Get configuration 6.736 s Configuration Operation
Get non existent configuration file 7.228 s Configuration Operation
Get non existent configuration type 5.643 s Configuration Operation
Update configuration plugin config via cloud 6.029 s Configuration Operation
Modify configuration plugin config via local filesystem modify inplace 3.468 s Configuration Operation
Modify configuration plugin config via local filesystem overwrite 6.18 s Configuration Operation
Update configuration plugin config via local filesystem copy 4.359 s Configuration Operation
Update configuration plugin config via local filesystem move (different directory) 5.95 s Configuration Operation
Update configuration plugin config via local filesystem move (same directory) 3.851 s Configuration Operation
Successful firmware operation 76.935 s Firmware Operation
Install with empty firmware name 49.975 s Firmware Operation
Prerequisite Parent 22.01 s Firmware Operation Child Device
Prerequisite Child 8.078 s Firmware Operation Child Device
Child device firmware update 5.987 s Firmware Operation Child Device
Child device firmware update with cache 5.99 s Firmware Operation Child Device
Firmware plugin supports restart via service manager #1932 7.606 s Firmware Operation Child Device Retry
Update Inventory data via inventory.json 1.377 s Inventory Update
Retrieve a JWT tokens 125.539 s Jwt Request
Check running collectd 1.318 s Monitor Device Collectd
Is collectd publishing MQTT messages? 3.047 s Monitor Device Collectd
Check thin-edge monitoring 4.791 s Monitor Device Collectd
Check grouping of measurements 9.313 s Monitor Device Collectd
Custom operation successful 42.219 s Dynamically Reload Operation
Main device registration 1.865 s Device Registration
Child device registration 2.742 s Device Registration
Supports restarting the device 138.19 s Restart Device
Update tedge version from previous using Cumulocity 109.956 s Tedge Self Update
Test if all c8y services are up 122.12 s Service Monitoring
Test if all c8y services are down 130.448 s Service Monitoring
Test if all c8y services are using configured service type 110.707 s Service Monitoring
Test if all c8y services using default service type when service type configured as empty 91.003 s Service Monitoring
Check health status of tedge-mapper-c8y service on broker stop start 26.783 s Service Monitoring
Check health status of tedge-mapper-c8y service on broker restart 29.183 s Service Monitoring
Check health status of child device service 25.809 s Service Monitoring
Failed shell command 3.557 s Shell Operation
Software list should be populated during startup 60.27 s Software
Install software via Cumulocity 68.899 s Software
Software list should only show currently installed software and not candidates 50.756 s Software
Child devices support sending simple measurements 1.587 s Child Device Telemetry
Child devices support sending custom measurements 1.367 s Child Device Telemetry
Child devices support sending custom events 1.206 s Child Device Telemetry
Child devices support sending custom events overriding the type 1.129 s Child Device Telemetry
Child devices support sending custom alarms #1699 1.3719999999999999 s Child Device Telemetry
Child devices support sending inventory data via c8y topic 1.075 s Child Device Telemetry
Main device support sending inventory data via c8y topic 1.564 s Child Device Telemetry
Child device supports sending custom child device measurements directly to c8y 2.214 s Child Device Telemetry
Main device supports sending custom child device measurements directly to c8y 1.718 s Child Device Telemetry
Check retained alarms 52.784 s Raise Alarms
Validate updated data path used by tedge-agent 0.825 s Data Path Config
Validate updated data path used by c8y-firmware-plugin 11.35 s Data Path Config
Stop tedge-agent service 0.386 s Log Path Config
Customize the log path 0.14 s Log Path Config
Initialize tedge-agent 0.209 s Log Path Config
Check created folders 0.167 s Log Path Config
Remove created custom folders 0.134 s Log Path Config
Install thin-edge via apt 62.547 s Install Apt
Install latest via script (from current branch) 31.465 s Install Tedge
Install specific version via script (from current branch) 30.357 s Install Tedge
Install latest tedge via script (from main branch) 32.24 s Install Tedge
Install then uninstall latest tedge via script (from main branch) 64.219 s Install Tedge
Support starting and stopping services 47.512 s Service-Control
Supports a reconnect 68.923 s Test-Commands
Supports disconnect then connect 42.869 s Test-Commands
Update unknown setting 54.817 s Test-Commands
Update known setting 32.025 s Test-Commands
Stop c8y-configuration-plugin 60.235 s Health C8Y-Configuration-Plugin
Update the service file 0.293 s Health C8Y-Configuration-Plugin
Reload systemd files 1.1400000000000001 s Health C8Y-Configuration-Plugin
Start c8y-configuration-plugin 0.256 s Health C8Y-Configuration-Plugin
Start watchdog service 10.557 s Health C8Y-Configuration-Plugin
Check PID of c8y-configuration-plugin 0.11 s Health C8Y-Configuration-Plugin
Kill the PID 0.21 s Health C8Y-Configuration-Plugin
Recheck PID of c8y-configuration-plugin 6.661 s Health C8Y-Configuration-Plugin
Compare PID change 0.001 s Health C8Y-Configuration-Plugin
Stop watchdog service 0.185 s Health C8Y-Configuration-Plugin
Remove entry from service file 0.156 s Health C8Y-Configuration-Plugin
Stop c8y-log-plugin 60.266 s Health C8Y-Log-Plugin
Update the service file 0.276 s Health C8Y-Log-Plugin
Reload systemd files 1.072 s Health C8Y-Log-Plugin
Start c8y-log-plugin 0.207 s Health C8Y-Log-Plugin
Start watchdog service 10.405 s Health C8Y-Log-Plugin
Check PID of c8y-log-plugin 0.304 s Health C8Y-Log-Plugin
Kill the PID 0.313 s Health C8Y-Log-Plugin
Recheck PID of c8y-log-plugin 6.84 s Health C8Y-Log-Plugin
Compare PID change 0.006 s Health C8Y-Log-Plugin
Stop watchdog service 0.395 s Health C8Y-Log-Plugin
Remove entry from service file 0.248 s Health C8Y-Log-Plugin
Stop tedge-mapper 0.142 s Health Tedge Mapper C8Y
Update the service file 0.123 s Health Tedge Mapper C8Y
Reload systemd files 0.358 s Health Tedge Mapper C8Y
Start tedge-mapper 0.133 s Health Tedge Mapper C8Y
Start watchdog service 10.119 s Health Tedge Mapper C8Y
Check PID of tedge-mapper 0.174 s Health Tedge Mapper C8Y
Kill the PID 0.328 s Health Tedge Mapper C8Y
Recheck PID of tedge-mapper 6.649 s Health Tedge Mapper C8Y
Compare PID change 0.002 s Health Tedge Mapper C8Y
Stop watchdog service 0.3 s Health Tedge Mapper C8Y
Remove entry from service file 0.202 s Health Tedge Mapper C8Y
Stop tedge-agent 0.197 s Health Tedge-Agent
Update the service file 0.161 s Health Tedge-Agent
Reload systemd files 0.339 s Health Tedge-Agent
Start tedge-agent 0.129 s Health Tedge-Agent
Start watchdog service 10.191 s Health Tedge-Agent
Check PID of tedge-mapper 0.119 s Health Tedge-Agent
Kill the PID 0.271 s Health Tedge-Agent
Recheck PID of tedge-agent 6.63 s Health Tedge-Agent
Compare PID change 0.001 s Health Tedge-Agent
Stop watchdog service 0.25 s Health Tedge-Agent
Remove entry from service file 0.148 s Health Tedge-Agent
Stop tedge-mapper-az 0.406 s Health Tedge-Mapper-Az
Update the service file 0.185 s Health Tedge-Mapper-Az
Reload systemd files 0.959 s Health Tedge-Mapper-Az
Start tedge-mapper-az 0.285 s Health Tedge-Mapper-Az
Start watchdog service 10.224 s Health Tedge-Mapper-Az
Check PID of tedge-mapper-az 0.132 s Health Tedge-Mapper-Az
Kill the PID 0.209 s Health Tedge-Mapper-Az
Recheck PID of tedge-agent 6.609 s Health Tedge-Mapper-Az
Compare PID change 0.006 s Health Tedge-Mapper-Az
Stop watchdog service 0.248 s Health Tedge-Mapper-Az
Remove entry from service file 0.228 s Health Tedge-Mapper-Az
Stop tedge-mapper-collectd 0.326 s Health Tedge-Mapper-Collectd
Update the service file 0.246 s Health Tedge-Mapper-Collectd
Reload systemd files 0.685 s Health Tedge-Mapper-Collectd
Start tedge-mapper-collectd 0.236 s Health Tedge-Mapper-Collectd
Start watchdog service 10.368 s Health Tedge-Mapper-Collectd
Check PID of tedge-mapper-collectd 0.13 s Health Tedge-Mapper-Collectd
Kill the PID 0.231 s Health Tedge-Mapper-Collectd
Recheck PID of tedge-mapper-collectd 7.014 s Health Tedge-Mapper-Collectd
Compare PID change 0.012 s Health Tedge-Mapper-Collectd
Stop watchdog service 0.225 s Health Tedge-Mapper-Collectd
Remove entry from service file 0.298 s Health Tedge-Mapper-Collectd
tedge-collectd-mapper health status 5.945 s Health Tedge-Mapper-Collectd
c8y-log-plugin health status 6.457 s MQTT health endpoints
c8y-configuration-plugin health status 5.789 s MQTT health endpoints
Publish on a local insecure broker 0.332 s Basic Pub Sub
Publish on a local secure broker 4.361 s Basic Pub Sub
Publish on a local secure broker with client authentication 8.098 s Basic Pub Sub
Check remote mqtt broker #1773 2.702 s Remote Mqtt Broker
Wrong package name 0.156 s Improve Tedge Apt Plugin Error Messages
Wrong version 0.135 s Improve Tedge Apt Plugin Error Messages
Wrong type 0.371 s Improve Tedge Apt Plugin Error Messages
tedge_connect_test_positive 0.379 s Tedge Connect Test
tedge_connect_test_negative 1.2530000000000001 s Tedge Connect Test
tedge_connect_test_sm_services 7.66 s Tedge Connect Test
tedge_disconnect_test_sm_services 0.815 s Tedge Connect Test
Install thin-edge.io 21.944 s Call Tedge
call tedge -V 0.166 s Call Tedge
call tedge -h 0.141 s Call Tedge
call tedge -h -V 0.257 s Call Tedge
call tedge help 0.1 s Call Tedge
tedge config list 0.12 s Call Tedge Config List
tedge config list --all 0.107 s Call Tedge Config List
set/unset device.type 0.513 s Call Tedge Config List
set/unset device.key.path 0.391 s Call Tedge Config List
set/unset device.cert.path 0.361 s Call Tedge Config List
set/unset c8y.root.cert.path 0.289 s Call Tedge Config List
set/unset c8y.smartrest.templates 0.298 s Call Tedge Config List
set/unset az.root.cert.path 0.53 s Call Tedge Config List
set/unset az.mapper.timestamp 0.351 s Call Tedge Config List
set/unset mqtt.bind_address 0.402 s Call Tedge Config List
set/unset mqtt.port 0.323 s Call Tedge Config List
set/unset tmp.path 0.681 s Call Tedge Config List
set/unset logs.path 0.647 s Call Tedge Config List
set/unset run.path 0.442 s Call Tedge Config List
Get Put Delete 3.725 s Http File Transfer Api
Set keys should return value on stdout 0.09 s Tedge Config Get
Unset keys should not return anything on stdout and warnings on stderr 0.221 s Tedge Config Get
Invalid keys should not return anything on stdout and warnings on stderr 0.156 s Tedge Config Get
Set configuration via environment variables 0.866 s Tedge Config Get
Set unknown configuration via environment variables 0.163 s Tedge Config Get

Failed Tests

Name Message ⏱️ Duration Suite
Successful shell command with output FinalAssertionError: Expected operation (id=2327279) to be SUCCESSFUL, but got: FAILED (failureReason: Operation execution failed: No such file or directory (os error 2). Command: /etc/tedge/operations/command_handler.sh. Operation name: c8y_Command) 3.901 s Shell Operation
Check Successful shell command with literal double quotes output FinalAssertionError: Expected operation (id=2327289) to be SUCCESSFUL, but got: FAILED (failureReason: Operation execution failed: No such file or directory (os error 2). Command: /etc/tedge/operations/command_handler.sh. Operation name: c8y_Command) 3.42 s Shell Operation
Execute multiline shell command FinalAssertionError: Expected operation (id=2327299) to be SUCCESSFUL, but got: FAILED (failureReason: Operation execution failed: No such file or directory (os error 2). Command: /etc/tedge/operations/command_handler.sh. Operation name: c8y_Command) 3.625 s Shell Operation

Signed-off-by: Pradeep Kumar K J <pradeepkumar.kj@softwareag.com>
@PradeepKiruvale PradeepKiruvale temporarily deployed to Test Pull Request May 11, 2023 06:51 — with GitHub Actions Inactive
@@ -743,7 +743,7 @@ impl Converter for CumulocityConverter {
) -> Result<Option<Message>, ConversionError> {
match message.ops_dir.parent() {
Some(parent_dir) => {
if parent_dir.eq(&self.cfg_dir.join("operations").join("c8y")) {
if parent_dir.eq(&self.cfg_dir.join("operations")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Using the operations directory instead of the operation/c8y surprises me. Are you sure we should be using this, as won't that potentially listen to other non-c8y changes as well?

For example:
/etc/tedge/operations/az

Copy link
Contributor Author

@PradeepKiruvale PradeepKiruvale May 11, 2023

Choose a reason for hiding this comment

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

The tedge-mapper-c8y subscribes for notifications for the path /etc/tedge/operations/c8y. So, it will receive the notifications only when there is a change in this directory. The ops_dir is derived as below.

let ops_dir = config_dir.join("operations").join("c8y")

When there is a change of operation in the parent/thin-edge device whenever the notification contains /etc/tedge/operations/c8y. The parent directory will be /etc/tedge/operations.

When there is a change of operation in the thin-edge cumulocity child device the notification contains the /etc/tedge/operations/c8y<child-id> path. In this case, the parent directory will be /etc/tedge/operations/c8y.

Copy link
Contributor

@didier-wenzek didier-wenzek May 11, 2023

Choose a reason for hiding this comment

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

So why not check the paths of the event against /etc/tedge/operations/c8y ?

  • if the dir of the updated file is /etc/tedge/operations/c8y, then the event if for the main device.
  • if the parent dir of the updated file is /etc/tedge/operations/c8y, the the event if for a child device.
  • otherwise the event has to be ignored.

Assuming that the mapper only subscribed to /etc/tedge/operations/c8y is really fragile.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I felt its redundant, if you think it's very fragile, then I am ok to add specific event path checks for parent n child devices.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's fragile because someone else might later add an apparently innocuous new subscriptions and break things in a fully unexpected manner.

Thank you for the update.

Signed-off-by: Pradeep Kumar K J <pradeepkumar.kj@softwareag.com>
@PradeepKiruvale PradeepKiruvale temporarily deployed to Test Pull Request May 11, 2023 10:57 — with GitHub Actions Inactive
Signed-off-by: Pradeep Kumar K J <pradeepkumar.kj@softwareag.com>
@PradeepKiruvale PradeepKiruvale temporarily deployed to Test Pull Request May 11, 2023 12:05 — 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

Comment on lines +753 to +757
} else if message.ops_dir.eq(&self
.cfg_dir
.join("operations")
.join("c8y")
.join(get_child_id(&message.ops_dir)?))
Copy link
Contributor

Choose a reason for hiding this comment

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

[Minor] One might have something simpler by comparing message.ops_dir.parent() with Some("/etc/tedge/operations/c8y").

@PradeepKiruvale PradeepKiruvale merged commit b70bf9f into thin-edge:main May 11, 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.

3 participants