Is there a possibility to throw an exception when configuration is not found in the cloud config server? Our project microservices architecture allows the situation when cloud config client is starting, but the configuration is not already passed to the cloud config server.
The problem is it actually locates some configuration (default?) so no exceptions are thrown and retry is not executed:
org.springframework.cloud.config.client.ConfigServicePropertySourceLocator.locate | Fetching config from server at: http://localhost:8089/config
org.springframework.cloud.bootstrap.config.PropertySourceBootstrapConfiguration.initialize | Located property source: CompositePropertySource [name='configService', propertySources=[MapPropertySource {name='configClient'}]]
But then the missleading error occured:
java.lang.IllegalArgumentException: Could not resolve placeholder 'key.value' in value "${key.value}"
Because config was not found in cloud config service. I want to enable retrying when configuration is not found, but the locate
function from ConfigServicePropertySourceLocator.class
does not throw any exceptions when config could not be found, only when connection to the server could not be established.
I had to make a workaround for this specific case and override ConfigServicePropertySourceLocator's locate
function by adding check if propertySources
list from Environment's result
object is empty. (when using common application.properties
in cloud config server it actually won't work as needed).
Comment From: ryanjbaxter
So do you have an application.properties file in your config repo?
Comment From: spencergibb
Yeah, I don't think this is something we want to do. There's never been a guarantee that there is available properties for a given app. IIRC there's an open issue about validating before applying.
Comment From: jacekfalfasinski
I understand, but isn't missing config the case which should throw an exception or at least log warning that propertySources are empty, nothing was located? In my opinion an application should fail here, not when starting other beans which refer to the missing properties. Another thing is that it doesn't allow to set retries on failure. It is only possible to set retry when a client cannot connect to the config server.
Comment From: spencergibb
Yes, the failure of not finding a property is orthoganal to connecting to config server.
How do we know when empty is a failure? We can't
Comment From: jacekfalfasinski
I didn't mean missing keys in .properties file, but missing .properties file. It is impossible to handle first case in generic way as You've mentioned.
Maybe response status should not be 200 on GET /{name}/{profile}/{label}
but 404 when looked specific .properties file is not found (getRemoteEnvironment
function).
My custom semi-hardcoded workaround, after the getRemoteEnvironment
function call in locate
function:
if (!result.getPropertySources()
.stream()
.filter(ps -> Paths.get(ps.getName()).getFileName().toString().equals(propertiesName))
.findAny()
.isPresent()) {
String errorMessage = "Configuration not found for: " + result.getName();
logger.error(errorMessage);
throw new IllegalStateException(errorMessage);
}
which is caught later and thrown again in properties.isFailFast
condition check (retry enabled).
Comment From: spencergibb
I know, that will break many existing users
Comment From: spencergibb
Closing as wontfix