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

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

Open
Gregsen opened this issue Jun 8, 2023 · 6 comments

Comments

@Gregsen
Copy link

Gregsen commented Jun 8, 2023

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.

@ryanjbaxter
Copy link
Contributor

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

@Gregsen
Copy link
Author

Gregsen commented Jun 9, 2023

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?

@ryanjbaxter
Copy link
Contributor

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.

@Gregsen
Copy link
Author

Gregsen commented Jun 12, 2023

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.

@ryanjbaxter
Copy link
Contributor

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
Copy link
Contributor

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.

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

3 participants