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

azure tedge mapper fails to translate health status messages #2273

Merged
merged 1 commit into from
Sep 25, 2023

Conversation

PradeepKiruvale
Copy link
Contributor

@PradeepKiruvale PradeepKiruvale commented Sep 20, 2023

Proposed changes

Issue:
Azure mapper converter was failing to translate the service health message timestamp, because it's an integer number.

Proposed solution/fix:
Forward the health status message payload to Azure Cloud without translating.

As a followup tasks

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

#2256

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

@PradeepKiruvale PradeepKiruvale temporarily deployed to Test Pull Request September 20, 2023 04:58 — with GitHub Actions Inactive
@codecov
Copy link

codecov bot commented Sep 20, 2023

Codecov Report

Merging #2273 (47248f9) into main (7e6da86) will increase coverage by 0.0%.
Report is 19 commits behind head on main.
The diff coverage is 100.0%.

Additional details and impacted files
Files Changed Coverage Δ
crates/extensions/az_mapper_ext/src/error.rs 0.0% <ø> (ø)
crates/extensions/az_mapper_ext/src/converter.rs 97.3% <100.0%> (+0.4%) ⬆️

... and 28 files with indirect coverage changes

@github-actions
Copy link
Contributor

github-actions bot commented Sep 20, 2023

Robot Results

✅ Passed ❌ Failed ⏭️ Skipped Total Pass % ⏱️ Duration
273 0 5 273 100 52m49.136s

Comment on lines 57 to 69
let mut payload_json: Map<String, Value> =
serde_json::from_slice(input.payload.as_bytes())?;
if let Some(timestamp) = default_timestamp {
let timestamp = timestamp
.format(&time::format_description::well_known::Rfc3339)?
.as_str()
.into();
payload_json.entry("time").or_insert(timestamp);
}
let payload = serde_json::to_string(&payload_json)?;
Ok(vec![
(MqttMessage::new(&self.mapper_config.out_topic, payload)),
])
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not simply publish the health status message unchanged?

This piece of code will only add a timestamp to down status (the only ones without a time field).
And this done using a different time format as for the up status (as demonstrated by the converting_service_health_status test).

An alternative, is to rewrite the time field if not using the RFC 3339 format.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we can push the whole time stamp without doing any sort of translation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why not simply publish the health status message unchanged?

This piece of code will only add a timestamp to down status (the only ones without a time field). And this done using a different time format as for the up status (as demonstrated by the converting_service_health_status test).

An alternative, is to rewrite the time field if not using the RFC 3339 format.

@reubenmiller what's your thought on this? Shall we translate the time to RFC 3339 format or send out the message as it comes in?

Copy link
Contributor

Choose a reason for hiding this comment

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

We need to be consistent, otherwise we'll have the same problem as we have in #2237.

I would align to what the majority is or if you can find best practises in azure about timestamps. RFC3339 is more human readable but less machine readable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@didier-wenzek The root cause is the API health_status_up_message(daemon_name: &str) where the timestamp is added as a Unix timestamp. So, shall we add in RFC 3339 format while adding a timestamp to the status message? then it will resolve all the issues and no need to re-write while parsing.

Copy link
Contributor

Choose a reason for hiding this comment

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

So, shall we add in RFC 3339 format while adding a timestamp to the status message?

Indeed an idea to consider.

Copy link
Member

@rina23q rina23q left a comment

Choose a reason for hiding this comment

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

Some comments.

  1. Tests are missing! I believe adding them to converter.rs is the right thing.

  2. I'm not fully sure if I knew the requirements correctly. So, azure converter should translate these kind of messages?

From

[tedge/health/tedge-mapper-az] {"pid":51367,"status":"down"}
[tedge/health/tedge-mapper-az] {"pid":13280,"status":"up","time":1675330667}

To

[az/messages/events/] {"pid":51367,"status":"down"}
[az/messages/events/] {"pid":13280,"status":"up","time": 2023-09-20T14:37:49+00:00}

if is_bridge_health(&input.topic.name) {
Ok(vec![])
} else if input.topic.name.starts_with("tedge/health") {
Copy link
Member

Choose a reason for hiding this comment

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

This check is too wild. The mapper subscribes to tedge/health/+ and tedge/health/+/+. Therefore, for example, I think this c8y message will be translated by the azure mapper.

tedge mqtt pub tedge/health/tedge-mapper-c8y '{"pid":19753,"status":"up","time":1694586060}'

Copy link
Contributor

Choose a reason for hiding this comment

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

@rina23q Though shouldn't the az mapper forward all service status messages that are published in the json format? It should not care which service is actually behind it, as you can use Azure to monitor the c8y service.

Copy link
Member

@rina23q rina23q Sep 21, 2023

Choose a reason for hiding this comment

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

@reubenmiller Ah okay, but then simple forwarding the payload {"pid":19753,"status":"up","time":1694586060} to the topic az/messages/events/ is not enough. How can user know which service is behind the message?

Honestly speaking, I'm still confused what is preferred conversion output for azure.

Copy link
Contributor

Choose a reason for hiding this comment

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

@rina23q very good point regarding the sourceless messages about the service, though I think this will require more thought. Child devices are modelled as components using the $.sub nomenclature, but there isn't a great strategy for handling services of components.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It may be for another PR, but I feel maybe we can use the {property-bag} messages to send extra information. Find more info here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes we can do the adjustments to how to communicate which service it is in a follow service. Though someone needs to point some thought into how to do this following the best practices of Azure IoT Hub.

@PradeepKiruvale Can you create a follow up ticket?

crates/extensions/az_mapper_ext/src/converter.rs Outdated Show resolved Hide resolved
@PradeepKiruvale
Copy link
Contributor Author

Some comments.

  1. Tests are missing! I believe adding them to converter.rs is the right thing.
  2. I'm not fully sure if I knew the requirements correctly. So, azure converter should translate these kind of messages?

From

[tedge/health/tedge-mapper-az] {"pid":51367,"status":"down"}
[tedge/health/tedge-mapper-az] {"pid":13280,"status":"up","time":1675330667}

To

[az/messages/events/] {"pid":51367,"status":"down"}
[az/messages/events/] {"pid":13280,"status":"up","time": 2023-09-20T14:37:49+00:00}

Some comments.

  1. Tests are missing! I believe adding them to converter.rs is the right thing.
  2. I'm not fully sure if I knew the requirements correctly. So, azure converter should translate these kind of messages?

From

[tedge/health/tedge-mapper-az] {"pid":51367,"status":"down"}
[tedge/health/tedge-mapper-az] {"pid":13280,"status":"up","time":1675330667}

To

[az/messages/events/] {"pid":51367,"status":"down"}
[az/messages/events/] {"pid":13280,"status":"up","time": 2023-09-20T14:37:49+00:00}

I already added a test with time.I will add it without a time stamp.

@PradeepKiruvale PradeepKiruvale marked this pull request as draft September 22, 2023 01:30
@PradeepKiruvale PradeepKiruvale marked this pull request as ready for review September 22, 2023 03:11
@PradeepKiruvale PradeepKiruvale temporarily deployed to Test Pull Request September 22, 2023 03:17 — with GitHub Actions Inactive
Copy link
Member

@rina23q rina23q left a comment

Choose a reason for hiding this comment

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

Looks a good bug fix!

Signed-off-by: Pradeep Kumar K J <pkj@softwareag.com>
@PradeepKiruvale PradeepKiruvale temporarily deployed to Test Pull Request September 22, 2023 10: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

@PradeepKiruvale PradeepKiruvale merged commit be351da into thin-edge:main Sep 25, 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

4 participants