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

Abstract thin-edge MQTT topic schema #2189

Merged
merged 7 commits into from
Aug 28, 2023

Conversation

didier-wenzek
Copy link
Contributor

@didier-wenzek didier-wenzek commented Aug 24, 2023

Proposed changes

  • Add struct MqttSchema abstracting all topic definitions
  • Deprecate struct EntityTopic
  • Improve the Channel type to abstract away all topic parsing.

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


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

@codecov
Copy link

codecov bot commented Aug 24, 2023

Codecov Report

Merging #2189 (a341a31) into main (81b9d51) will decrease coverage by 0.1%.
The diff coverage is 80.4%.

❗ Current head a341a31 differs from pull request most recent head 5d28f11. Consider uploading reports for the commit 5d28f11 to get more accurate results

Additional details and impacted files
Files Changed Coverage Δ
crates/core/tedge_api/src/lib.rs 100.0% <ø> (ø)
crates/extensions/c8y_mapper_ext/src/actor.rs 70.6% <ø> (ø)
crates/core/tedge_api/src/mqtt_topics.rs 75.4% <75.4%> (ø)
crates/extensions/c8y_mapper_ext/src/converter.rs 78.0% <87.5%> (+0.9%) ⬆️
crates/core/tedge_api/src/entity_store.rs 91.0% <93.2%> (-0.6%) ⬇️

... and 5 files with indirect coverage changes

@didier-wenzek didier-wenzek temporarily deployed to Test Pull Request August 24, 2023 16:11 — with GitHub Actions Inactive
@github-actions
Copy link
Contributor

github-actions bot commented Aug 24, 2023

Robot Results

✅ Passed ❌ Failed ⏭️ Skipped Total Pass % ⏱️ Duration
257 0 5 257 100 46m36.261s

@didier-wenzek didier-wenzek marked this pull request as ready for review August 24, 2023 19:14
@didier-wenzek didier-wenzek temporarily deployed to Test Pull Request August 24, 2023 19:23 — with GitHub Actions Inactive
crates/core/tedge_api/src/mqtt_topics.rs Outdated Show resolved Hide resolved
crates/core/tedge_api/src/mqtt_topics.rs Outdated Show resolved Hide resolved
Comment on lines -105 to 107
#[async_trait]
pub trait Converter: Send + Sync {
type Error: Display;

fn get_mapper_config(&self) -> &MapperConfig;

async fn try_convert(&mut self, input: &Message) -> Result<Vec<Message>, Self::Error>;

async fn convert(&mut self, input: &Message) -> Vec<Message> {
impl CumulocityConverter {
pub async fn convert(&mut self, input: &Message) -> Vec<Message> {
let messages_or_err = self.try_convert(input).await;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The Converter trait has been removed as implemented only once.

There are now several impl CumulocityConverter { ... } parts in this file. This has been done on purpose to ease this PR review. It would be good to reorganize this later.

Comment on lines +667 to +670
match self.mqtt_schema.entity_channel_of(&message.topic) {
Ok((source, channel)) => self.try_convert_te_topics(source, channel, message).await,
Err(_) => self.try_convert_tedge_topics(message).await,
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

To ease the transition there is now two separate methods, each used for a specific topic schema.

The end goal is to get rid of try_convert_tedge_topics.

@didier-wenzek didier-wenzek temporarily deployed to Test Pull Request August 24, 2023 20:11 — with GitHub Actions Inactive
@didier-wenzek didier-wenzek temporarily deployed to Test Pull Request August 25, 2023 13:38 — with GitHub Actions Inactive
@didier-wenzek didier-wenzek temporarily deployed to Test Pull Request August 26, 2023 16:00 — with GitHub Actions Inactive
@didier-wenzek didier-wenzek temporarily deployed to Test Pull Request August 28, 2023 08:54 — with GitHub Actions Inactive
crates/core/tedge_api/src/mqtt_topics.rs Outdated Show resolved Hide resolved
crates/core/tedge_api/src/mqtt_topics.rs Outdated Show resolved Hide resolved
crates/core/tedge_api/src/mqtt_topics.rs Outdated Show resolved Hide resolved
crates/core/tedge_api/src/mqtt_topics.rs Show resolved Hide resolved
crates/extensions/c8y_mapper_ext/src/error.rs Outdated Show resolved Hide resolved
@didier-wenzek didier-wenzek temporarily deployed to Test Pull Request August 28, 2023 13:28 — with GitHub Actions Inactive
The aim of this module is to abstract the MQTT topics used by thin-edge.
Entities, such as devices and services, have to be described by the
`entity_store` module.

Signed-off-by: Didier Wenzek <didier.wenzek@free.fr>
This is just a sketch of the API.
The implementation is done using the former `EntityTopic` concept.
The latter will be deprecated in the following steps.

Signed-off-by: Didier Wenzek <didier.wenzek@free.fr>
Signed-off-by: Didier Wenzek <didier.wenzek@free.fr>
To ease the transition phase where messages are sent over `tedge/#`
while others use `te/#`, the c8y converter main conversion method
has been broken in two parts: te vs tedge.

Signed-off-by: Didier Wenzek <didier.wenzek@free.fr>
Signed-off-by: Didier Wenzek <didier.wenzek@free.fr>
EntityId is confusing when used for devices which already have an id.

Signed-off-by: Didier Wenzek <didier.wenzek@free.fr>
Signed-off-by: Didier Wenzek <didier.wenzek@free.fr>
@didier-wenzek didier-wenzek temporarily deployed to Test Pull Request August 28, 2023 15:44 — with GitHub Actions Inactive
@didier-wenzek didier-wenzek merged commit 0270f5c into thin-edge:main Aug 28, 2023
17 of 18 checks passed
@didier-wenzek didier-wenzek deleted the feat/mqtt-topic-scheme branch August 28, 2023 16:06
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