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

Custom config source is not working in Quarkus 2.0.0 #18375

Closed
ennishol opened this issue Jul 3, 2021 · 13 comments · Fixed by #17483
Closed

Custom config source is not working in Quarkus 2.0.0 #18375

ennishol opened this issue Jul 3, 2021 · 13 comments · Fixed by #17483
Assignees
Labels
area/config kind/bug Something isn't working
Milestone

Comments

@ennishol
Copy link
Contributor

ennishol commented Jul 3, 2021

Describe the bug

Custom config source is loaded but afterward,

the exception is thrown:
java.util.NoSuchElementException: SRCFG00014: The config property some.key is required but it could not be found in any config source.

Expected behavior

Config values must be loaded and used

Actual behavior

Config values are loaded but not used, NoSuchElementException is thrown

To Reproduce

Steps to reproduce the behavior:
rest-json-quickstart.tar.gz
Custom config source selects application-*.properties file based on CONFIG_TYPE env variable:

  1. unset CONFIG_TYPE && mvn clean package
  2. export CONFIG_TYPE=b && mvn quarkus:dev
  3. see log
@ennishol ennishol added the kind/bug Something isn't working label Jul 3, 2021
@gsmet
Copy link
Member

gsmet commented Jul 3, 2021

/cc @radcortez

@radcortez
Copy link
Member

Relates with #18237.

We removed the ability to discover sources during static init, because some sources would not work due to required services not being available. Since Config is the first thing we need to initialize, if we need to connect to a database, the database resource would not be available, so this is mostly a chicken/egg problem. In this particular case, the RESTEasy Exception mapper is added in static init, so it causes the problem.

@ennishol looking into the reproducer, it seems that you want to activate custom application.properties files. Not sure if this is your actual use case, or just used for the reproducer. If this is your actual use case, Quarkus already supports this configuration style. Please check https://quarkus.io/guides/config-reference#profile-aware-files. If you use the Quarkus profile-aware files, this issue should go away, because we do load this configuration during static init.

In the meanwhile, I'll need to check if there is something we could do in RESTEasy.

@ennishol
Copy link
Contributor Author

ennishol commented Jul 5, 2021

@radcortez yes, loading specific file based on some env variable (not profile, like staging, dev or production) is my use case. In other words, I want to select config file, inside of which I'd be able to define overrides for specific profile:

export CONFIG_TYPE=a ---> application-a.properties is loaded with content:
some.key=a
%dev.some.key=x

export CONFIG_TYPE=b ---> application-b.properties is loaded with content:
some.key=b
%dev.some.key=y

@radcortez
Copy link
Member

Have you tried multiple profiles https://smallrye.io/docs/smallrye-config/config/config.html#_multiple_profiles?

In that way, you should be able to keep the Quakus profile and add your own.

@ennishol
Copy link
Contributor Author

ennishol commented Jul 6, 2021

@radcortez No I didn't know about multiple profiles. I will try that out. Thank you!

@radcortez
Copy link
Member

Great. Let me know if that works. If that works for you then you should be able to set up the RESTEasy provider using the default sources.

In the meanwhile, I'm prototyping something to support the custom sources when they are needed.

@ennishol
Copy link
Contributor Author

ennishol commented Jul 6, 2021

@radcortez I think it would work, but maintaining the configs with multiple profiles is a bit cumbersome. It would be really great if it would be possible to select config file per deployment as described above. It is really nice to have them isolated on the file level

@radcortez
Copy link
Member

I think it should work. When you pass in the multiple profiles, it will load any file with any profile in the name, but also the profile property names inside the file. So you use the something like quarkus.profile=dev,a where you have application-a.properties or quarkus.profile=dev,b where you have application-b.properties. Each file can contain different %dev properties.

Another alternative is to use quarkus.config.locations and you can pass in a dir, file, classpath, http to load additional configuration files. Example:

# Assuming the same working directory as the Quarkus app
|-a/application.properties
|-b/application.properties

Then, you can use quarkus.config.locations=a or quarkus.config.locations=b to load all the contents in a or b folder. Profile aware files are also loaded.

@ennishol
Copy link
Contributor Author

ennishol commented Jul 7, 2021

created a/application.properties and with
java -Dquarkus.profile=a -Dquarkus.config.locations=a -jar target/quarkus-app/quarkus-run.jar
the properties from a are not loaded, only default ones from src/main/resources

However, application-a.properties from resources folder is loaded with mvn quarkus:dev -Dquarkus.profile=a and with jar so I think, it will fit my needs.

@radcortez
Copy link
Member

created a/application.properties and with
java -Dquarkus.profile=a -Dquarkus.config.locations=a -jar target/quarkus-app/quarkus-run.jar
the properties from a are not loaded, only default ones from src/main/resources

Most likely the issue is related with the location of the file. When you pass a relative path, it uses the working directory of the quarkus application. So to be safe, just use the absolute path.

@ennishol
Copy link
Contributor Author

ennishol commented Jul 9, 2021

@radcortez The documentaion states: Only a single profile may be active at a time. This is incorrect, right?

@radcortez radcortez self-assigned this Jul 9, 2021
@radcortez
Copy link
Member

It is possible to have multiple profiles at a time, but this is provided by SR Config and not Quarkus. Quarkus was written with a single profile in mind, so some extensions may not be aware of the multi-profile capabilities of SR Config, so we prefer to just say a single profile in Quarkus to be safe :)

@ennishol
Copy link
Contributor Author

I see... On the other hand, I'd like to be safe too. So I have to move back to my custom config source as soon as the fix will be available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/config kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants