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

fix: Honor c8y.mqtt setting on tedge connect #2789

Merged
merged 2 commits into from
Mar 28, 2024

Conversation

albinsuresh
Copy link
Contributor

@albinsuresh albinsuresh commented Mar 18, 2024

Proposed changes

  • Use the port specified in c8y.mqtt setting while establishing direct connection to c8y on tedge connect c8y
  • Refactor BridgeConfig to use HostPort instead of separate host and port settings

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

Copy link
Contributor

github-actions bot commented Mar 18, 2024

Robot Results

✅ Passed ❌ Failed ⏭️ Skipped Total Pass % ⏱️ Duration
428 0 3 428 100 0s

@reubenmiller reubenmiller changed the title fix: Honor c8y.mqtt setting on tedge connect #2787 fix: Honor c8y.mqtt setting on tedge connect Mar 20, 2024
@reubenmiller reubenmiller added theme:mqtt Theme: mqtt and mosquitto related topics theme:c8y Theme: Cumulocity related topics labels Mar 20, 2024
@albinsuresh albinsuresh requested a review from a team as a code owner March 20, 2024 15:31
@albinsuresh albinsuresh temporarily deployed to Test Pull Request March 20, 2024 15:31 — with GitHub Actions Inactive
Copy link

codecov bot commented Mar 20, 2024

Codecov Report

Attention: Patch coverage is 53.96825% with 29 lines in your changes are missing coverage. Please review.

Project coverage is 76.6%. Comparing base (d55ddd2) to head (2fa7266).
Report is 5 commits behind head on main.

Additional details and impacted files
Files Coverage Δ
.../common/tedge_config/src/tedge_config_cli/error.rs 21.0% <ø> (ø)
...ge_config/src/tedge_config_cli/models/host_port.rs 76.5% <100.0%> (+9.1%) ⬆️
...n/tedge_config/src/tedge_config_cli/models/port.rs 75.0% <100.0%> (ø)
crates/core/tedge/src/bridge/aws.rs 98.1% <50.0%> (-1.0%) ⬇️
crates/core/tedge/src/bridge/azure.rs 98.1% <66.6%> (-1.0%) ⬇️
crates/core/tedge/src/bridge/c8y.rs 88.1% <33.3%> (-0.9%) ⬇️
crates/core/tedge/src/cli/certificate/upload.rs 61.8% <0.0%> (ø)
crates/core/c8y_api/src/http_proxy.rs 71.6% <73.6%> (-0.2%) ⬇️
crates/core/tedge/src/bridge/config.rs 81.5% <28.5%> (-2.8%) ⬇️
...ore/tedge/src/cli/connect/c8y_direct_connection.rs 0.0% <0.0%> (ø)
... and 1 more

... and 6 files with indirect coverage changes

Comment on lines +111 to +116
// The configured `c8y.http` setting may have a port value specified,
// but the incoming URL is less likely to have any port specified.
// Hence just matching the host prefix.
Copy link
Contributor Author

@albinsuresh albinsuresh Mar 22, 2024

Choose a reason for hiding this comment

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

The other option was to change the C8yEndPoint::c8y_host field into a HostPort and just validate the host part of it against the incoming host. But, that would be have been a huge change needing the generic port parameter <P> to be added to C8yEndPoint as well, since HostPort<P> is generic.

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.

The system test "tedge-agent should terminate on SIGINT while downloading file" is failing, because the url http://localhost/speedlimit/10MB is erroneously rewritten http://127.0.0.1:8001/c8y/speedlimit/10MB, preventing the download to start.

Copy link
Contributor

@Bravo555 Bravo555 left a comment

Choose a reason for hiding this comment

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

Found one thing I'm unsure of, otherwise LGTM

crates/core/c8y_api/src/http_proxy.rs Outdated Show resolved Hide resolved
@albinsuresh albinsuresh temporarily deployed to Test Pull Request March 28, 2024 09:39 — with GitHub Actions Inactive
let url = Url::parse(url).ok()?;
let url_host = url.domain()?;

let (_, host) = url_host.split_once('.').unwrap_or((url_host, ""));
let (_, c8y_host) = tenant_uri.split_once('.').unwrap();
let (_, c8y_host) = tenant_host.split_once('.').unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure this unwrap is safe. What's about a C8Y Edge tenant known only by its host name?

Copy link
Contributor Author

@albinsuresh albinsuresh Mar 28, 2024

Choose a reason for hiding this comment

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

Yeah, this is something that @reubenmiller and I were discussing in the morning and the conclusion was that this whole subdomain based check is fragile and must be replaced with a proper check that retrieves the real tenant URL behind any custom domain and validates the incoming URL against that. But, since that work is a bit more involved, we decided to create a separate issue for that, and just resolve the port aspect in this PR (keeping the existing fragile mechanism as-is for now).

Copy link
Contributor

Choose a reason for hiding this comment

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

So, let's go with this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here is ticket for the custom domain issue: #2804

In the mean time, I've just updated the unwrap logic to at least avoid a panic.

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

@albinsuresh albinsuresh force-pushed the fix/2787/use-c8y-mqtt-port branch from 282bfb8 to 2fa7266 Compare March 28, 2024 11:30
@albinsuresh albinsuresh temporarily deployed to Test Pull Request March 28, 2024 11:30 — with GitHub Actions Inactive
@albinsuresh albinsuresh added this pull request to the merge queue Mar 28, 2024
Merged via the queue into thin-edge:main with commit 92f140d Mar 28, 2024
32 checks passed
@albinsuresh albinsuresh deleted the fix/2787/use-c8y-mqtt-port branch April 17, 2024 06:51
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:mqtt Theme: mqtt and mosquitto related topics
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants