-
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
371 - clarify javadoc on config.getConfigSources #581
Conversation
@jbee @radcortez @ljnelson please review |
* The {@link java.util.Iterator Iterable} is not alterable and | ||
* contains a fixed number of {@linkplain ConfigSource configuration sources}, which may be either static or dynamic. |
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.
I find the wording very vague and easy to misunderstand.
Ideas you could (wrongly) get:
- not alterable means you will get errors when trying the
remove()
method? - not alterable means every call might return the very same
Iterable
instance - which may be either static or dynamic means the iterated elements (the length and order of the backing collection) may or may not change
Ideas you might not get but should:
- every call returns a new
Iterable
instance but the elements iterated never change (when are they pinned down? bootstrapping, point of first use?)
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.
Good point @jbee! I tried a few variants, and then settle on the current statement.
every call returns a new Iterable instance but the elements iterated never change (when are they pinned down? bootstrapping, point of first use?)
The elements never change is problematic. The elements are config sources. Some config sources might change as they might be dynamic.
How about just saying:
The Iterable contains a fixed number of config sources, determined at application start time, and the config sources may be static or dynamic.
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.
@jbee I thought it further and altered the above comments. Can you double check?
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 Iterable contains a fixed number of config sources, determined at application start time, and the config sources may be static or dynamic.
More clear. Go for it.
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.
Well, now, wait a minute: can't a ConfigSourceProvider
supply a set of ConfigSources
? So if a Config
uses that set for its own ConfigSource
s, then the set's "staticness" cannot be guaranteed, right? Nor, presumably, can the iteration behavior be guaranteed? Is it written somewhere that a ConfigSourceProvider
must provide a snapshot?
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.
Yep; just checked the ConfigSourceProvider
javadocs and there is nothing specified about how this must or must not behave. Nor is there anything specified about how Config
must represent its output. So that may need to change before we make a guarantee here.
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.
Hum, I believe that we need to change other parts of the specification if we want to make this change.
From the spec:
MicroProfile Config also allows to implement and register own configuration sources in a portable way, e.g. for reading configuration values from a shared database in an application cluster.
From my understanding, there might be non-portable ways to register Config Sources, including after the Config
object is initialized. In that particular case, then getConfigSources
may be dynamic as well. If it needs to be determined at Config
startup, then the spec must also change (or provide clarification), to Config Sources can only be registered / discovered on Config
init.
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.
I have made the similar javadocs on ConfigSourceProvider
@ljnelson. Please check to see whether you have any further comments.
Signed-off-by: Emily Jiang <emijiang6@googlemail.com>
Signed-off-by: Emily Jiang <emijiang6@googlemail.com>
fixes #371 |
Signed-off-by: Emily Jiang <emijiang6@googlemail.com>
Signed-off-by: Emily Jiang <emijiang6@googlemail.com>
Signed-off-by: Emily Jiang <emijiang6@googlemail.com>
5605857
to
ffb088f
Compare
api/src/main/java/org/eclipse/microprofile/config/spi/ConfigSourceProvider.java
Outdated
Show resolved
Hide resolved
api/src/main/java/org/eclipse/microprofile/config/spi/ConfigSourceProvider.java
Outdated
Show resolved
Hide resolved
* be returned if no sources are to be provided. | ||
* Return the {@link ConfigSource} instances that are provided by this provider. | ||
* The {@link java.util.Iterator Iterable} contains a fixed number of {@linkplain ConfigSource configuration sources}, | ||
* determined at application start time, and the config sources themselves may be static or dynamic. |
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.
How does the ConfigSourceProvider
know when "application start time" is? Do you just mean that the method is called once? Or maybe you mean that the method must be deterministic, i.e. must return whatever it returns whenever it is invoked?
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.
I've also stated that adding a restriction on the sources determined at start time, removes the ability to register additional sources later on. For instance, SmallRyeConfig
provides an API to do just that.
I'm not against this restriction, but then I propose that the spec is also updated to clarify that sources may only be discovered on Config initialization.
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.
How does the
ConfigSourceProvider
know when "application start time" is?
I think the most correct timeline is on Config
initialization. Remember that MP Config may be used outside of application containers, where the notion of "application start time" is not well defined.
Even on application container, due to the programmatic API, nothings stops you to access the Config before the application starts, so you need to have the Config instance ready.
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.
I don't understand the focus on lifecycle concerns. Isn't this proposed restriction just saying: if the method returns sources A, B and C the first time it is invoked, then it must return sources A, B and C the second time it is invoked, and the third, and the nth? Or, much more clearly and succinctly: isn't this just saying the method must be deterministic?
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.
It is what it says, yes.
My point is, once you get a Config
instance, you are locked in the registered ConfigSources
. Right now, the spec did not specify that you couldn't add additional sources after getting a hold of the Config
. With this change it effectively locks the Config
. Is this a reasonable assumption?
If so, I'm only requesting that we clarify in the actual spec documentation the proper behaviour, instead of just being in the java docs. This seems to be somehow important to only be referenced in the java docs.
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.
added more clarification on the spec.
Signed-off-by: Emily Jiang <emijiang6@googlemail.com>
Signed-off-by: Emily Jiang <emijiang6@googlemail.com>
Signed-off-by: Emily Jiang <emijiang6@googlemail.com>
@@ -24,7 +24,8 @@ | |||
== ConfigSources | |||
|
|||
A `ConfigSource` is exactly what its name says: a source for configured values. | |||
The `Config` uses all configured implementations of `ConfigSource` to look up the property in question. | |||
The `Config` uses all configured implementations of `ConfigSource` to look up the property in question. Dynamically added config sources after the `Config` object has been built would be ignored, | |||
which means `Config.getConfigSources` always returns the same collection of `ConfigSource`s. The same rule applies to `ConfigSourceProvider.getConfigSources`. | |||
|
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.
@Emily-Jiang Did this comment ever make it into the spec? If not, it would probably be best to put it here.
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.
@ljnelson it is pretty much common sense implementation. I prefer not to put it here as getPropertyNames() could give you a different list depending when you call it since some configsources are dynamic. This issue is about we ensure the number of configsources are determined and not dynamic while the config sources might be dynamic.
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.
IMHO specifications should never ever rely on "common sense". "Common sense" is "undefined behavior".
Here, it is best to specify what the behavior of Config#getPropertyNames()
is with respect to the behavior of ConfigSource#getPropertyNames()
, because it does not seem to be specified anywhere at the moment. If you do not want to specify it, then an explicit statement to that effect would be important I think. Obviously if you think it should go in a separate issue that's fine too; I just don't want this to get lost.
Signed-off-by: Emily Jiang <emijiang6@googlemail.com>
One other question that may end up being its own issue:
My question: why does the restriction defined by (1) exist if (3) can work around it? If there's a simple answer, feel free to respond here, otherwise I'll open an issue. |
I want to believe for the same reason any limitation exist, namely (quoting Paul Phillips)
Or as Paul put it more bluntly
He reminded us that we easily fall for the "more power is better" fallacy and forget about being on the receiving end of it,
Which causes the paradox of...
He concludes:
;) Remains the question of a changing list of sources being unnecessary? I'd say the TL;DR; is yes, you pretty much gave the answer. Like you suggest, if you have dynamically appearing sources through some vendor specific mechanism this can be represented as single source hooked in from the beginning which wraps the actual dynamic mechanism and acts as the façade for the properties they export. These dynamics allowed at the level of properties within a source make it unnecessary to additionally have dynamics on the level or sources. As a nice side effect it makes something visible that otherwise would be invisible. The existence of a DynamicSomethingSomethingSource in the list of sources will tell you that under certain circumstances more properties might occur though a certain mechanism. But more importantly being able to rely on a fixed list of sources simplifies any bit of code build on top or around sources as you will not have to deal with the possibility of more sources appearing or sources disappearing. |
I'm not sure I understood all that but there were some eloquent parts! Answering my own question: I remember now it is for thread safety: you can safely iterate over a fixed set of |
Signed-off-by: Emily Jiang emijiang6@googlemail.com