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: Ribbon Implementation Does not Support "https" when using Eureka / Service Discovery #231

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

Conversation

gmcouto
Copy link

@gmcouto gmcouto commented May 11, 2020

This PR is meant to make url expander implementation to consider eureka data and change schema to https when necessary

Fixes #230

@@ -24,7 +25,7 @@
*/
public class RibbonPublisherClient implements PublisherHttpClient {

private final LazyInitialized<LoadBalancerCommand<Object>> loadBalancerCommand;
private final LazyInitialized<LoadBalancerCommand<Object>> loadBalancerCommand;

Choose a reason for hiding this comment

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

please revert whitespaces changes

.host(server.getHost())
.scheme(scheme)
Copy link
Collaborator

@kptfh kptfh May 12, 2020

Choose a reason for hiding this comment

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

can we simply use here server.getScheme() instead all this logic?

Copy link
Author

@gmcouto gmcouto May 13, 2020

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you find out how open feign had fixed this issue?

Copy link
Author

Choose a reason for hiding this comment

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

Sure, will look into it and reply here.

Copy link
Author

@gmcouto gmcouto May 15, 2020

Choose a reason for hiding this comment

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

@kptfh It is actually a very similar solution... see in DefaultServerIntrospector:

public boolean isSecure(Server server) {
    return this.serverIntrospectorProperties.getSecurePorts().contains(server.getPort());
  }

called from EuerekaServerIntrospector:

public boolean isSecure(Server server) {
    if (server instanceof DiscoveryEnabledServer) {
      DiscoveryEnabledServer discoveryServer = (DiscoveryEnabledServer)server;
      return discoveryServer.getInstanceInfo().isPortEnabled(PortType.SECURE);
    } else {
      return super.isSecure(server);
    }
  }

called from RibbonUtils:

public static boolean isSecure(IClientConfig config, ServerIntrospector serverIntrospector, Server server) {
    if (config != null) {
      Boolean isSecure = (Boolean)config.get(CommonClientConfigKey.IsSecure);
      if (isSecure != null) {
        return isSecure;
      }
    }

    return serverIntrospector.isSecure(server);
  }

called from RibbonUtils:

  public static URI updateToSecureConnectionIfNeeded(URI uri, IClientConfig config, ServerIntrospector serverIntrospector, Server server) {
    String scheme = uri.getScheme();
    if (StringUtils.isEmpty(scheme)) {
      scheme = "http";
    }

    return !StringUtils.isEmpty(uri.toString()) && unsecureSchemeMapping.containsKey(scheme) && isSecure(config, serverIntrospector, server) ? upgradeConnection(uri, (String)unsecureSchemeMapping.get(scheme)) : uri;
  }

called from FeignLoadBalancer:

public URI reconstructURIWithServer(Server server, URI original) {
    URI uri = RibbonUtils.updateToSecureConnectionIfNeeded(original, this.clientConfig, this.serverIntrospector, server);
    return super.reconstructURIWithServer(server, uri);
  }

But these are all workarounds in the spring-cloud-netflix-ribbon library... I guess that openfeign does not have any implementation related to/for eureka service discovery, or even any implementation for upgrading schemes.
So, this spring cloud library is responsible for integrating them properly.

Copy link
Collaborator

@kptfh kptfh May 18, 2020

Choose a reason for hiding this comment

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

Don't like to add 2 additional dependencies. I think it should be fixed on Spring side. It should return Server instance with correct schema.
Can you use "https" in URL as workaround?

Copy link
Author

@gmcouto gmcouto May 18, 2020

Choose a reason for hiding this comment

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

Well, the fix is on the reactive feign spring integration module(cloud module), just like spring-cloud-netflix-ribbon library is an integration library... so, to me, it is fitting. I didn't want to add additional dependencies neither, but the "cloud1" is specifically to be used with ribbon and, optionally, eureka.
I guess if we want to use spring fix for this(which is already in place), then we would need to have LoadBalancerCommand to accept a AbstractLoadBalancerAwareClient as a way to reach the loadbalancer, and use spring implementation FeignLoadBalancer wrapper to the ILoadBalancer instead... as it is able to automatically upgrade to https when necessary.
However, I think this fix will impact reactive-feign way more than what I proposed.

In another note, if I add "https" to the url it won't use the loadbalancer...
Because of
https://github.com/Playtika/feign-reactive/blob/bafb08f33142e494829b638d3bdfe3f30419ba29/feign-reactor-spring-configuration/src/main/java/reactivefeign/spring/config/ReactiveFeignClientFactoryBean.java#L95
And
https://github.com/Playtika/feign-reactive/blob/bafb08f33142e494829b638d3bdfe3f30419ba29/feign-reactor-cloud/src/main/java/reactivefeign/cloud/CloudReactiveFeign.java#L195
Maybe changing this can be more appealing. What do you think?

Choose a reason for hiding this comment

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

Are there any updates on this? I am in dire need of this capability.

Choose a reason for hiding this comment

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

Me too..

Copy link
Author

@gmcouto gmcouto Feb 1, 2021

Choose a reason for hiding this comment

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

I suggest you do what I did at the time. Compile and package your own version with the fix on this PR.

Unfortunately, I'm not working on this anymore

@kptfh kptfh force-pushed the develop branch 2 times, most recently from fae4b51 to 100b03b Compare May 7, 2021 16:52
@kptfh
Copy link
Collaborator

kptfh commented May 14, 2021

@gmcouto can you check if it works with Spring Cloud 3.0?
You can take the latest version of reactive feign client

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.

Ribbon Implementation Does not Support "https" when using Eureka / Service Discovery
5 participants