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

Add configuration option to disable lock file creation #1818

Merged
merged 1 commit into from
Mar 20, 2023

Conversation

Ruadhri17
Copy link
Contributor

Proposed changes

This commit adds a configuration option to disable lock file creation by running the tedge config command or editing the tedge.toml file. More information in #1802

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

#1802

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

@Ruadhri17 Ruadhri17 temporarily deployed to Test Pull Request March 16, 2023 21:20 — with GitHub Actions Inactive
@didier-wenzek didier-wenzek self-requested a review March 16, 2023 21:21
@github-actions
Copy link
Contributor

github-actions bot commented Mar 16, 2023

Robot Results

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

Passed Tests

Name ⏱️ Duration Suite
Define Child device 1 ID 0.013 s C8Y Child Alarms Rpi
Normal case when the child device does not exist on c8y cloud 5.027 s C8Y Child Alarms Rpi
Normal case when the child device already exists 1.28 s C8Y Child Alarms Rpi
Reconciliation when the new alarm message arrives, restart the mapper 2.271 s C8Y Child Alarms Rpi
Reconciliation when the alarm that is cleared 6.448 s C8Y Child Alarms Rpi
Prerequisite Parent 22.376 s Child Conf Mgmt Plugin
Prerequisite Child 0.313 s Child Conf Mgmt Plugin
Child device bootstrapping 17.143 s Child Conf Mgmt Plugin
Snapshot from device 20.145 s Child Conf Mgmt Plugin
Child device config update 19.956 s Child Conf Mgmt Plugin
Configuration types should be detected on file change (without restarting service) 57.852 s Inotify Crate
Child devices support sending simple measurements 58.23 s Child Device Telemetry
Child devices support sending custom measurements 55.74 s Child Device Telemetry
Child devices support sending custom events 54.246 s Child Device Telemetry
Child devices support sending custom events overriding the type 37.336 s Child Device Telemetry
Child devices support sending custom alarms #1699 53.651 s Child Device Telemetry
Child devices support sending inventory data via c8y topic 26.293 s Child Device Telemetry
Main device support sending inventory data via c8y topic 26.325 s Child Device Telemetry
Successful firmware operation 69.647 s Firmware Operation
Install with empty firmware name 67.864 s Firmware Operation
Prerequisite Parent 23.835 s Firmware Operation Child Device
Prerequisite Child 8.871 s Firmware Operation Child Device
Child device firmware update 6.928 s Firmware Operation Child Device
Child device firmware update with cache 6.732 s Firmware Operation Child Device
Retrieve a JWT tokens 57.05 s Jwt Request
Supports restarting the device 95.774 s Restart Device
Update tedge version from previous using Cumulocity 126.359 s Tedge Self Update
Test if all c8y services are up 76.999 s Service Monitoring
Test if all c8y services are down 67.156 s Service Monitoring
Test if all c8y services are using configured service type 73.484 s Service Monitoring
Test if all c8y services using default service type when service type configured as empty 54.941 s Service Monitoring
Check health status of tedge-mapper-c8y service on broker restart 31.568 s Service Monitoring
Check health status of child device service 24.426 s Service Monitoring
Successful shell command with output 4.549 s Shell Operation
Check Successful shell command with literal double quotes output 4.108 s Shell Operation
Execute multiline shell command 3.882 s Shell Operation
Failed shell command 3.685 s Shell Operation
Software list should be populated during startup 62.502 s Software
Install software via Cumulocity 85.909 s Software
Software list should only show currently installed software and not candidates 56.313 s Software
Stop tedge-agent service 0.619 s Log Path Config
Customize the log path 0.153 s Log Path Config
Initialize tedge-agent 0.13 s Log Path Config
Check created folders 0.105 s Log Path Config
Remove created custom folders 0.119 s Log Path Config
Install thin-edge via apt 56.047 s Install Apt
Install latest via script (from current branch) 29.933 s Install Tedge
Install specific version via script (from current branch) 32.186 s Install Tedge
Install latest tedge via script (from main branch) 21.585 s Install Tedge
Support starting and stopping services 47.563 s Service-Control
Supports a reconnect 66.786 s Test-Commands
Supports disconnect then connect 61.519 s Test-Commands
Update unknown setting 44.466 s Test-Commands
Update known setting 34.67 s Test-Commands
Stop c8y-configuration-plugin 0.239 s Health C8Y-Configuration-Plugin
Update the service file 0.207 s Health C8Y-Configuration-Plugin
Reload systemd files 0.792 s Health C8Y-Configuration-Plugin
Start c8y-configuration-plugin 0.298 s Health C8Y-Configuration-Plugin
Start watchdog service 10.431 s Health C8Y-Configuration-Plugin
Check PID of c8y-configuration-plugin 0.131 s Health C8Y-Configuration-Plugin
Kill the PID 0.209 s Health C8Y-Configuration-Plugin
Recheck PID of c8y-configuration-plugin 2.239 s Health C8Y-Configuration-Plugin
Compare PID change 0.001 s Health C8Y-Configuration-Plugin
Stop watchdog service 0.128 s Health C8Y-Configuration-Plugin
Remove entry from service file 0.085 s Health C8Y-Configuration-Plugin
Stop c8y-log-plugin 0.36 s Health C8Y-Log-Plugin
Update the service file 0.241 s Health C8Y-Log-Plugin
Reload systemd files 0.845 s Health C8Y-Log-Plugin
Start c8y-log-plugin 0.32 s Health C8Y-Log-Plugin
Start watchdog service 10.406 s Health C8Y-Log-Plugin
Check PID of c8y-log-plugin 0.199 s Health C8Y-Log-Plugin
Kill the PID 0.233 s Health C8Y-Log-Plugin
Recheck PID of c8y-log-plugin 2.266 s Health C8Y-Log-Plugin
Compare PID change 0.001 s Health C8Y-Log-Plugin
Stop watchdog service 0.183 s Health C8Y-Log-Plugin
Remove entry from service file 0.156 s Health C8Y-Log-Plugin
Stop tedge-mapper 0.507 s Health Tedge Mapper C8Y
Update the service file 0.336 s Health Tedge Mapper C8Y
Reload systemd files 1.388 s Health Tedge Mapper C8Y
Start tedge-mapper 0.474 s Health Tedge Mapper C8Y
Start watchdog service 10.345 s Health Tedge Mapper C8Y
Check PID of tedge-mapper 0.275 s Health Tedge Mapper C8Y
Kill the PID 0.204 s Health Tedge Mapper C8Y
Recheck PID of tedge-mapper 2.509 s Health Tedge Mapper C8Y
Compare PID change 0.002 s Health Tedge Mapper C8Y
Stop watchdog service 0.502 s Health Tedge Mapper C8Y
Remove entry from service file 0.287 s Health Tedge Mapper C8Y
Stop tedge-agent 0.244 s Health Tedge-Agent
Update the service file 0.122 s Health Tedge-Agent
Reload systemd files 0.804 s Health Tedge-Agent
Start tedge-agent 0.149 s Health Tedge-Agent
Start watchdog service 10.27 s Health Tedge-Agent
Check PID of tedge-mapper 0.178 s Health Tedge-Agent
Kill the PID 0.157 s Health Tedge-Agent
Recheck PID of tedge-agent 2.213 s Health Tedge-Agent
Compare PID change 0.001 s Health Tedge-Agent
Stop watchdog service 0.383 s Health Tedge-Agent
Remove entry from service file 0.279 s Health Tedge-Agent
Stop tedge-mapper-az 0.306 s Health Tedge-Mapper-Az
Update the service file 0.244 s Health Tedge-Mapper-Az
Reload systemd files 1.119 s Health Tedge-Mapper-Az
Start tedge-mapper-az 0.27 s Health Tedge-Mapper-Az
Start watchdog service 10.343 s Health Tedge-Mapper-Az
Check PID of tedge-mapper-az 0.093 s Health Tedge-Mapper-Az
Kill the PID 0.112 s Health Tedge-Mapper-Az
Recheck PID of tedge-agent 2.189 s Health Tedge-Mapper-Az
Compare PID change 0.001 s Health Tedge-Mapper-Az
Stop watchdog service 0.152 s Health Tedge-Mapper-Az
Remove entry from service file 0.181 s Health Tedge-Mapper-Az
Stop tedge-mapper-collectd 0.262 s Health Tedge-Mapper-Collectd
Update the service file 0.312 s Health Tedge-Mapper-Collectd
Reload systemd files 1.236 s Health Tedge-Mapper-Collectd
Start tedge-mapper-collectd 0.357 s Health Tedge-Mapper-Collectd
Start watchdog service 10.415 s Health Tedge-Mapper-Collectd
Check PID of tedge-mapper-collectd 0.199 s Health Tedge-Mapper-Collectd
Kill the PID 0.231 s Health Tedge-Mapper-Collectd
Recheck PID of tedge-mapper-collectd 2.3970000000000002 s Health Tedge-Mapper-Collectd
Compare PID change 0.027 s Health Tedge-Mapper-Collectd
Stop watchdog service 0.154 s Health Tedge-Mapper-Collectd
Remove entry from service file 0.198 s Health Tedge-Mapper-Collectd
c8y-log-plugin health status 5.942 s MQTT health endpoints
c8y-configuration-plugin health status 5.635 s MQTT health endpoints
Wrong package name 0.416 s Improve Tedge Apt Plugin Error Messages
Wrong version 0.272 s Improve Tedge Apt Plugin Error Messages
Wrong type 0.578 s Improve Tedge Apt Plugin Error Messages
tedge_connect_test_positive 0.811 s Tedge Connect Test
tedge_connect_test_negative 2.681 s Tedge Connect Test
tedge_connect_test_sm_services 11.38 s Tedge Connect Test
tedge_disconnect_test_sm_services 3.783 s Tedge Connect Test
Install thin-edge.io 25.172 s Call Tedge
call tedge -V 0.368 s Call Tedge
call tedge -h 0.379 s Call Tedge
call tedge -h -V 0.333 s Call Tedge
call tedge help 0.452 s Call Tedge
tedge config list 0.15 s Call Tedge Config List
tedge config list --all 0.146 s Call Tedge Config List
set/unset device.type 0.774 s Call Tedge Config List
set/unset device.key.path 0.846 s Call Tedge Config List
set/unset device.cert.path 1.046 s Call Tedge Config List
set/unset c8y.root.cert.path 1.085 s Call Tedge Config List
set/unset c8y.smartrest.templates 1.1 s Call Tedge Config List
set/unset az.root.cert.path 1.086 s Call Tedge Config List
set/unset az.mapper.timestamp 0.69 s Call Tedge Config List
set/unset mqtt.bind_address 0.63 s Call Tedge Config List
set/unset mqtt.port 0.796 s Call Tedge Config List
set/unset tmp.path 0.863 s Call Tedge Config List
set/unset logs.path 1.016 s Call Tedge Config List
set/unset run.path 1.008 s Call Tedge Config List
Get Put Delete 7.362 s Http File Transfer Api
Set keys should return value on stdout 0.26 s Tedge Config Get
Unset keys should not return anything on stdout and warnings on stderr 0.574 s Tedge Config Get
Invalid keys should not return anything on stdout and warnings on stderr 0.487 s Tedge Config Get

// Run only one instance of a mapper (if enabled)
if config.query(LockFilesSetting)?.is_set() {
let run_dir: PathBuf = config.query(RunPathSetting)?.into();
let _flock = check_another_instance_is_not_running(&mapper_opt.name.to_string(), &run_dir)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

Since the lock is released on drop, you have to use here the same trick as for the agent, i.e. to hold a reference to Some(Lock).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Comment on lines 276 to 278
let config_repository =
tedge_config::TEdgeConfigRepository::new(config.config_location.clone());
let tedge_config = config_repository.load()?;
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor. Since the config is already read to populate the SmAgentConfig, I wonder if one can simply extend the SmAgentConfig struct with a use_lock property that would be used here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It makes sense. I extended SmAgentConfig and now it looks for this flag there.

@Ruadhri17 Ruadhri17 temporarily deployed to Test Pull Request March 17, 2023 12:21 — with GitHub Actions Inactive
Comment on lines 105 to 112
if config.query(LockFilesSetting)?.is_set() {
let run_dir: PathBuf = config.query(RunPathSetting)?.into();
let _flock = Some(check_another_instance_is_not_running(
&mapper_opt.name.to_string(),
&run_dir,
)?);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The lock must stay in scope up to the end of main(), as it would be released on drop.

Suggested change
if config.query(LockFilesSetting)?.is_set() {
let run_dir: PathBuf = config.query(RunPathSetting)?.into();
let _flock = Some(check_another_instance_is_not_running(
&mapper_opt.name.to_string(),
&run_dir,
)?);
}
let mut flock = None;
if config.query(LockFilesSetting)?.is_set() {
let run_dir: PathBuf = config.query(RunPathSetting)?.into();
flock = Some(check_another_instance_is_not_running(
&mapper_opt.name.to_string(),
&run_dir,
)?);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Edited

Signed-off-by: Krzysztof Piotrowski <krzysztof.piotrowski@inetum.com>
@Ruadhri17 Ruadhri17 temporarily deployed to Test Pull Request March 17, 2023 14:38 — 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. Thank you.

@didier-wenzek didier-wenzek merged commit 87d72ed into thin-edge:main Mar 20, 2023
@Ruadhri17 Ruadhri17 deleted the conditional-lock-files branch June 26, 2023 14:37
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

2 participants