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

Change "127.0.0.1" to SIDECAR_IP to dynamically account for IPv4 vs. IPv6 environments #649

Merged
merged 48 commits into from
Feb 20, 2024

Conversation

willtsai
Copy link
Contributor

@willtsai willtsai commented Nov 4, 2021

Description

I've made some changes to move away from hardcoded "127.0.0.1" IP addresses (representing localhost) to make the SDK and Tests compatible with exclusively IPv6 environments:

  • Replaced hardcoded "127.0.0.1" in various URL strings with the SIDECAR_IP property constant
  • Changed the DEFAULT_SIDECAR_IP property constant's value from the hardcoded "127.0.0.1" to instead use the Java API getLoopbackAddress(). This would make the IP default value more dynamic and account for situations where users operate in an exclusively ipv6 environment and the logic ends up falling back to the default value.
  • Added a test util to detect IPv6 addresses and format them accordingly for HTTP URLs using the square brackets representation in unit tests

Issue reference

We strive to have all PR being opened based on an issue, where the problem or feature have been discussed prior to implementation.

Please reference the issue this PR will close: #218

Checklist

Please make sure you've completed the relevant tasks for this PR, out of the following list:

  • Code compiles correctly
  • Created/updated tests
  • Extended the documentation (N/A)

@willtsai willtsai requested review from a team as code owners November 4, 2021 06:09
@mukundansundar
Copy link
Contributor

@artursouza Wasn't there was a particular reason why 127.0.0.1 was used instead of localhost?

@willtsai
Copy link
Contributor Author

@artursouza Wasn't there was a particular reason why 127.0.0.1 was used instead of localhost?

@mukundansundar according to #213, it was changed from localhost to 127.0.0.1 "to avoid local OS specific DNS lookups that might hinder performance". My changes here don't reintroduce the use of localhost, but rather uses the dynamically sourced SIDECAR_IP constant from the system.

@willtsai willtsai changed the title Change "127.0.0.1" to SIDECAR_IP to dynamically account for IPv4 vs. IPv6 environments [WIP] Change "127.0.0.1" to SIDECAR_IP to dynamically account for IPv4 vs. IPv6 environments Nov 13, 2021
@willtsai
Copy link
Contributor Author

willtsai commented Dec 6, 2021

Work in progress, please do not merge

@willtsai willtsai changed the title [WIP] Change "127.0.0.1" to SIDECAR_IP to dynamically account for IPv4 vs. IPv6 environments Change "127.0.0.1" to SIDECAR_IP to dynamically account for IPv4 vs. IPv6 environments Jan 26, 2022
artursouza and others added 20 commits January 25, 2022 16:28
* Upgrade okhttp-mock dependency

Version 1.3.2 was never deployed to Maven Central

* No longer refer to JCenter, as it has been shut down

Signed-off-by: Will Tsai <[email protected]>
Signed-off-by: Will Tsai <[email protected]>
Signed-off-by: Will Tsai <[email protected]>
Bumps [actions/setup-java](https://github.com/actions/setup-java) from 2.3.1 to 2.4.0.
- [Release notes](https://github.com/actions/setup-java/releases)
- [Commits](actions/setup-java@v2.3.1...v2.4.0)

---
updated-dependencies:
- dependency-name: actions/setup-java
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Signed-off-by: Will Tsai <[email protected]>
* Upgrade Dapr CLI and runtime.

Signed-off-by: Artur Souza <[email protected]>

* Fix expected vault output.

Signed-off-by: Artur Souza <[email protected]>
Signed-off-by: Will Tsai <[email protected]>
* Update LICENSE to Apache 2.0

Signed-off-by: Artur Souza <[email protected]>

* Update headers to Apache 2.

Signed-off-by: Artur Souza <[email protected]>

Co-authored-by: Artur Souza <[email protected]>
Signed-off-by: Will Tsai <[email protected]>
Bumps [actions/github-script](https://github.com/actions/github-script) from 1 to 5.
- [Release notes](https://github.com/actions/github-script/releases)
- [Commits](actions/github-script@v1...v5)

---
updated-dependencies:
- dependency-name: actions/github-script
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Signed-off-by: Will Tsai <[email protected]>
Bumps [actions/setup-java](https://github.com/actions/setup-java) from 2.4.0 to 2.5.0.
- [Release notes](https://github.com/actions/setup-java/releases)
- [Commits](actions/setup-java@v2.4.0...v2.5.0)

---
updated-dependencies:
- dependency-name: actions/setup-java
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Artur Souza <[email protected]>
Signed-off-by: Will Tsai <[email protected]>
* inital draft for config api

Signed-off-by: Pravin Pushkar <[email protected]>

* Introducing new client for preview apis and code refactoring

Signed-off-by: Pravin Pushkar <[email protected]>

* Unit tests and code refactoring

Signed-off-by: Pravin Pushkar <[email protected]>

* Adding integration test

Signed-off-by: pravinpushkar <[email protected]>

* Copyright changes

Signed-off-by: pravinpushkar <[email protected]>

* Review comments fixes

Signed-off-by: pravinpushkar <[email protected]>

* Removed DaprPreviewClientProxy and updated example README

Signed-off-by: pravinpushkar <[email protected]>

* Adding validate workflow for cofiguration api example

Signed-off-by: pravinpushkar <[email protected]>

* fixing example autovalidation and code coverage

Signed-off-by: pravinpushkar <[email protected]>

* Fixing autovalidation and removing getAllConfiguration

Signed-off-by: pravinpushkar <[email protected]>

* Fixing review comments

Signed-off-by: pravinpushkar <[email protected]>

* Add regex header checkstyle.

Signed-off-by: Artur Souza <[email protected]>

* Fix headers and add javadocs to some.

Signed-off-by: Artur Souza <[email protected]>

Co-authored-by: Artur Souza <[email protected]>
Signed-off-by: Will Tsai <[email protected]>
Copy link
Member

@artursouza artursouza left a comment

Choose a reason for hiding this comment

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

I will give another pass tomorrow. Thanks.

Copy link
Member

@artursouza artursouza left a comment

Choose a reason for hiding this comment

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

Just a minor change.

* @return The loopback address String
*/
public static String getHostLoopbackAddress() {
return InetAddress.getLoopbackAddress().getHostAddress();
Copy link
Member

Choose a reason for hiding this comment

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

Can this method automatically return the Ipv6 between "[]"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@artursouza Sorry for the delay, finally had some time to look into this. I changed some unit tests locally to validate IPv6 sidecar IP constants contained within "[]" and it seems like your suggestion is viable - for both URL endpoint invocation formats and Dapr client instantiation. Great recommendation!

However, before I proceed, I need to validate an implementation detail with you. To test for whether an address is IPv6, it would be convenient to leverage the Apache Commons Validator, though you have recommended against bringing in 3P libraries beyond the test scope. Is it possible to get an exception for this case, or do I have to write a custom IPv6 validator within NetworkUtils?

Copy link
Contributor

Choose a reason for hiding this comment

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

@willtsai Is it complex to write a validator for IPv6 ? both standard pattern and hex compressed pattern along with IPv4 validation?
I am wary of adding a new dependency specifically for one validation ....

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Understood - should not be too complex but I wanted to see if the work (and subsequent unit tests) could be avoided. Seems like adding a new dependency is not worth it here, so I'll work on the custom validator.

Copy link
Contributor Author

@willtsai willtsai Jul 12, 2022

Choose a reason for hiding this comment

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

I started the implementation for this and have a working validator, but then realized that this would introduce inconsistencies into the Property<String> SIDECAR_IP config object since the result would be that the special IPv6 formatting would only get applied when DEFAULT_SIDECAR_IP is used in fallback scenarios, so the IPv6 address would not get "[]" applied to them when they are sourced from the system property name or env variable.

Thus, I think there are two options:

  1. Leave the implementation of adding "[]" to the http address to the client and thus just modifying our test clients accordingly, i.e. code in this PR remain as is.
  2. Make modifications to the Property and/or Properties objects to introduce a new object class IpProperty.java or equivalent that would apply the required IPv6 formatting to the IP address it returns.

@artursouza @mukundansundar - what are your thoughts here? which option would you prefer? (I personally think option 1 introduces less surprises to the client who may not be expecting IPv6 address to be pre-formatted for http URLs)

@cicoyle
Copy link
Contributor

cicoyle commented Dec 21, 2023

@willtsai mind resolving the conflicts?

@willtsai
Copy link
Contributor Author

willtsai commented Jan 2, 2024

@willtsai mind resolving the conflicts?

@cicoyle done, though now i need to investigate the test failures...

@willtsai
Copy link
Contributor Author

willtsai commented Jan 4, 2024

@cicoyle i've addressed all merge conflicts and test failures, can you please take another look? (i think the build tests just need to be re-run)

Copy link

codecov bot commented Feb 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (14cc3f8) 77.60% compared to head (d9fd2c0) 77.61%.
Report is 4 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##             master     #649   +/-   ##
=========================================
  Coverage     77.60%   77.61%           
- Complexity     1570     1571    +1     
=========================================
  Files           144      144           
  Lines          4765     4767    +2     
  Branches        554      554           
=========================================
+ Hits           3698     3700    +2     
  Misses          781      781           
  Partials        286      286           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@cicoyle cicoyle left a comment

Choose a reason for hiding this comment

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

lgtm - nice to see this coming to a closing 🎉

@artursouza artursouza merged commit 57b86c5 into dapr:master Feb 20, 2024
9 of 10 checks passed
@willtsai
Copy link
Contributor Author

woo! thanks @cicoyle @artursouza 🥳

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.

The sdk should auto-detect ipv4 loopback and ipv6 loopback for daprd communication.
8 participants