spring-cloud / spring-cloud-config

External configuration (server and client) for Spring Cloud
Apache License 2.0
1.94k stars 1.28k forks source link

Spring Cloud Config Server - Multi-File Composition / Importing #2335

Open tomcruise81 opened 9 months ago

tomcruise81 commented 9 months ago

Is your feature request related to a problem? Please describe. I'm trying to group blocks of configuration into individual files for clarity. Unfortunately, I can't find any documentation on if Spring Cloud Config Server offers the ability to reference other Spring Cloud Config Server files from within a given file and have them imported / included in the final rendered file.

Describe the solution you'd like Much in the same way that Spring Boot offers the spring.config.import option, I'd like to see a way to import or include populated Spring Cloud Config Server files part-a.properties & part-b.properties in template.properties. Maybe name it ${spring.cloud.config.import}

# part-a.properties
property.a=SOME_VALUE_A
# part-b.properties
property.b=SOME_VALUE_B
# template.properties

${spring.cloud.config.import=part-a.properties}

${spring.cloud.config.import=part-b.properties}

Spring Cloud Config Server rendered template.properties:

# template.properties

# part-a.properties
property.a=SOME_VALUE_A

# part-b.properties
property.b=SOME_VALUE_B

Describe alternatives you've considered Specifying every single property that we want to include is cumbersome and lacks clarity.

ryanjbaxter commented 9 months ago

Even spring.config.import does not do this, when you use spring.config.import each import statement is still its own property source.

You can have the config server serve up the files in your example by making a request to /part/a,b. In other words if the client had an application name part and activated profiles a, and b, that would cause the config server to return both configuration files in its list of property sources.

tomcruise81 commented 9 months ago

Thanks for the input @ryanjbaxter.

One of the benefits of Spring Cloud Config Server is that it doesn't just work with Spring clients but can serve up populated config files directly to be consumed by other types of applications - hence my desire for the rendered result rather than the notion of multiple property sources.

Trying to include the multiple profiles seems to only render the results of the first matching file/profile.

ryanjbaxter commented 9 months ago

So are you using the config server to serve up specific files? Can you provide an example of the requests you are making to the config server?

tomcruise81 commented 9 months ago

https://spring-cloud-config-server.somedomain.com/GIT_PROJECT%28_%29GIT_REPO/PROFILE/BRANCH/template.properties

Where:

ryanjbaxter commented 9 months ago

Essentially what you are looking for a way to return multiple config files in a single request, correct?

tomcruise81 commented 9 months ago

In the simplest sense - yes.

But I could see the benefit to doing something like:

# template.properties

info.app.name=${application.name}
info.app.version=${application.version}

${spring.cloud.config.import=part-a.properties}

${spring.cloud.config.import=part-b.properties}

getting rendered to:

# template.properties

info.app.name=Something Useful
info.app.version=1.2.3.4

# part-a.properties
property.a=SOME_VALUE_A

# part-b.properties
property.b=SOME_VALUE_B

where there's a mix of populated properties and resolved property file contents