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

Clarification of ConfigSource.getProperties and getPropertyNames #333

Closed
tevans78 opened this issue Mar 26, 2018 · 6 comments
Closed

Clarification of ConfigSource.getProperties and getPropertyNames #333

tevans78 opened this issue Mar 26, 2018 · 6 comments
Assignees
Labels
clarification 🏆 A clarification (PR) or request for clarification (issue) in the spec or API
Milestone

Comments

@tevans78
Copy link
Contributor

tevans78 commented Mar 26, 2018

Not so long ago there was an issue opened in the javaee-samples repo because the Liberty config impl did not work as expected with an "EchoConfigSource".

javaee-samples/microprofile1.2-samples#3
https://github.com/javaee-samples/microprofile1.2-samples/blob/master/config/config-source/src/main/java/org/eclipse/microprofile12/config/configsource/EchoConfigSource.java

The EchoConfigSource has been implemented to simply echo back anything that is requested via ConfigSource.getValue. That means that the returns from getProperties and getPropertyNames are incomplete compared with what getValue will respond to.

If ConfigSource.getPropertyNames is not guaranteed to return a complete set then Config.getPropertyNames can not be guaranteed to be complete either. Without that guarantee then the method isn't of much use beyond perhaps some non-critical tracing.

Either the javadoc for both ConfigSource and Config should be updated to make if clear what can be relied upon and what can not... or the methods should just be removed?!

@smillidge
Copy link
Contributor

+1 for updating the docs. Removal could break backwards compatibility however I would also be in favour of removal.
Both methods could be very expensive depending on the Config Source for example imagine a config source that looks up a key in a Redis or memcached KV store it would need to retrieve all keys to comply with the api signature.

@OndroMih
Copy link
Contributor

The javadoc should say that both methods reflect the current state and results may change during runtime.

@OndroMih
Copy link
Contributor

OndroMih commented Apr 16, 2018

@Emily-Jiang explained that there's a usecase to find out whether a value exists in a config source or not and the only way to find out now is to call getPropertyNames(). The usecase is motly valid when checking that a config value is present at deploy time.
I think this usecase would be better supported by a new method propertyExists(String).

It can even be a default method like this to avoid breaking existing config sources:

default boolean propertyExists(String propertyName) {
        return getPropertyNames().contains(propertyName);
}

However, I would remove both getProperties() and getPropertyNames() as @smillidge suggested. For most sources, there's no guarantee that the config values won't change during runtime. Even standard system property config source can change values during runtime.

To avoid breaking existing code, we can make them deprecated and return empty set/map by default, so that config sources don't have to implement them.

@dmlloyd
Copy link
Contributor

dmlloyd commented Dec 17, 2018

I ran into a related problem with smallrye/smallrye-config#70 - essentially, custom ConfigSource implementations generally must implement a full Map even if their backing implementation isn't really Map-like. It's a heavy burden to place on implementors.

@jmesnil jmesnil added clarification 🏆 A clarification (PR) or request for clarification (issue) in the spec or API mpconfig-1.4 labels Aug 2, 2019
@Emily-Jiang Emily-Jiang added this to the MP Config 1.4 milestone Oct 11, 2019
@ljnelson
Copy link
Contributor

For the record and posterity: please do not remove getPropertyNames(). There are many use cases that depend on discovering at least the names of available properties in the system. Thanks.

@Emily-Jiang
Copy link
Member

related #431

Emily-Jiang added a commit to Emily-Jiang/microprofile-config that referenced this issue Jan 16, 2020
Signed-off-by: Emily Jiang <emijiang6@googlemail.com>
@Emily-Jiang Emily-Jiang self-assigned this Jan 20, 2020
Emily-Jiang added a commit to Emily-Jiang/microprofile-config that referenced this issue Jan 21, 2020
Signed-off-by: Emily Jiang <emijiang6@googlemail.com>
Emily-Jiang added a commit that referenced this issue Jan 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clarification 🏆 A clarification (PR) or request for clarification (issue) in the spec or API
Projects
None yet
Development

No branches or pull requests

7 participants