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

MQTT twin/ topic support for Cumulocity inventory updates #2280

Merged
merged 4 commits into from
Oct 19, 2023

Conversation

reubenmiller
Copy link
Contributor

@reubenmiller reubenmiller commented Sep 22, 2023

Proposed changes

PR to communicate the proposed mapping of the /twin/ topics including integration tests. This PR can be used for the actual implementation.

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


#2279

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

@reubenmiller reubenmiller added theme:mqtt Theme: mqtt and mosquitto related topics theme:c8y Theme: Cumulocity related topics theme:telemetry Theme: Telemetry data and removed theme:mqtt Theme: mqtt and mosquitto related topics labels Sep 22, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Sep 22, 2023

Robot Results

✅ Passed ❌ Failed ⏭️ Skipped Total Pass % ⏱️ Duration
321 0 3 321 100 50m53.260999999s

docs/src/references/mappers/c8y-mapper.md Outdated Show resolved Hide resolved
docs/src/references/mappers/c8y-mapper.md Outdated Show resolved Hide resolved
docs/src/references/mappers/c8y-mapper.md Show resolved Hide resolved
docs/src/references/mappers/c8y-mapper.md Show resolved Hide resolved
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.

It would be really nice to use this PR for pushing the implementation along docs and tests.

I see two points that really needs to be clarified:

  • How this feature is combined with the inventory fragments extracted from tedge-config and inventory.json
  • The local consolidation of all the fragments. It's a good idea to persist this aggregated view, but I would really avoid to use the former inventory.json file for that. We need to be clear what is the source of truth: the persisted view of the inventory must only be edited by the mapper after data collected from the config and over MQTT.

docs/src/references/mappers/c8y-mapper.md Show resolved Hide resolved
docs/src/references/mappers/c8y-mapper.md Show resolved Hide resolved
docs/src/references/mappers/c8y-mapper.md Outdated Show resolved Hide resolved
docs/src/references/mappers/c8y-mapper.md Outdated Show resolved Hide resolved
Cumulocity.Set Device ${CHILD_SN}
${mo}= Device Should Have Fragments subtype
Should Be Equal ${mo["subtype"]} LinuxDeviceA
Should Be Equal ${mo["type"]} thin-edge.io
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice to have tests along the specs ♥

This one makes me understand why a type fragment is an issue as already defined by tedge config get device.type. But, don't we have to address with a broader view these conflicts with legacy features (inventory.json and tedge config)?

Copy link
Contributor

Choose a reason for hiding this comment

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

The inventory.json contents can be parsed and any direct key-value pairs can be published to the meta/key topic, with the value as the payload. The same can be extended to tedge config as well, where the value would be just be the plain value instead of a JSON object, as you suggested.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could go the layered approach and first parse the inventory.json file and use that as the base model, and then apply any changes from the MQTT topics. The inventory.json is good for being able to hardcode static information into a build, however we could also just phase the file out (behind a feature flag or something).

Copy link
Contributor

Choose a reason for hiding this comment

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

@reubenmiller So, no need to re-publish the contents of the file as twin messages to the broker? Without that, the other components relying on the broker for the inventory information will never get that "base model", right? Unless they all parse that file.

docs/src/references/mappers/c8y-mapper.md Outdated Show resolved Hide resolved
@albinsuresh albinsuresh marked this pull request as ready for review October 5, 2023 06:47
@albinsuresh albinsuresh force-pushed the feat-tedge-inventory-topic branch from db40a8d to 5a14baa Compare October 13, 2023 04:39
@codecov
Copy link

codecov bot commented Oct 13, 2023

Codecov Report

Merging #2280 (d5f35fc) into main (f811fad) will increase coverage by 0.1%.
The diff coverage is 86.5%.

Additional details and impacted files
Files Coverage Δ
.../tedge_config/src/tedge_config_cli/tedge_config.rs 81.8% <100.0%> (ø)
crates/core/tedge_api/src/mqtt_topics.rs 88.2% <100.0%> (+0.1%) ⬆️
crates/extensions/c8y_mapper_ext/src/lib.rs 87.5% <ø> (ø)
crates/extensions/c8y_mapper_ext/src/tests.rs 92.6% <98.9%> (+0.2%) ⬆️
crates/extensions/c8y_mapper_ext/src/config.rs 48.8% <60.0%> (+0.4%) ⬆️
crates/extensions/c8y_mapper_ext/src/converter.rs 79.6% <81.8%> (-0.1%) ⬇️
crates/extensions/c8y_mapper_ext/src/inventory.rs 82.7% <82.7%> (ø)

... and 5 files with indirect coverage changes

@albinsuresh albinsuresh temporarily deployed to Test Pull Request October 13, 2023 18:28 — with GitHub Actions Inactive
@albinsuresh albinsuresh force-pushed the feat-tedge-inventory-topic branch from aa63bca to f0c96fc Compare October 18, 2023 14:47
@albinsuresh albinsuresh temporarily deployed to Test Pull Request October 18, 2023 15:00 — with GitHub Actions Inactive
@albinsuresh albinsuresh force-pushed the feat-tedge-inventory-topic branch from f0c96fc to 0aa10cb Compare October 18, 2023 16:32
@albinsuresh albinsuresh temporarily deployed to Test Pull Request October 18, 2023 16:46 — 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.

I still have to review inventory.rs. So far things look really nice.

I'm missing doc comments in inventory.rs though. This makes things a bit harder to understand/check as one has to compare each implementation with its uses.

docs/src/references/mappers/c8y-mapper.md Outdated Show resolved Hide resolved
docs/src/references/mappers/c8y-mapper.md Outdated Show resolved Hide resolved
crates/extensions/c8y_mapper_ext/src/converter.rs Outdated Show resolved Hide resolved
crates/extensions/c8y_mapper_ext/src/converter.rs Outdated Show resolved Hide resolved
@albinsuresh albinsuresh temporarily deployed to Test Pull Request October 19, 2023 07:31 — 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.

I really like how things are structured, the inventory.json file being translated into a sequence of twin data messages which are then translated into c8y fragments exactly as any other twin data.

I have some questions about the protected keys (name and type):

  • These keys are not protected when read from the inventory.json file.
  • c8y_Agent seems to be the key needing to be protected form override, not name.

Once these two points clarified, I will be happy to approve.

crates/extensions/c8y_mapper_ext/src/inventory.rs Outdated Show resolved Hide resolved
crates/extensions/c8y_mapper_ext/src/inventory.rs Outdated Show resolved Hide resolved
:::warning
Updating the following properties via the `twin` channel is not supported

* `name`
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is the name property forbidden? Looking at the code, c8y_Agent is the fragment that must be protected from overriding.

Copy link
Contributor

@albinsuresh albinsuresh Oct 19, 2023

Choose a reason for hiding this comment

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

The name and type fields are forbidden here because they're already part of the entity registration message. If someone wants to update these, they must send another registration message with the updated values. Allowing them to update the same data via both these endpoints will might be confusing especially in the broker as we may have different name and type in the device registration topic as well as in the twin/... topics.

I didn't really understand why you think c8y_Agent must not be overridden?

Copy link
Contributor

@didier-wenzek didier-wenzek Oct 19, 2023

Choose a reason for hiding this comment

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

The name and type fields are forbidden here because they're already part of the entity registration message. If someone wants to update these, they must send another registration message with the updated values. Allowing them to update the same data via both these endpoints will might be confusing especially in the broker as we may have different name and type in the device registration topic as well as in the twin/... topics.

Okay

I didn't really understand why you think c8y_Agent must not be overridden?

What if a user publish its own fragment on te/device/main///twin/c8y_Agent ?

Copy link
Contributor

Choose a reason for hiding this comment

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

What if a user publish its own fragment on te/device/main///twin/c8y_Agent

I don't really have a use-case for someone wanting to update that fragment for the thin-edge device, as we set that. But I don't have any strong arguments to close that option either. So, will need @reubenmiller 's advise on this. For child devices, we probably wouldn't want to prevent them from setting it. For services, this fragment probably doesn't even make any sense.

Copy link
Contributor

Choose a reason for hiding this comment

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

What if a user publish its own fragment on te/device/main///twin/c8y_Agent

I don't really have a use-case for someone wanting to update that fragment for the thin-edge device, as we set that. But I don't have any strong arguments to close that option either. So, will need @reubenmiller 's advise on this. For child devices, we probably wouldn't want to prevent them from setting it. For services, this fragment probably doesn't even make any sense.

Indeed, this would make no sense, but could be done by a user who fails to notice that this is already done by thin-edge as for the type. I that case there will be inconsistencies.

@albinsuresh albinsuresh temporarily deployed to Test Pull Request October 19, 2023 17:19 — 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. Nice feature and implementation!

docs/src/references/mappers/c8y-mapper.md Outdated Show resolved Hide resolved
docs/src/references/mappers/c8y-mapper.md Show resolved Hide resolved
@albinsuresh albinsuresh force-pushed the feat-tedge-inventory-topic branch from 0a1351f to d5f35fc Compare October 19, 2023 18:33
@albinsuresh albinsuresh temporarily deployed to Test Pull Request October 19, 2023 18:47 — with GitHub Actions Inactive
@albinsuresh albinsuresh merged commit 8948451 into thin-edge:main Oct 19, 2023
18 checks passed
@albinsuresh
Copy link
Contributor

Test Plan

The new twin topics and their mapping contracts are documented in the mqtt-api.md and c8y-mapper.md docs included in this PR. The basic feature is already covered in the system tests updated in the same PR: child_device_telemetry.robot and thin-edge_device_telemetry.robot. Tests for clearing inventory fragments will be added in a follow-up PR soon, as some Cumulocity library updates are required for it.

@albinsuresh albinsuresh changed the title feat(mqtt): add docs for tedge data/inventory topic MQTT twin/ topic support for Cumulocity inventory updates Oct 20, 2023
@reubenmiller reubenmiller deleted the feat-tedge-inventory-topic branch October 20, 2023 09:04
@gligorisaev
Copy link
Contributor

QA has thoroughly checked the feature and here are the results:

  • Test for ticket exists in the test suite.
  • tests/RobotFramework/tests/cumulocity/telemetry/child_device_telemetry.robot
  • tests/RobotFramework/tests/cumulocity/telemetry/thin-edge_device_telemetry.robot
  • tests/RobotFramework/tests/tedge/call_tedge_config_list.robot
  • QA has tested the bug and could not reproduce it anymore.

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 theme:telemetry Theme: Telemetry data
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants