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

Support Spring RestClient as TransportClientFactory #4281

Merged
merged 23 commits into from
Nov 4, 2024

Conversation

heowc
Copy link
Contributor

@heowc heowc commented May 5, 2024

Change RestClient to default eureka client. This changes the default behavior.

  • Changed from RestTemplate to RestClient
  • Related tests have also been changed

Add related classes

  • RestClientDiscoveryClientOptionalArgs
  • RestClientEurekaHttpClient
  • RestClientTransportClientFactories
  • RestClientTransportClientFactory

Add property

  • eureka.client.restclient.enabled (default false)

Move commonly used classes

  • NotFoundHttpResponse
  • EurekaHttpClientUtils

Edit the document

Added similar tests referring to RestTemplate and WebClient

Close #4257

Add related classes
- `RestClientDiscoveryClientOptionalArgs`
- `RestClientEurekaHttpClient`
- `RestClientTransportClientFactories`
- `RestClientTransportClientFactory`

Add property
- `eureka.client.restclient.enabled` (default `false`)

Change auto-configure
- `RestTemplate`-related settings for `webclient.enabled=false` have been removed. `restclient.enabled` makes it meaningless

Move commonly used classes
- `NotFoundHttpResponse`
- `EurekaHttpClientUtils`

Edit the document

Added similar tests referring to `RestTemplate` and `WebClient`
@heowc
Copy link
Contributor Author

heowc commented May 5, 2024

Could you please inform me if there are any plans to phase out RestTemplate related implementations in the future? 🤔

@injae-kim
Copy link

FYI) target issue: #4257

@heowc
Copy link
Contributor Author

heowc commented Jun 20, 2024

gentle ping 😄

@OlgaMaciaszek
Copy link
Collaborator

Thanks @heowc, will take a look. We do not have a plan for phasing out RestTemplate at this point.

Copy link
Collaborator

@OlgaMaciaszek OlgaMaciaszek left a comment

Choose a reason for hiding this comment

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

Thanks, @heowc. So far, have only looked at the docs - please implement the suggestion. Will continue the review of this PR tomorrow.

docs/modules/ROOT/pages/spring-cloud-netflix.adoc Outdated Show resolved Hide resolved
@heowc heowc requested a review from OlgaMaciaszek June 29, 2024 05:55
Copy link
Collaborator

@OlgaMaciaszek OlgaMaciaszek left a comment

Choose a reason for hiding this comment

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

Thanks @heowc. Have added some comments - please take a look. Will continue this review tomorrow.

@OlgaMaciaszek
Copy link
Collaborator

Fixes gh-4257.

Copy link
Collaborator

@OlgaMaciaszek OlgaMaciaszek left a comment

Choose a reason for hiding this comment

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

Thanks a lot for working on it @heowc. This concludes the first review pass on this PR. Please address the comments I've added and let me know when it's ready for another pass.
Also, please make sure to update the date in license file comments in all the classes you've modified to end with -2022, add your full name and surname with the @author tag to the javadocs to all the classes you've modified, and add @since 4.1.3 to the javadocs of all the production classes you've added.

@OlgaMaciaszek
Copy link
Collaborator

Hi @heowc, I have pushed a fix in the same area: b23c587. Please merge the code and resolve any conflict before proceeding with working on this PR.

heowc added 5 commits October 3, 2024 23:03
# Conflicts:
#	docs/modules/ROOT/partials/_configprops.adoc
#	spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/config/DiscoveryClientOptionalArgsConfiguration.java
#	spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/http/RestTemplateTransportClientFactory.java
#	spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/config/EurekaHttpClientsOptionalArgsConfigurationTests.java
Copy link
Collaborator

@OlgaMaciaszek OlgaMaciaszek left a comment

Choose a reason for hiding this comment

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

Thanks, @heowc. Have added some comments. Please take a look. Also, please merge the changes from origin/main, since I've modified some tests that may cause a conflict: 44e22ad.

final ResponseEntity<String> response = restClient.get().uri("http://localhost:" + port).retrieve()
.toEntity(String.class);

assertThat(response).isNotNull();
Copy link
Collaborator

Choose a reason for hiding this comment

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

What I mean is that we're testing a call done by RestClient, which is a component provided by Spring Framework and tested very well itself. What we should do is instead use RestClientEurekaHttpClient to do the call, and then verify its result.

@@ -109,6 +114,22 @@ public WebClientEurekaHttpClient configDiscoveryWebClientEurekaHttpClient(Eureka

}

@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(name = "org.springframework.web.client.RestClient")
@ConditionalOnProperty(prefix = "eureka.client", name = "restclient.enabled", havingValue = "true")
Copy link
Collaborator

Choose a reason for hiding this comment

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

After some more consideration, I actually think we could switch to using RestClient by default in case of the non-blocking stack, so let's add matchIfMissing=true and @ConditionalOnProperty(prefix = "eureka.client", name = "restclient.enabled", havingValue = "false") to the RestTemplate-based configuration. Sorry for the confusion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added related conditions while changing JerseyClientNotPresentOrNotEnabledCondition to RestTemplateEnabledCondition. Is this what you intended? 🤔

Copy link
Collaborator

Choose a reason for hiding this comment

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

No, the logic after your changes has been modified - please take a look at the review comments.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

스크린샷 2024-10-27 오후 10 53 08

I think I understood it a little differently, but I think you should change JerseyClientNotPresentOrNotEnabledCondition to RestTemplateEnabledCondition for the same issue. Don't you think so??

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If there is something I misunderstood, please let me know.

  1. Modify the eureka.client.restclient.enabled annotation I added as follows.
@ConditionalOnProperty(prefix = "eureka.client", name = "restclient.enabled", havingValue = "true")

->

@ConditionalOnProperty(prefix = "eureka.client", name = "restclient.enabled", havingValue = "true", matchIfMissing = true)
  1. Then, set the following annotation to the configuration beans that are set based on RestTemplate.
@ConditionalOnProperty(prefix = "eureka.client", name = "restclient.enabled", havingValue = "false")

However, if I set it like this, some tests will fail. The reason is that matchIfMissing is changed so that it should default to RestTemplate, but it changes to RestClient, or even RestTemplate is not set, so the bean is not configured.

Copy link
Collaborator

@OlgaMaciaszek OlgaMaciaszek left a comment

Choose a reason for hiding this comment

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

Thanks @heowc. Have added additional comments. Please take a look.

Copy link
Collaborator

@OlgaMaciaszek OlgaMaciaszek left a comment

Choose a reason for hiding this comment

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

Hi @heowc, thanks for adding changes and comments. I have tried to further clarify the configuration setup by adding some comments to the code changes along with reasoning behind them. If possible, please add the changes discussed till the end of this week. If you don't have the time, no worries, however, since I want to make sure we get this feature into the upcoming RC, if this is not ready, then on Mon, I will cherry-pick your changes and add any necessary changes on top of them. Thank you for all your work on this PR (and others).

}

@ConditionalOnProperty(prefix = "eureka.client", name = "restclient.enabled", matchIfMissing = true,
havingValue = "false")
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should not be matchIfMissing=true. Since we now want the RestClient based implementation to be default, we only want to do RestTemplate if RestClient is explicitly disabled.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was really hoping that the default would change while working on this issue (it's too complicated).
Is this direction related to the issue below?
#4347

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, we would like to change the default here to RestClient. That is why we don't want to use RestTemplate unless RestClient is explicitly disabled.

@heowc
Copy link
Contributor Author

heowc commented Oct 31, 2024

Hi @heowc, thanks for adding changes and comments. I have tried to further clarify the configuration setup by adding some comments to the code changes along with reasoning behind them. If possible, please add the changes discussed till the end of this week. If you don't have the time, no worries, however, since I want to make sure we get this feature into the upcoming RC, if this is not ready, then on Mon, I will cherry-pick your changes and add any necessary changes on top of them. Thank you for all your work on this PR (and others).

Thank you for reviewing this issue for a rather long time. I was fixed everything in response to your comments, but if you have any other suggestions, please let us know.

Of course, there were some test modifications with the changed direction. Please take note.

@heowc heowc requested a review from OlgaMaciaszek October 31, 2024 14:20
@heowc
Copy link
Contributor Author

heowc commented Nov 3, 2024

Hello @OlgaMaciaszek,
As you mentioned, I've modified the setup, testing, and documentation to make RestClient the default client.

See #4281 (comment)

Copy link
Collaborator

@OlgaMaciaszek OlgaMaciaszek left a comment

Choose a reason for hiding this comment

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

LGTM, @heowc. Thanks for relentlessly working on this.

@OlgaMaciaszek OlgaMaciaszek merged commit c2c5352 into spring-cloud:main Nov 4, 2024
1 check passed
@heowc heowc deleted the feature/4257 branch November 5, 2024 07:51
@injae-kim
Copy link

Nice work @heowc !!! also thanks for the kind review @OlgaMaciaszek 👍👍👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support Spring RestClient as TransportClientFactory and make it the default implementation
6 participants