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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

heowc
Copy link
Contributor

@heowc heowc commented May 5, 2024

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

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`
Comment on lines +72 to +76
final Function<UriBuilder, URI> uriFunction = builder -> builder.pathSegment("apps", appName, id)
.queryParam("status", info.getStatus().toString())
.queryParam("lastDirtyTimestamp", info.getLastDirtyTimestamp().toString()).queryParamIfPresent(
"overriddenstatus", Optional.ofNullable(overriddenStatus).map(InstanceStatus::name))
.build();
Copy link
Contributor Author

@heowc heowc May 5, 2024

Choose a reason for hiding this comment

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

Copy link

Choose a reason for hiding this comment

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

Related #4163, so I guess it should be accepted as there's a linked bug report.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems like a good idea.

@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.

@@ -69,8 +74,6 @@ public EurekaClientConfigBean eurekaClientConfigBean() {

@Bean
@ConditionalOnMissingBean(EurekaHttpClient.class)
@ConditionalOnProperty(prefix = "eureka.client", name = "webclient.enabled", matchIfMissing = true,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why remove 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.

From my analysis, it seems that previously, resttemplate was set as default even if webclient was disabled. However, after that, I felt that the above setting was a bit ambiguous because there are two options even if webclient is disabled. What do you think? 🤔

Copy link
Collaborator

Choose a reason for hiding this comment

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

We want to preserve the default behaviour and only add opt-in RestClient support at this point. We may want to change it in a major release at this point. If webClient is not enabled, we want to use RestTemplate, and there should be a similar @Conditional added for restClient as well.

@@ -68,8 +71,6 @@ public TlsProperties tlsProperties() {
@ConditionalOnClass(name = "org.springframework.web.client.RestTemplate")
@ConditionalOnMissingClass("org.glassfish.jersey.client.JerseyClient")
@ConditionalOnMissingBean(value = { AbstractDiscoveryClientOptionalArgs.class }, search = SearchStrategy.CURRENT)
@ConditionalOnProperty(prefix = "eureka.client", name = "webclient.enabled", matchIfMissing = true,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why remove this?

@@ -84,8 +85,6 @@ public RestTemplateDiscoveryClientOptionalArgs restTemplateDiscoveryClientOption
@ConditionalOnClass(name = "org.springframework.web.client.RestTemplate")
@ConditionalOnMissingClass("org.glassfish.jersey.client.JerseyClient")
@ConditionalOnMissingBean(value = { TransportClientFactories.class }, search = SearchStrategy.CURRENT)
@ConditionalOnProperty(prefix = "eureka.client", name = "webclient.enabled", matchIfMissing = true,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why remove this?

@@ -84,8 +85,6 @@ public RestTemplateDiscoveryClientOptionalArgs restTemplateDiscoveryClientOption
@ConditionalOnClass(name = "org.springframework.web.client.RestTemplate")
@ConditionalOnMissingClass("org.glassfish.jersey.client.JerseyClient")
@ConditionalOnMissingBean(value = { TransportClientFactories.class }, search = SearchStrategy.CURRENT)
@ConditionalOnProperty(prefix = "eureka.client", name = "webclient.enabled", matchIfMissing = true,
Copy link
Collaborator

Choose a reason for hiding this comment

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

A similar conditional for restclient.enabled should be added.

@@ -68,8 +71,6 @@ public TlsProperties tlsProperties() {
@ConditionalOnClass(name = "org.springframework.web.client.RestTemplate")
@ConditionalOnMissingClass("org.glassfish.jersey.client.JerseyClient")
@ConditionalOnMissingBean(value = { AbstractDiscoveryClientOptionalArgs.class }, search = SearchStrategy.CURRENT)
@ConditionalOnProperty(prefix = "eureka.client", name = "webclient.enabled", matchIfMissing = true,
Copy link
Collaborator

Choose a reason for hiding this comment

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

A similar conditional for restclient.enabled should be added.

search = SearchStrategy.CURRENT)
public RestClientDiscoveryClientOptionalArgs restClientDiscoveryClientOptionalArgs(TlsProperties tlsProperties,
ObjectProvider<RestClient.Builder> builder) throws GeneralSecurityException, IOException {
logger.info("Eureka HTTP Client uses RestClient.");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wrap with a logger.isInfoEnabled() check. Could you also add it to the other calls of this method in the class?

@@ -69,8 +74,6 @@ public EurekaClientConfigBean eurekaClientConfigBean() {

@Bean
@ConditionalOnMissingBean(EurekaHttpClient.class)
@ConditionalOnProperty(prefix = "eureka.client", name = "webclient.enabled", matchIfMissing = true,
Copy link
Collaborator

Choose a reason for hiding this comment

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

A similar conditional for restclient.enabled should be added.

import static com.netflix.discovery.shared.transport.EurekaHttpResponse.anEurekaHttpResponse;

/**
* @author Wonchul Heo
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add class description in the javadoc.

Comment on lines +72 to +76
final Function<UriBuilder, URI> uriFunction = builder -> builder.pathSegment("apps", appName, id)
.queryParam("status", info.getStatus().toString())
.queryParam("lastDirtyTimestamp", info.getLastDirtyTimestamp().toString()).queryParamIfPresent(
"overriddenstatus", Optional.ofNullable(overriddenStatus).map(InstanceStatus::name))
.build();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems like a good idea.

@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.


/**
* @author Wonchul Heo
*/
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add description in the class javadoc.

/**
* @author Wonchul Heo
*/
class RestClientTransportClientFactoryTest {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please rename to RestClientTransportClientFactoryTests.

transportClientFactory = new RestClientTransportClientFactory(RestClient::builder);
}

@Test
Copy link
Collaborator

Choose a reason for hiding this comment

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

All the tests methods need some kind of assertions to verify that whatever was expected to happen has, in fact, happened.

}

@Test
void testInvalidUserInfo() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's remove the test prefix from all the test method names.

}

@Test
void testWithoutUserInfo() {
transportClientFatory.newClient(new DefaultEndpoint("http://localhost:8761"));
transportClientFactory.newClient(new DefaultEndpoint("http://localhost:8761"));
Copy link
Collaborator

Choose a reason for hiding this comment

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

I know this code was already here, but as you're changing this area, can you please add appropriate assertions to all the test methods? and remove test prefix from the test method names?

@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.

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
5 participants