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 operation support to c8y-mapper #2303

Merged

Conversation

rina23q
Copy link
Member

@rina23q rina23q commented Sep 29, 2023

Proposed changes

Todo:

  • Fix why te/../cmd/config.. topic is not picked up by mapper. Check subscription
  • Improve error management. Remove all unwraps.
  • Add unit tests
  • Fix issues found by unit tests
  • Delete a file from file-transfer-repo after operation is successful
  • Add tedge config like c8y.enable.config_update and c8y.enable.config_snapshot

Follow-up:

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

#2292

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

@rina23q rina23q temporarily deployed to Test Pull Request September 29, 2023 01:40 — with GitHub Actions Inactive
@github-actions
Copy link
Contributor

github-actions bot commented Sep 29, 2023

Robot Results

✅ Passed ❌ Failed ⏭️ Skipped Total Pass % ⏱️ Duration
314 0 3 314 100 55m20.587999999s

@rina23q rina23q temporarily deployed to Test Pull Request October 2, 2023 22:09 — with GitHub Actions Inactive
crates/core/c8y_api/src/smartrest/download.rs Outdated Show resolved Hide resolved
crates/extensions/c8y_mapper_ext/src/actor.rs Outdated Show resolved Hide resolved
crates/extensions/c8y_mapper_ext/src/config_operations.rs Outdated Show resolved Hide resolved
crates/extensions/c8y_mapper_ext/src/config_operations.rs Outdated Show resolved Hide resolved
&response.config_type,
external_id.as_ref().to_string(),
)
.await; // We need to get rid of this await, otherwise it blocks
Copy link
Contributor

Choose a reason for hiding this comment

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

To be replaced by a call to the config uploader actor once #2302 is done.

crates/extensions/c8y_mapper_ext/src/config_operations.rs Outdated Show resolved Hide resolved
crates/extensions/c8y_mapper_ext/src/config_operations.rs Outdated Show resolved Hide resolved
crates/extensions/c8y_mapper_ext/src/config_operations.rs Outdated Show resolved Hide resolved
crates/extensions/c8y_mapper_ext/src/config_operations.rs Outdated Show resolved Hide resolved
Signed-off-by: Rina Fujino <18257209+rina23q@users.noreply.github.com>
Upon receiving c8y_UploadConfigFile request, c8y-mapper does
* create a new config_snapshot command
* upload a config file to c8y on successful state of config_snapshot cmd

Upon receiving c8y_DownloadConfigFile request, c8y-mapper does
* download a target file from remote if not available in cache directory
* create a new config_update command
* remove a symlink on successful state of config_update cmd

For both matadata, c8y-mapper sends supported config types message and
supported operations to c8y

Signed-off-by: Rina Fujino <18257209+rina23q@users.noreply.github.com>
@rina23q rina23q force-pushed the feature/2098/c8y-mapper-for-config-ops branch from f93b9f1 to a8830b1 Compare October 11, 2023 17:42
@codecov
Copy link

codecov bot commented Oct 11, 2023

Codecov Report

Merging #2303 (6aa7b9e) into main (7509cbf) will increase coverage by 0.3%.
Report is 7 commits behind head on main.
The diff coverage is 81.6%.

Additional details and impacted files
Files Coverage Δ
crates/common/tedge_config_macros/impl/src/lib.rs 95.2% <100.0%> (ø)
...rates/common/tedge_config_macros/impl/src/query.rs 95.2% <100.0%> (+1.7%) ⬆️
crates/extensions/c8y_mapper_ext/src/error.rs 0.0% <ø> (ø)
crates/extensions/c8y_mapper_ext/src/lib.rs 87.5% <100.0%> (+4.1%) ⬆️
crates/extensions/c8y_mapper_ext/src/log_upload.rs 77.0% <100.0%> (+0.1%) ⬆️
...common/tedge_config_macros/impl/src/input/parse.rs 39.7% <0.0%> (-0.6%) ⬇️
...mon/tedge_config_macros/impl/src/input/validate.rs 94.3% <94.7%> (+0.2%) ⬆️
...re/c8y_api/src/smartrest/smartrest_deserializer.rs 93.4% <0.0%> (-0.2%) ⬇️
crates/core/tedge_api/src/messages.rs 92.2% <0.0%> (-0.2%) ⬇️
.../tedge_config/src/tedge_config_cli/tedge_config.rs 81.8% <75.0%> (-8.0%) ⬇️
... and 6 more

... and 12 files with indirect coverage changes

@rina23q rina23q marked this pull request as ready for review October 11, 2023 20:35
@rina23q rina23q force-pushed the feature/2098/c8y-mapper-for-config-ops branch 2 times, most recently from 9c3decd to 406aece Compare October 11, 2023 20:46
Slash is reserved for file system, therefore, using '/' inside tedgeUrl
causes creating unexpected directories in the file transfer repository.
Since '/' is still valid as config type, replacing slashes only in paths

Signed-off-by: Rina Fujino <18257209+rina23q@users.noreply.github.com>
Signed-off-by: Rina Fujino <18257209+rina23q@users.noreply.github.com>
@rina23q rina23q force-pushed the feature/2098/c8y-mapper-for-config-ops branch from 406aece to 26b0c72 Compare October 11, 2023 20:47
Copy link
Contributor

@reubenmiller reubenmiller left a comment

Choose a reason for hiding this comment

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

We're going to have to include the packaging and system tests in this PR so that we avoid publishing a tedge-mapper which sends the configuration operation to a component that does not exist. So even though the additional packaging changes are not directly related to the PR, I don't see any easy way to merge this PR without fully switching over from c8y-configuration-plugin to tedge-configuration-plugin.

I've started preparing the packaging/updated system tests, however the following still needs to be done in order to assist:

Update

I just saw that there are feature flags included in this PR to disable this feature until we're ready with the packaging. So I don't have any problem merging.

@rina23q rina23q temporarily deployed to Test Pull Request October 12, 2023 02:21 — with GitHub Actions Inactive
Copy link
Contributor

@reubenmiller reubenmiller left a comment

Choose a reason for hiding this comment

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

Approved

crates/extensions/c8y_mapper_ext/src/actor.rs Show resolved Hide resolved
crates/extensions/c8y_mapper_ext/src/config.rs Outdated Show resolved Hide resolved
crates/extensions/c8y_mapper_ext/src/config.rs Outdated Show resolved Hide resolved
crates/extensions/c8y_mapper_ext/src/converter.rs Outdated Show resolved Hide resolved
Comment on lines +79 to +82
.get_by_external_id(&snapshot_request.device.clone().into())
.ok_or_else(|| UnknownDevice {
device_id: snapshot_request.device.to_string(),
})?;
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 this pattern repeating a lot these days (for restart, log_upload etc) and this will just increase. May be it's time to add try_get_by_external_id and try_get API counterparts which will return that Err<UnknownDevice> result instead of None as returned by the existing APIs. It can be done in a follow-up PR though.

Copy link
Member Author

Choose a reason for hiding this comment

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

Addressed in the PR #2340

"http://{}/tedge/file-transfer/{}/config_snapshot/{}-{}",
&self.config.tedge_http_host,
external_id,
snapshot_request.config_type.replace('/', ":"),
Copy link
Contributor

Choose a reason for hiding this comment

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

With this, there is the risk of different config types abc:xyz and abc/xyz conflicting. The snapshot of the first file might get overwritten by the second one. As long as our request processing is serial, this many not be an issue. But still, why not allow those extra dirs when the type has / in it? What's the harm?

Copy link
Member Author

Choose a reason for hiding this comment

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

Our config_type allows to use / (it's even a kind of default when user doesn't give specific type, then using file path as type). However, since / is considered directory separator, so somehow need to escape. Then I introduce replacing with : .

If we don't escape, when plugin uploads to http://localhost:8888/tedge/file-transfer/test-device/config_snapshot//etc/tedge/tedge.toml-1234 for the type /etc/tedge/tedge.toml, the file will be stored /var/tedge/test-device/config_snapshot/etc/tedge/tedge.toml-1234. Too many directories.

Signed-off-by: Rina Fujino <18257209+rina23q@users.noreply.github.com>
Signed-off-by: Rina Fujino <18257209+rina23q@users.noreply.github.com>
@rina23q rina23q temporarily deployed to Test Pull Request October 12, 2023 10:03 — with GitHub Actions Inactive
Copy link
Contributor

@albinsuresh albinsuresh left a comment

Choose a reason for hiding this comment

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

LGTM

pub enum SmartRestVariant {
SmartRestLogRequest,
#[derive(Debug)]
pub enum SmartRestOperationVariant {
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
pub enum SmartRestOperationVariant {
pub enum SmartRestOperation {

@rina23q rina23q merged commit 1dffbb6 into thin-edge:main Oct 12, 2023
18 checks passed
@rina23q rina23q deleted the feature/2098/c8y-mapper-for-config-ops branch October 12, 2023 10:50
rina23q added a commit to rina23q/thin-edge.io that referenced this pull request Oct 12, 2023
As commented in thin-edge#2303#discussion_r1356364285, we have many patterns
using get() or get_by_external_id() and map them None to Err.

The new APIs returns Error::UnknownEntity instead of None.

Signed-off-by: Rina Fujino <18257209+rina23q@users.noreply.github.com>
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