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

Unable to configure Eureka port #3889

Open
dlvenable opened this issue Sep 9, 2020 · 2 comments
Open

Unable to configure Eureka port #3889

dlvenable opened this issue Sep 9, 2020 · 2 comments

Comments

@dlvenable
Copy link

dlvenable commented Sep 9, 2020

We need to be able to run our services with dynamic ports in Amazon ECS. We have an internal Spring Boot starter which is able to successfully get the ECS port and set it on a new EurekaInstanceConfigBean bean.

However, the EurekaAutoServiceRegistration class is overriding this value.

Here are our log files. You can see that our starter is finding port 32768. However, you can also see where EurekaAutoServiceRegistration sets it afterward.

2020-09-09 16:18:58.021  INFO [,] 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8001 (http)
2020-09-09 16:18:58.987 DEBUG [,] 1 --- [           main] c.a.s.cloud.boot.EurekaAutoConfigure     : Received host port 32768 from ECS container metadata.
2020-09-09 16:18:58.988  INFO [,] 1 --- [           main] c.a.s.cloud.boot.EurekaAutoConfigure     : Setting non-secure port to 32768
2020-09-09 16:19:02.370  INFO [,] 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8001 (http) with context path ''
2020-09-09 16:19:02.375  INFO [,] 1 --- [           main] .s.c.n.e.s.EurekaAutoServiceRegistration : Updating port to 8001 

I believe the relevant code in Spring Cloud Eureka is this:
https://github.com/spring-cloud/spring-cloud-netflix/blob/master/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/serviceregistry/EurekaAutoServiceRegistration.java#L139-L150

It seems that this registration should not be attempting to override an existing configuration. Also, since it running based on a, WebServerInitializedEvent, we can't use Spring Boot's configure-after controls.

@spencergibb
Copy link
Member

yeah, if the port is set by properties and it is greater than zero we should use that.

@dlvenable
Copy link
Author

Thank you for the response. For additional information, here is a snippet from where we do our configuration.

You can see that our log line "Setting non-secure port to {}" is being reached in the logs above.

   @Value("${server.port:#{null}}")
    private Integer port;

    @Bean
    @Profile("production")
    public EurekaInstanceConfigBean eurekaInstanceConfig(InetUtils inetUtils)
    {
        EurekaInstanceConfigBean eurekaConfig = new EurekaInstanceConfigBean(inetUtils);
        AmazonInfo awsInfo = AmazonInfo.Builder.newBuilder().autoBuild("eureka");
        eurekaConfig.setDataCenterInfo(awsInfo);
        eurekaConfig.setIpAddress(awsInfo.get(AmazonInfo.MetaDataKey.localIpv4));
        eurekaConfig.setHostname(awsInfo.get(AmazonInfo.MetaDataKey.localHostname));

        Integer port = getInstancePort();  // This is just a method to get the port from AWS ECS
        if(port != null)
        {
            log.info("Setting non-secure port to {}", port);
            eurekaConfig.setNonSecurePort(port);
        }

        return eurekaConfig;
    }

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

No branches or pull requests

2 participants