Skip to content

fix: cleanup temp log artefacts created for log_upload#4141

Open
albinsuresh wants to merge 2 commits intothin-edge:mainfrom
albinsuresh:fix/cleaup-stale-tmp-artefacts
Open

fix: cleanup temp log artefacts created for log_upload#4141
albinsuresh wants to merge 2 commits intothin-edge:mainfrom
albinsuresh:fix/cleaup-stale-tmp-artefacts

Conversation

@albinsuresh
Copy link
Copy Markdown
Contributor

@albinsuresh albinsuresh commented Apr 23, 2026

Proposed changes

Cleanup the following temp files created during the log_upload operation handling:

  • The temp file created by the file plugin combining all target files
  • The uploaded log file in the file transfer service, cleaned up by the mapper

The agent was already deleting the tmp file that it creates after applying the filters like line count and search text.

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

#4139

Checklist

  • I have read the CONTRIBUTING doc
  • I have signed the CLA (in all commits with git commit -s. You can activate automatic signing by running just prepare-dev once)
  • I ran just format as mentioned in CODING_GUIDELINES
  • I used just check 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

@albinsuresh albinsuresh temporarily deployed to Test Pull Request April 23, 2026 08:52 — with GitHub Actions Inactive
@reubenmiller reubenmiller added theme:troubleshooting Theme: Troubleshooting and remote control labels Apr 23, 2026
@albinsuresh albinsuresh removed theme:troubleshooting Theme: Troubleshooting and remote control labels Apr 23, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 23, 2026

Robot Results

✅ Passed ❌ Failed ⏭️ Skipped Total Pass % ⏱️ Duration
910 1 4 911 99.89 2h42m40.809546999s

Failed Tests

Name Message ⏱️ Duration Suite
Connect to Cumulocity MQTT Service endpoint basic auth tedge connect c8y returned an unexpected exit code stdout: stderr: Connecting to Cumulocity: mapper configuration file: /etc/tedge/mappers/c8y/mapper.toml device id: TST_diminish_few_brightness cloud profile: <none> cloud host: qaenvironment.eu-latest.cumulocity.com:9883 auth type: Basic credentials path: /etc/tedge/credentials.toml bridge: built-in service manager: systemd mosquitto version: 2.0.11 proxy: Not configured Updating bridge rule templates... ✓ Creating device in Cumulocity cloud... ✗ error: Connection error while creating device in Cumulocity: Connection refused, return code: NotAuthorized [RETRY] FAIL on 3. retry. 48.178 s Tedge Connect Mqtt Service

@albinsuresh albinsuresh temporarily deployed to Test Pull Request April 23, 2026 15:05 — with GitHub Actions Inactive
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 23, 2026

Codecov Report

❌ Patch coverage is 79.41176% with 7 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...extensions/c8y_mapper_ext/src/operations/upload.rs 60.00% 5 Missing and 1 partial ⚠️
plugins/tedge_file_log_plugin/src/bin.rs 0.00% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@albinsuresh albinsuresh marked this pull request as ready for review April 23, 2026 15:27
Copy link
Copy Markdown
Member

@rina23q rina23q left a comment

Choose a reason for hiding this comment

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

Approved. Confirmed it fixed the reported issue.

println!("{}", line);
}

std::fs::remove_file(log_path)?;
Copy link
Copy Markdown
Member

@rina23q rina23q Apr 24, 2026

Choose a reason for hiding this comment

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

You can ignore this. What I was thinking here:

If we use tempfile instead of regular file creation for the temporary file, we probably don't need to have this remove_file(). However, then the return type of FileLogPlugin::get() and the actual function new_read_logs() would need to be changed to NamedTempFile. Doable, but not sure if it's worth it.

Copy link
Copy Markdown
Member

@Bravo555 Bravo555 left a comment

Choose a reason for hiding this comment

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

NOTE: The same issue happens with config snapshot operation

When the same check is applied to config snapshot test:

diff --git a/tests/RobotFramework/tests/cumulocity/configuration/configuration_with_file_transfer_https.robot b/tests/RobotFramework/tests/cumulocity/configuration/configuration_with_file_transfer_https.robot
index 824c5536c5..a8c08e0de6 100644
--- a/tests/RobotFramework/tests/cumulocity/configuration/configuration_with_file_transfer_https.robot
+++ b/tests/RobotFramework/tests/cumulocity/configuration/configuration_with_file_transfer_https.robot
@@ -54,6 +54,11 @@ File Transfer Service is accessible over HTTPS from child device
 Configuration snapshots are uploaded to File Transfer Service via HTTPS
     Get Configuration Should Succeed    device=${CHILD_SN}    external_id=${PARENT_SN}:device:${CHILD_SN}
 
+    # Validate that all temporary files created for the log upload operation are cleaned up
+    ThinEdgeIO.Set Device Context    ${FTS_SN}
+    Execute Command    ls /tmp/CONFIG1*    exp_exit_code=2
+    Execute Command    ls /var/tedge/file-transfer/${PARENT_SN}:device:${CHILD_SN}/config_snapshot/CONFIG1*    exp_exit_code=2
+
 Configuration snapshots are uploaded to File Transfer Service via HTTPS with client certificate
     Enable Certificate Authentication for File Transfer Service
     Get Configuration Should Succeed    device=${CHILD_SN}    external_id=${PARENT_SN}:device:${CHILD_SN}

It fails:

`ls /var/tedge/file-transfer/TS...` returned an unexpected exit code
stdout:
/var/tedge/file-transfer/TST_hoard_massive_carrier:device:TST_detour_smart_gang/config_snapshot/CONFIG1-c8y-mapper-54216380

stderr:

I'd say since this is the same issue, it should should also be fixed in this PR.

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.

4 participants