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

Entity store: change constructors to remove redundant clones and rename fields #2176

Merged
merged 2 commits into from
Aug 22, 2023

Conversation

Bravo555
Copy link
Contributor

@Bravo555 Bravo555 commented Aug 21, 2023

Proposed changes

  • Change EntityTopic and EntityRegistrationMessage TryInto impls to take references instead of values, removing
    needless clones
  • Renamed external_id to entity_id (it was already used in thin-edge documentation as device id or service id) and mqtt_id to topic_id

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

@Bravo555 Bravo555 changed the title Entity store Entity store: change constructors to remove redundant clones and remove fields Aug 21, 2023
@Bravo555 Bravo555 changed the title Entity store: change constructors to remove redundant clones and remove fields Entity store: change constructors to remove redundant clones and rename fields Aug 21, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Aug 21, 2023

Robot Results

✅ Passed ❌ Failed ⏭️ Skipped Total Pass %
257 0 5 257 100

Comment on lines 15 to 22
/// Represents an "MQTT entity identifier" portion of the MQTT topic
/// Represents an "Entity MQTT address" portion of the MQTT topic
///
/// Example:
/// - topic: `te/device/dev1/service/myservice/m//my_measurement
/// - topic: `te/device/dev1/service/myservice/m//my_measurement`
/// - entity id: `device/dev1/service/myservice`
///
/// <https://thin-edge.github.io/thin-edge.io/next/references/mqtt-api/#group-identifier>
type EntityId = String;
type EntityMqttAddress = String;
Copy link
Contributor

Choose a reason for hiding this comment

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

@Bravo555, @reubenmiller, @albinsuresh

I'm not fully happy with this proposal for a new name:

Pros:

  • EntityId is definitely confusing, knowing that device id is already used with a different meaning: (the main device id is the CN of its certificate while its entity identifier is device/main//.

Cons:

  • The specifications uses the term entity identifier.
  • The address suffix of EntityMqttAddress might be confused with some kind of network address.
  • This identifier is used only for MQTT topics. Hence, I would expect the term topic rather than address

What about EntityTopicId or EntityMqttTopicId ?

Alternative

Another way to solve the issue is t:

  • keep the terms EntityId and entity identifier, when speaking about topics.
  • use the terms EntityName and entity name, when speaking about the CommonName (CN) of these devices.

Important

In any case, the terms used in the code base must be the same as those used in the docs.

Copy link
Contributor

Choose a reason for hiding this comment

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

We agreed to use the name EntityTopicId for entity identifiers in the new topic scheme.

Comment on lines 167 to 170

let external_id = message
.external_id
.unwrap_or_else(|| self.derive_external_id(&message.mqtt_id));
let entity_id = message
.entity_id
.unwrap_or_else(|| self.derive_entity_id(&message.mqtt_id));
Copy link
Contributor

Choose a reason for hiding this comment

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

This change is really good one, as external id has a specific meaning in the context of c8y.

@Bravo555 Bravo555 temporarily deployed to Test Pull Request August 22, 2023 10:01 — with GitHub Actions Inactive
@Bravo555 Bravo555 temporarily deployed to Test Pull Request August 22, 2023 11:29 — with GitHub Actions Inactive
@codecov
Copy link

codecov bot commented Aug 22, 2023

Codecov Report

Merging #2176 (083d4c1) into main (d35823f) will decrease coverage by 0.1%.
Report is 6 commits behind head on main.
The diff coverage is 82.1%.

❗ Current head 083d4c1 differs from pull request most recent head c3371c1. Consider uploading reports for the commit c3371c1 to get more accurate results

Additional details and impacted files
Files Changed Coverage Δ
crates/extensions/c8y_mapper_ext/src/actor.rs 68.2% <41.6%> (+0.6%) ⬆️
crates/core/tedge_api/src/entity_store.rs 88.8% <88.7%> (-2.9%) ⬇️
crates/core/tedge_api/src/entity.rs 82.1% <100.0%> (+3.9%) ⬆️

... and 5 files with indirect coverage changes

Because we need to clone anyway while constructing `EntityTopic` and
`EntityRegistrationTopic`, the `TryFrom` impls were changed to convert
from references instead of values.

Signed-off-by: Marcel Guzik <marcel.guzik@inetum.com>
Because the name `external_id` was not used anywhere else to refer to
the identifiers of devices and services on the cloud, it was renamed in
favour of `entity_id`, which covers device ids and service ids.

`mqtt_id` was renamed to `topic_id`.

Signed-off-by: Marcel Guzik <marcel.guzik@inetum.com>
@Bravo555 Bravo555 temporarily deployed to Test Pull Request August 22, 2023 11:55 — 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

@didier-wenzek didier-wenzek merged commit 75127c6 into thin-edge:main Aug 22, 2023
18 checks passed
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