Questions about profile aware files #25332
-
Hello Everyone, We have a question about the profile aware property files. We do have separate files for different environments (prod, staging, local, ...) and we activate the different profiles in their corresponding environments. From our point of view, we have some strange behavior when running the application from the command line and we wanted to ask if someone could clarify that with us. We have created a small repo to reproduce that behavior. About the setup:
application-common.properties:
application-staging.properties:
application-prod.properties
When we start the application with the When we package and start the application via the CLI in both profiles ( Here is the log output when we run the sample project with 2022-05-03 10:50:12,537 INFO [com.tes.con.con.use.Startup] (main) Config property names: '[services.test.SERVICE1, services.test.SERVICE2, services.test.SERVICE3]'
2022-05-03 10:50:12,537 INFO [com.tes.con.con.use.Startup] (main) name: 'services.test.SERVICE1' -> value: 'http://localhost:8080/health'; (source: ConfigValue{name='services.test.SERVICE1', value='http://localhost:8080/health', rawValue='http://localhost:8080/health', profile='null', configSourceName='PropertiesConfigSource[source=jar:file:/tmp/quarkus-app/app/configtest-main-0.1.0-SNAPSHOT.jar!/application-staging.properties]', configSourceOrdinal=253, configSourcePosition=3, lineNumber=-1})
2022-05-03 10:50:12,538 INFO [com.tes.con.con.use.Startup] (main) name: 'services.test.SERVICE2' -> value: 'http://localhost:8081/health'; (source: ConfigValue{name='services.test.SERVICE2', value='http://localhost:8081/health', rawValue='http://localhost:8081/health', profile='null', configSourceName='PropertiesConfigSource[source=Specified default values]', configSourceOrdinal=-2147483548, configSourcePosition=7, lineNumber=-1})
2022-05-03 10:50:12,538 INFO [com.tes.con.con.use.Startup] (main) name: 'services.test.SERVICE3' -> value: 'http://localhost:8082/health'; (source: ConfigValue{name='services.test.SERVICE3', value='http://localhost:8082/health', rawValue='http://localhost:8082/health', profile='null', configSourceName='PropertiesConfigSource[source=Specified default values]', configSourceOrdinal=-2147483548, configSourcePosition=7, lineNumber=-1})
2022-05-03 10:50:12,538 INFO [com.tes.con.con.use.Startup] (main) Config profiles: [staging, common, common]
2022-05-03 10:50:12,539 INFO [com.tes.con.con.use.Startup] (main) Default config source (class: class io.smallrye.config.PropertiesConfigSource): {value.in.prod.only=true, send.interval.in.sec=30, quarkus.config.profile.parent=common, services.test.SERVICE1=http://localhost:8080/health, services.test.SERVICE2=http://localhost:8081/health, services.test.SERVICE3=http://localhost:8082/health} We can see that the And here is now the log output when we run the sample project with 2022-05-03 10:56:05,750 INFO [com.tes.con.con.use.Startup] (main) Config property names: '[services.test.SERVICE1, services.test.SERVICE2, services.test.SERVICE3]'
2022-05-03 10:56:05,750 INFO [com.tes.con.con.use.Startup] (main) name: 'services.test.SERVICE1' -> value: 'http://localhost:8080/health'; (source: ConfigValue{name='services.test.SERVICE1', value='http://localhost:8080/health', rawValue='http://localhost:8080/health', profile='null', configSourceName='PropertiesConfigSource[source=jar:file:/tmp/quarkus-app/app/configtest-main-0.1.0-SNAPSHOT.jar!/application-prod.properties]', configSourceOrdinal=253, configSourcePosition=3, lineNumber=-1})
2022-05-03 10:56:05,751 INFO [com.tes.con.con.use.Startup] (main) name: 'services.test.SERVICE2' -> value: 'http://localhost:8081/health'; (source: ConfigValue{name='services.test.SERVICE2', value='http://localhost:8081/health', rawValue='http://localhost:8081/health', profile='null', configSourceName='PropertiesConfigSource[source=jar:file:/tmp/quarkus-app/app/configtest-main-0.1.0-SNAPSHOT.jar!/application-prod.properties]', configSourceOrdinal=253, configSourcePosition=3, lineNumber=-1})
2022-05-03 10:56:05,751 INFO [com.tes.con.con.use.Startup] (main) name: 'services.test.SERVICE3' -> value: 'http://localhost:8082/health'; (source: ConfigValue{name='services.test.SERVICE3', value='http://localhost:8082/health', rawValue='http://localhost:8082/health', profile='null', configSourceName='PropertiesConfigSource[source=jar:file:/tmp/quarkus-app/app/configtest-main-0.1.0-SNAPSHOT.jar!/application-prod.properties]', configSourceOrdinal=253, configSourcePosition=3, lineNumber=-1})
2022-05-03 10:56:05,751 INFO [com.tes.con.con.use.Startup] (main) Config profiles: [prod, common, common]
2022-05-03 10:56:05,752 INFO [com.tes.con.con.use.Startup] (main) Default config source (class: class io.smallrye.config.PropertiesConfigSource): {value.in.prod.only=true, send.interval.in.sec=30, quarkus.config.profile.parent=common, services.test.SERVICE1=http://localhost:8080/health, services.test.SERVICE2=http://localhost:8081/health, services.test.SERVICE3=http://localhost:8082/health} Now all values, as expected, are loaded from the We would expect that in the case of the staging profile we just load the 2022-05-03 10:58:56,320 INFO [com.tes.con.con.use.Startup] (Quarkus Main Thread) Config property names: '[services.test.SERVICE1]'
2022-05-03 10:58:56,321 INFO [com.tes.con.con.use.Startup] (Quarkus Main Thread) name: 'services.test.SERVICE1' -> value: 'http://localhost:8080/health'; (source: ConfigValue{name='services.test.SERVICE1', value='http://localhost:8080/health', rawValue='http://localhost:8080/health', profile='null', configSourceName='PropertiesConfigSource[source=file:/home/pwanko/NTS/DEV/Code/shitfuck/configtest/configtest-main/target/classes/application-staging.properties]', configSourceOrdinal=253, configSourcePosition=4, lineNumber=-1})
2022-05-03 10:58:56,321 INFO [com.tes.con.con.use.Startup] (Quarkus Main Thread) Config profiles: [staging, common, common]
2022-05-03 10:58:56,322 INFO [com.tes.con.con.use.Startup] (Quarkus Main Thread) Default config source (class: class io.smallrye.config.PropertiesConfigSource): {} We tried to debug this but all we could find so far was that the default The current "workaround" is to keep the So we wanted to ask the community if someone could tell us please if this is working as designed and our setup is wrong or if this is a bug? Kind Regards |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hi Philipp, Yes, this is expected and working as intended. I know it can be a little confusing. Let me explain. The Quarkus application is built with the So, in this case, because you have more configuration set up for the My recommendation is to just empty the values in the ##### SERVICES #####
services.test.SERVICE1=http://localhost:8080/health
services.test.SERVICE2=
services.test.SERVICE3= This will override the recorded Another option is to use I hope this makes sense. |
Beta Was this translation helpful? Give feedback.
-
Hi Roberto, thank you very much for the answer and the explanation. For now we had a "workaround" based on your second suggestion. We moved the services in a separate profile aware file and removed them from the prod profile and just loaded the other profile with We will change our current solution to your second suggestion and will provide those values with Kind Regards |
Beta Was this translation helpful? Give feedback.
Hi Philipp,
Yes, this is expected and working as intended. I know it can be a little confusing. Let me explain.
The Quarkus application is built with the
prod
profile, and we record the configuration values in a minimal ordinalConfigSource
. This action intends to prevent the application startup from failing because the configuration required during the build may be absent from runtime. Another reason is to remove the file reading from the native image binary.So, in this case, because you have more configuration set up for the
prod
profile (service 2 and service 3), when you activate thestaging
, which only contains service 1, you will still see service 2 and 3. You also noticed that the…