spring-petclinic/spring-petclinic-microservices

Activate docker profile only but read default profile also

sanme98 opened this issue · 5 comments

Hi All,

I ran docker-compose up to start the docker, but I found all of the services unable to register on Eureka, it seems connect to Eureka using http://localhost:8761 instead of http://discovery-server:8761. I cloned this project without any changes. From the log, it seems loaded docker profile and then default profile? Which shouldn't need to load default profile since the Dockerfile only specify docker profile?

Below is some part of the log for Customer Services:

2023-06-25T08:41:48.062Z  INFO 13 --- [           main] o.s.s.p.c.CustomersServiceApplication    : The following 1 profile is active: "docker"
2023-06-25T08:41:48.108Z  INFO 13 --- [           main] o.s.c.c.c.ConfigServerConfigDataLoader   : Fetching config from server at : http://localhost:8888/
2023-06-25T08:41:48.108Z  INFO 13 --- [           main] o.s.c.c.c.ConfigServerConfigDataLoader   : Exception on Url - http://localhost:8888/:org.springframework.web.client.ResourceAccessException: I/O error on GET request for "http://localhost:8888/customers-service/default": Connection refused. Will be trying the next url if available
2023-06-25T08:41:48.108Z  WARN 13 --- [           main] o.s.c.c.c.ConfigServerConfigDataLoader   : Could not locate PropertySource ([ConfigServerConfigDataResource@7e1a1da6 uris = array<String>['http://localhost:8888/'], optional = true, profiles = list['default']]): I/O error on GET request for "http://localhost:8888/customers-service/default": Connection refused
2023-06-25T08:41:48.108Z  INFO 13 --- [           main] o.s.c.c.c.ConfigServerConfigDataLoader   : Fetching config from server at : http://config-server:8888
2023-06-25T08:41:48.108Z  INFO 13 --- [           main] o.s.c.c.c.ConfigServerConfigDataLoader   : Located environment: name=customers-service, profiles=[docker], label=null, version=e19bfe823ffa415f0f44d7ec798959b79741ab16, state=null
2023-06-25T08:41:48.108Z  INFO 13 --- [           main] o.s.c.c.c.ConfigServerConfigDataLoader   : Fetching config from server at : http://config-server:8888
2023-06-25T08:41:48.109Z  INFO 13 --- [           main] o.s.c.c.c.ConfigServerConfigDataLoader   : Located environment: name=customers-service, profiles=[default], label=null, version=e19bfe823ffa415f0f44d7ec798959b79741ab16, state=null
2023-06-25T08:41:48.109Z  INFO 13 --- [           main] o.s.c.c.c.ConfigServerConfigDataLoader   : Fetching config from server at : http://localhost:8888/
2023-06-25T08:41:48.109Z  INFO 13 --- [           main] o.s.c.c.c.ConfigServerConfigDataLoader   : Exception on Url - http://localhost:8888/:org.springframework.web.client.ResourceAccessException: I/O error on GET request for "http://localhost:8888/customers-service/docker": Connection refused. Will be trying the next url if available
2023-06-25T08:41:48.109Z  WARN 13 --- [           main] o.s.c.c.c.ConfigServerConfigDataLoader   : Could not locate PropertySource ([ConfigServerConfigDataResource@49a64d82 uris = array<String>['http://localhost:8888/'], optional = true, profiles = list['docker']]): I/O error on GET request for "http://localhost:8888/customers-service/docker": Connection refused
2023-06-25T08:41:48.109Z  INFO 13 --- [           main] o.s.c.c.c.ConfigServerConfigDataLoader   : Fetching config from server at : http://localhost:8888/
2023-06-25T08:41:48.109Z  INFO 13 --- [           main] o.s.c.c.c.ConfigServerConfigDataLoader   : Exception on Url - http://localhost:8888/:org.springframework.web.client.ResourceAccessException: I/O error on GET request for "http://localhost:8888/customers-service/default": Connection refused. Will be trying the next url if available
2023-06-25T08:41:48.109Z  WARN 13 --- [           main] o.s.c.c.c.ConfigServerConfigDataLoader   : Could not locate PropertySource ([ConfigServerConfigDataResource@66d23e4a uris = array<String>['http://localhost:8888/'], optional = true, profiles = list['default']]): I/O error on GET request for "http://localhost:8888/customers-service/default": Connection refused
....
2023-06-25T08:41:52.573Z  INFO 13 --- [           main] com.netflix.discovery.DiscoveryClient    : Getting all instance registry info from the eureka server
2023-06-25T08:41:52.643Z  INFO 13 --- [           main] c.n.d.s.t.d.RedirectingEurekaHttpClient  : Request execution error. endpoint=DefaultEndpoint{ serviceUrl='http://localhost:8761/eureka/}, exception=I/O error on GET request for "http://localhost:8761/eureka/apps/": Connect to http://localhost:8761 [localhost/127.0.0.1] failed: Connection refused stacktrace=org.springframework.web.client.ResourceAccessException: I/O error on GET request for "http://localhost:8761/eureka/apps/": Connect to http://localhost:8761 [localhost/127.0.0.1] failed: Connection refused

May I know how to resolve this error without changing the config yml, so it can still work to run locally and docker?

Noted: If I changed the config yml to below by removed the docker profile, it works.

spring:
  config:
    activate:
      on-profile: default
eureka:
  instance:
    # enable to register multiple app instances with a random server port
    instance-id: ${spring.application.name}:${random.uuid}

---
spring:
  # config:
    # activate:
      # on-profile: docker
  zipkin:
    baseUrl: http://tracing-server:9411
server:
  port: 8081
eureka:
  client:
    serviceUrl:
      defaultZone: http://discovery-server:8761/eureka/

Thank you.

arey commented

Hi @sanme98. Thank you for your feedback. I've the same issue. Maybe it was introduced in a recent Spring Boot and/or Spring Cloud upgrade?

The microservices start with the docker active spring profile:

customers-service    | 2023-06-25T13:18:00.305Z  INFO 17 --- [           main] o.s.s.p.c.CustomersServiceApplication    : The following 1 profile is active: "docker"

At startup, they look at their configuration both at localhost then config-server. I don't know why?

ting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
customers-service    | 2023-06-25T13:18:00.725Z  INFO 17 --- [           main] o.s.c.c.c.ConfigServerConfigDataLoader   : Fetching config from server at : http://localhost:8888/
customers-service    | 2023-06-25T13:18:00.727Z  INFO 17 --- [           main] o.s.c.c.c.ConfigServerConfigDataLoader   : Exception on Url - http://localhost:8888/:org.springframework.web.client.ResourceAccessException: I/O error on GET request for "http://localhost:8888/customers-service/default": Connection refused. Will be trying the next url if available
customers-service    | 2023-06-25T13:18:00.728Z  WARN 17 --- [           main] o.s.c.c.c.ConfigServerConfigDataLoader   : Could not locate PropertySource ([ConfigServerConfigDataResource@7e1a1da6 uris = array<String>['http://localhost:8888/'], optional = true, profiles = list['default']]): I/O error on GET request for "http://localhost:8888/customers-service/default": Connection refused
customers-service    | 2023-06-25T13:18:00.734Z  INFO 17 --- [           main] o.s.c.c.c.ConfigServerConfigDataLoader   : Fetching config from server at : http://config-server:8888

We need to investigate.

arey commented

I rollback to a Spring Cloud 2022.0.1 and Spring Boot 3.0.2 commit and I've noticed that config server lookup are reversed. First http://config-server:8888 then http://localhost:8888/
Maybe a lead?

customers-service    | 2023-06-25T13:50:53.647Z  INFO 17 --- [           main] o.s.c.c.c.ConfigServerConfigDataLoader   : Fetching config from server at : http://config-server:8888
customers-service    | 2023-06-25T13:50:53.650Z  INFO 17 --- [           main] o.s.c.c.c.ConfigServerConfigDataLoader   : Located environment: name=customers-service, profiles=[docker], label=null, version=e19bfe823ffa415f0f44d7ec798959b79741ab16, state=null
customers-service    | 2023-06-25T13:50:53.651Z  INFO 17 --- [           main] o.s.c.c.c.ConfigServerConfigDataLoader   : Fetching config from server at : http://localhost:8888/
customers-service    | 2023-06-25T13:50:53.653Z  INFO 17 --- [           main] o.s.c.c.c.ConfigServerConfigDataLoader   : Connect Timeout Exception on Url - http://localhost:8888/. Will try the next url if available

Hi @arey, I have tried v2.6.7, it is working fine for that version. Maybe it just happens on Spring Boot v3? Thanks.

arey commented

This issue comes from the upgrade to Spring Cloud 2022.0.2 to 2022.0.3. On the master branch I will downgrade the dependencies while waiting for a proper correction.
See #233

arey commented

Should be work. Please reopen if not