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

feat: add an option to use c8y operation ID to update its status #3076

Conversation

rina23q
Copy link
Member

@rina23q rina23q commented Aug 21, 2024

Proposed changes

Cumulocity 10.18 version added 504-506 SmartREST static templates, which enables users to update operation status with its operation ID. This PR adds a new tedge config to switch either 501-503 or 504-506 for operation status updates.

One can change the setting by tedge config. true (504-506), false (501-503). Ideally making auto option, however, this is out of scope of this PR.

tedge config set c8y.smartrest.use_operation_id true

Note: for the naming decision, see this thread.

This change excludes the supports for below since they react to SmartREST operation messages, not JSON over MQTT. This means it's not possible to take its operation ID. Also, we don't generate thin-edge commands for these operations.

  • custom operation plugin
  • legacy c8y-firmware-plugin

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

#2616

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 August 21, 2024 14:40 — with GitHub Actions Inactive
@rina23q rina23q added the theme:c8y Theme: Cumulocity related topics label Aug 21, 2024
Copy link

codecov bot commented Aug 21, 2024

Codecov Report

Attention: Patch coverage is 98.73950% with 12 lines in your changes missing coverage. Please review.

Files Patch % Lines
crates/extensions/c8y_mapper_ext/src/converter.rs 73.68% 5 Missing ⚠️
...ions/c8y_mapper_ext/src/operations/handlers/mod.rs 94.02% 4 Missing ⚠️
crates/extensions/c8y_mapper_ext/src/config.rs 50.00% 2 Missing ⚠️
...core/c8y_api/src/smartrest/smartrest_serializer.rs 98.46% 1 Missing ⚠️
Additional details and impacted files

📢 Thoughts on this report? Let us know!

Copy link
Contributor

github-actions bot commented Aug 21, 2024

Robot Results

✅ Passed ❌ Failed ⏭️ Skipped Total Pass % ⏱️ Duration
494 0 2 494 100 1h31m34.715098s

@rina23q rina23q force-pushed the improve/2616/use-smartrest-504-505-506-for-operation-status-update branch from 4814b7a to e366d50 Compare August 23, 2024 20:32
@rina23q rina23q temporarily deployed to Test Pull Request August 23, 2024 20:54 — with GitHub Actions Inactive
@rina23q rina23q temporarily deployed to Test Pull Request August 26, 2024 12:05 — with GitHub Actions Inactive
@rina23q rina23q force-pushed the improve/2616/use-smartrest-504-505-506-for-operation-status-update branch from cd275db to 5e95aa0 Compare August 26, 2024 13:03
@rina23q rina23q temporarily deployed to Test Pull Request August 26, 2024 13:03 — with GitHub Actions Inactive
@rina23q rina23q temporarily deployed to Test Pull Request August 26, 2024 14:49 — with GitHub Actions Inactive
@rina23q rina23q marked this pull request as ready for review August 26, 2024 14:50
@rina23q rina23q requested a review from Bravo555 August 26, 2024 14:50
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.

I will be really happy to merge this PR. I just have one question.

Comment on lines 473 to 475
/// Switch using 501-503 (without operation ID) or 504-506 (with operation ID) SmartREST messages for operation status update
#[tedge_config(example = "true", default(value = true))]
with_operation_id: bool,
Copy link
Contributor

Choose a reason for hiding this comment

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

What will be the behavior if operation ids are enabled on the device but not available on the c8y instance? Would things work? If not how the user will be notified? By error messages or stuck operations?

Copy link
Member Author

@rina23q rina23q Aug 27, 2024

Choose a reason for hiding this comment

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

What will be the behavior if operation ids are enabled on the device but not available on the c8y instance? Would things work?

No, it won't work (that's we want to improve with auto option)

If not how the user will be notified? By error messages or stuck operations?

I can't really test it since all tenants available for us are already 10.18 or above. User will definitely receive an error message on c8y/s/e for unknown static template like below.

[c8y/s/us] 900
[c8y/s/e] 40,900,No static template for this message id

In this case, operation will be executed and successful/failed in thin-edge, but the status will stay PENDING in c8y.

Copy link
Contributor

Choose a reason for hiding this comment

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

What's the plan to implement auto detection? Can we probe for errors on c8y/s/e when sending 504-506 messages and then fallback to the previous API?

Copy link
Member Author

@rina23q rina23q Aug 27, 2024

Choose a reason for hiding this comment

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

What's the plan to implement auto detection? Can we probe for errors on c8y/s/e when sending 504-506 messages and then fallback to the previous API?

Definitely it's one of the doable options. We have similar issue for Advanced Software Management (requirement: 10.14> and dedicated Microservice). I want to have a consistent solution for this and Advanced Software Management. Probably we need to discuss Device Management Team to choose the best solution.

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.

fail_operation("505", op_id, reason)
}

fn fail_operation(number: &str, operation: &str, reason: &str) -> String {
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
fn fail_operation(number: &str, operation: &str, reason: &str) -> String {
fn fail_operation(template_id: &str, operation: &str, reason: &str) -> String {

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 all your renaming suggestion in this commit: 2e15950

crates/core/c8y_api/src/smartrest/smartrest_serializer.rs Outdated Show resolved Hide resolved
crates/core/c8y_api/src/smartrest/smartrest_serializer.rs Outdated Show resolved Hide resolved
crates/core/c8y_api/src/smartrest/smartrest_serializer.rs Outdated Show resolved Hide resolved

/// Switch using 501-503 (without operation ID) or 504-506 (with operation ID) SmartREST messages for operation status update
#[tedge_config(example = "true", default(value = true))]
with_operation_id: bool,
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
with_operation_id: bool,
direct_operation_update: bool,

Not fully happy about this suggestion either. Accept only if you're convinced.

Copy link
Member Author

Choose a reason for hiding this comment

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

The key will look c8y.smartrest.direct_operation_update. I don't think what "direct" means is so clear. At least, not for me. How about something in between my proposal and yours, c8y.smartrest.operation_id_update?

Copy link
Contributor

Choose a reason for hiding this comment

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

My bikeshed take would be something like c8y.smartrest.operation_explicit_id or operation_template_explicit_id

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 reason to change anything here: with_operation_id is simple and clear.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, direct isn't very clear. I kinda liked operation_explicit_id as well. How about something even more direct: use_operation_id?

Copy link
Member Author

Choose a reason for hiding this comment

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

I vote +1 for use_operation_id

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

@Bravo555 Bravo555 self-assigned this Aug 27, 2024
@rina23q rina23q temporarily deployed to Test Pull Request August 27, 2024 14:32 — with GitHub Actions Inactive
Cumulocity 10.18 version added 504-506 SmartREST static templates,
which enables users to update operation status with its operation ID.

Add a new tedge config to switch either 501-503 or 504-506 for operation
status updates.

Signed-off-by: Rina Fujino <[email protected]>
@rina23q rina23q force-pushed the improve/2616/use-smartrest-504-505-506-for-operation-status-update branch from 0136b9e to e53921c Compare August 27, 2024 15:11
@rina23q rina23q temporarily deployed to Test Pull Request August 27, 2024 15:11 — with GitHub Actions Inactive
@rina23q rina23q added this pull request to the merge queue Aug 27, 2024
Merged via the queue into thin-edge:main with commit c4d27ff Aug 27, 2024
33 checks passed
@Bravo555 Bravo555 removed their assignment Dec 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme:c8y Theme: Cumulocity related topics
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants