-
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
Support variable expansion #405
Conversation
The feature breaks backward compatibility (as explained in the spec) but this feature is too useful to be disabled by default. With that requirement, could we add this feature to MP Config 1.4 (without having to bump the major version)? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure we are ready to do this PR as yet. I would like to ask the community first for this backward incompatibility changes first.
api/src/main/java/org/eclipse/microprofile/config/ConfigAccessorBuilder.java
Outdated
Show resolved
Hide resolved
06ea882
to
ccb6d13
Compare
|
||
Implementation of MicroProfile Config MUST provide a way to disable variable expansion to provide backwards compatibility. | ||
|
||
The property `mp-config.expand-variables` can be configured as a boolean in one of the 3 default `ConfigSource` (environment variables, system properties, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: rename it to mp.config.expandVariables
to be consistent with other MP specs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this be implemented as a default method on ConfigSource
, whose default implementation is to evaluate that property? This would allow for config source implementations that always or never expand properties. For example, we've already run into trouble with property expansion in environment variables which contain ${..}
sequences.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The intent of this property is a global switch that applies at the Config level (either try to expand all properties or not).
If I follow you, you want to be able to configure variable expansion on a ConfigSource
level.
E.g.
# config_source_1
mp.config.source.expandVariables=true
host=localhost
port=8080
server=http://${host}:${port}
# config_source_2
mp.config.source.expandVariables=false
server=http://${host}:${port}
If config_source_1
has higher ordinal, config.getValue("server", String.class)
would return http://localhost:8080
(as its variables are expanded).
If config_source_2
has higher ordinal, config.getValue("server", String.class)
would return http://${host}:${port}
(as its variables are not expanded).
@dmlloyd is that the behaviour you are expecting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I had just misinterpreted the description of the functionality. I thought the property applied to each config source but the specification states that it must be configured in one of the default config sources to apply (globally).
That said, we did internally talk about the fact that we probably do not want to allow expansion within environment variable values as this could cause issues with certain environments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The intent of this property is a global switch that applies at the Config level (either try to expand all properties or not).
If I follow you, you want to be able to configure variable expansion on a
ConfigSource
level.
E.g.# config_source_1 mp.config.source.expandVariables=true host=localhost port=8080 server=http://${host}:${port} # config_source_2 mp.config.source.expandVariables=false server=http://${host}:${port}
If
config_source_1
has higher ordinal,config.getValue("server", String.class)
would returnhttp://localhost:8080
(as its variables are expanded).
Ifconfig_source_2
has higher ordinal,config.getValue("server", String.class)
would returnhttp://${host}:${port}
(as its variables are not expanded).@dmlloyd is that the behaviour you are expecting?
Is this implemented already and can you please let us know how to use it and details.?
7ddb06f
to
4643bc5
Compare
api/src/main/java/org/eclipse/microprofile/config/spi/ConfigBuilder.java
Outdated
Show resolved
Hide resolved
api/src/main/java/org/eclipse/microprofile/config/ConfigAccessorBuilder.java
Outdated
Show resolved
Hide resolved
7012a38
to
06b27e6
Compare
|
||
Implementation of MicroProfile Config MUST provide a way to disable variable evaluation to provide backwards compatibility. | ||
|
||
The property `mp.config.evaluateVariables` can be configured as a boolean in one of the 3 default `ConfigSource` (environment variables, system properties, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-1 on specifying the location of the property. It should be allowed to be specified anywhere as a config, as long as it is available on application starting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand correctly, the property is supposed to apply on a per-source basis only, so that some sources can have expressions and some not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dmlloyd no, that's not the intent.
The intent is to support the mp.config.evaluateVariables
property to configure globally variable evaluation on a Config level.
The wording is poor. I just wanted to restrict the usage of this property to the 3 default config sources so that a ConfigBuilder will only look in these 3 config sources to determine the behaviour of the built Config.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@emilyjiang we can not specify this property that is using to configure the Config
itself on any ConfigSource
or we end up with a chicken-and-egg situation.
Let's say we have a 3rd-party Zookeeper ConfigSource that calls ConfigProvider.getConfig()
to get its own configuration (to be able to connect to ZK).
If we look for any ConfigSource
to get this mp.config.evaluateVariables
, we will call ZooKeep ConfigSource that will call ConfigProvider.getConfig()
to get its configuration (to be able to fetch its properties). In turn this will call the method responsible to get the mp.config.evaluateVariables
property, etc.
Restricting to the 3 default ConfigSource avoid this situation. This property is a special case: it it used to configure the ConfigBuilder
itself, not the application. It seems ok to me to limit its use.
Not per source but per application |
I guess this was meant to be in reply to #405 (comment) ? There are two points where expansion could be decidable. One is per-source (for example, the environment often can contain things that look like expressions but would fail on expansion), and the other is the application. I believe the specification allows both. But the paragraph in question that you responded to seems to be referring to controlling expansion by source, not by application. |
* Spec * Update specification with Variable Evaluation chapter * Introduce mp.config.evaluateVariables property to support previous behaviour. * Add a note about backwards compatibilty * API * add ConfigBuilder#evaluateVariables * TCK * Add VariableEvaluationTest to the TCK to validate variable evaluation Signed-off-by: Jeff Mesnil <[email protected]>
* Add VariableEvaluationTest#testMPConfigEvaluateVariablesProperty to check that an implement does *not* evaluate variables if the mp.config.evaluateVariabes config property is set to false.
085c612
to
73ca146
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One tiny typo fix. Also I was wondering: is escaping handled somewhere? I.e. how can I have a config var to return ${name}
literally instead of resolving it?
[[variable-evaluation]] | ||
== Variable Evaluation | ||
|
||
The value of a configuration property can contains a variable corresponding to another configuration property. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The value of a configuration property can contains a variable corresponding to another configuration property. | |
The value of a configuration property can contain a variable corresponding to another configuration property. |
Hi folks, why can't we have a more generic approach to this? I think of invoking (custom) interceptors/filters before returning a value. Each interceptor should be provided with a context that e.g. contains all (unresolved) config properties from With this, a variable expansion would be just an implementation of this interface. |
In SmallRye, we provide an API to allow a |
I think we should close this old PR and open one or more new |
Closing this PR, as we discussed previously. |
Signed-off-by: Jeff Mesnil [email protected]