spring-cloud-config icon indicating copy to clipboard operation
spring-cloud-config copied to clipboard

Fallback to default values from application.yaml on "spring.cloud.config.fail-fast: true"

Open Gregsen opened this issue 2 years ago • 6 comments

Is your feature request related to a problem? Please describe. As per the docs:

If you expect that the config server may occasionally be unavailable
 when your application starts, you can make it keep trying after a failure.

We want to use that, since our config server take some time to be up. But, we also want to use the application.yaml, if the server is not reachable (basically, the behaviour of spring.cloud.config.fail-fast: false). Can we have the "best of both worlds"?

Describe the solution you'd like When I have the spring.cloud.config.fail-fast: false set and added spring-retry and spring-boot-starter-aop to my classpath, I want to have an additional flag to indicate, that the application should fall back default values from the application.yaml

Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

Additional context In the ConfigServicePropertySourceLocator is the code that checks for the fail-fast propery.

Gregsen avatar Jun 08 '23 12:06 Gregsen

Are you using spring.config.import=optional:configserver?

ryanjbaxter avatar Jun 08 '23 17:06 ryanjbaxter

Hey,

I am using the "old" setup: I have a bootstrap.yaml

spring:
  application:
    name: my-application
  cloud:
    config:
      uri: http://localhost:8888
      server:
        bootstrap: false
      fail-fast: false

and I am using version 2.0.0.M9 of spring-cloud-config. The application is on spring boot 2.6.6 and java 11.

Would moving to spring.config.import=optional:configserver make it possible to have a retry and a fallback?

Gregsen avatar Jun 09 '23 07:06 Gregsen

I believe it would, see the NOTE in this section of our documentation

https://docs.spring.io/spring-cloud-config/docs/4.0.3/reference/html/#config-client-fail-fast

Spring Cloud Config 2.0.0.M9 is not supported any longer, I would at least upgrade to Spring Cloud 2021.0.7.

ryanjbaxter avatar Jun 09 '23 15:06 ryanjbaxter

Hey,

I tried your suggestion with a "newer" application of ours. It's spring boot 2.7.0 application with spring-cloud-dependencies 2021.0.7. The issue is basically the same. While the application now keeps running, its marked as failed and will stop all listeners and endpoints (going to Application availability state ReadinessState changed to REFUSING_TRAFFIC). The Exception this time is different:

org.springframework.cloud.config.client.ConfigClientFailFastException: Could not locate PropertySource and the fail fast property is set, failing
	at org.springframework.cloud.config.client.ConfigServerConfigDataLoader.doLoad(ConfigServerConfigDataLoader.java:197) ~[spring-cloud-config-client-3.1.3.jar:3.1.3]

However, the reason seems similar: If fail-fast is enabled, the application will not fall back to the default values in the application.yaml, but just stop with an error.

Ideally, there would be an option to prevent the exception and just continue running.

Gregsen avatar Jun 12 '23 09:06 Gregsen

What if you remove the fail-fast property and just set `spring.config.import=optional:configserver:"? If the client can't reach the config server in that case it should just continue on.

ryanjbaxter avatar Oct 13 '23 20:10 ryanjbaxter

If fail-fast is set to true it means to fail on startup if it can't reach the config server. You want the application to startup and use application.yaml if it can't reach the config server so fail-fast needs to be false and/or you need to add optional to the config.import statement.

ryanjbaxter avatar Oct 13 '23 20:10 ryanjbaxter