-
Notifications
You must be signed in to change notification settings - Fork 116
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
Should Config.getValue() to support variable replacement #396
Comments
I'd really like to avoid having a breaking change due to this feature. As discussed during the last mp config meeting, we could move on to support variable evaluation and specifies that implementation MUST provide a way to support backwards compatibility. My suggestion for this would be:
This way an existing application could run without changing its code by adding the sys prop |
We also need to have a proper spec for what variable evaluation. I've starting working on a prototype and these are the questions I need to answer to move forward:
Starting with your example What should happen when all variables can be evaluated?
=> the expected value will be What should happen when some variables can not be evaluated?
=> The API should throw a Should we support default values?
=> The expected value will be I really like having default value as it avoid having to create and configure "transitive configuration properties" for such use case. Having:
is much simpler to maintain and configure than:
(and we still support the latter for complex configuration where many other configuration properties could reference Should we support expression in the default values?This one makes sense only if we support default values
would evaluate to:
My personal opinion is that we should support only raw "unevaluated" default value and not expression in the default values. |
• support multiple levels of hierarchy • handle at augment time via reflection instead of using code generation • distinguish build-/run-time injection items • generate config parsing with unknown key detection • lighten annotation processing to work better with eclipse (hopefully) • support a wide range of configuration types • require explicit specification of build phase for configuration groups Co-authored-by: Alexey Loubyansky <[email protected]> Co-authored-by: Stuart Douglas <[email protected]>
I've opened #405 to add variable expansion to the spec. The PR contains spec and TCK tests that will make it simpler to agree on the feature. |
What are the plans for variable replacement in MP Config API? We just implemented a possible solution in SmallRye Config, but I'm not sure if it is the right time to move it here or even think about something different in the context of MP Config. I'm wondering if we should give more time for the implementations to come up with their solutions and field test them before deciding something here. So maybe, we should postpone this for 2.1? |
I would like this to be part of ConfigValue interface. |
Which If you want to have a look, here is some of the work we have done: Property Expansion Support: |
There was a ConfigValue prior to Config 1.4 release, but we deleted it to get 1.4 release. We need to bring it back. |
I took at your PRs @radcortez ! I think there is the common understanding that ConfigValue consists of name, value. I am thinking add another method to expandValue. I am not sure why you need any config source ordinal, config source name, etc. By the way, the InterceptorContext should be implementation details, right? |
We are not sure what we need in ConfigValue. For instance, ConfigSource name and ordinal were added so you can retrieve some information from the ConfigSource used to load a that particular configuration. Here is another sample: Well the idea with the interceptor was to provide an easy way to extend and implement many of the features we are discussing here, so I would like to see a similar approach done in the spec. For instance, with the interceptor chain, it would also be easy to implement something like Configuration Name Relocation: |
Remember, we are driving the implementation by use cases, not the other way around. One of the stated use cases for having a Another use case is to be able to support profiles in the manner of Quarkus. For this, an interceptor is required; if interceptors use |
The use case is twofold: to be able to read properties with expanded values, and to be able to selectively enable or disable property variable expansion. Property expansion is best achieved using interceptors. This allows the user to disable property expansion globally and optionally substitute their own implementation or even implement expansion on a per-property basis if they choose. So it doesn't necessarily make sense to tie in property expansion, which is effectively an orthogonal concern, to the config value API. So far everything on |
Sound great! How do you handle empty or missing values from a high order config source? Currently the list of ConfigSources is iterated until a value is perhaps present, see: io.smallrye.config.SmallRyeConfig#getRawValue. |
Empty values are addressed by #541. An explicit empty value is to be considered an intent to have an empty value for the property, which is not the same thing as undefining the property (such that it falls through to the next configuration source). If a property expression expands to an empty string, then the property is considered to be explicitly empty. |
If it is empty, with #541, it means the property value does not exist. After the expansion, it does not exist, an exception should be thrown. |
There is a final interceptor in the chain that performs the regular lookup. So, if the property doesn't exist, you get the exception. |
With the interceptor approach, how to retrieve the raw value per config? |
The same thing. The final chain will retrieve the raw value, but when going up the chain, that value can be modified by any interceptor. Something like:
|
To address the issue #118, we have this PR #392 introducing a way on variable replacement.
In the class ConfigAccessorBuilder.evaluateVariable(boolean evaluateVariables), we would like to suggest the evaluateVariable is on by default.
However, the above only impacts the variable values obtained via ConfigAccess. In ConfigProperty annotation, we also introduced a property evaluateVariables with the default value of true.
Base on this, it might make sense to support evaluateVaribles by default with Config.getValue(). Basically, if a config contains a variable replacement, the variable will be evaluated.
If this issue is accepted, a backward incompatible change will be introduced. This will lead MP Config release to bump major version.
when calling config.getValue(server.url, String.class) will return
If this issue is accepted, a backward incompatible change will be introduced. Hence, this issue will lead MP Config release to bump major version.
The text was updated successfully, but these errors were encountered: