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

Add ability to decorate ConfigSources #66

Closed
dmlloyd opened this issue Dec 14, 2018 · 9 comments
Closed

Add ability to decorate ConfigSources #66

dmlloyd opened this issue Dec 14, 2018 · 9 comments

Comments

@dmlloyd
Copy link
Contributor

dmlloyd commented Dec 14, 2018

It would be nice if there were some way to install global Converter decorators/interceptors (e.g. UnaryOperator<Converter>) which can enhance the conversion process.

This would enable an easy way to plug in various variable expansion capabilities.

I'll work up a possible implementation.

@dmlloyd
Copy link
Contributor Author

dmlloyd commented Dec 14, 2018

This is actually quite difficult to do in the higher level APIs, because in the end, it's possible to query the ConfigSource for all of its properties and values which would bypass any converters. So, it might be better to implement this by wrapping the ConfigSource implementations themselves.

@dmlloyd dmlloyd changed the title Add ability to decorate converters Add ability to decorate ConfigSources Dec 14, 2018
@dmlloyd
Copy link
Contributor Author

dmlloyd commented Dec 14, 2018

Here are some example use cases:

  • Value property expansion
  • Key filtering and transposition
  • Caching or copying for slow config sources
  • Snapshot/point-in-time configuration views

dmlloyd added a commit to dmlloyd/smallrye-config that referenced this issue Dec 14, 2018
dmlloyd added a commit to dmlloyd/smallrye-config that referenced this issue Dec 14, 2018
dmlloyd added a commit to dmlloyd/smallrye-config that referenced this issue Dec 17, 2018
@jmesnil
Copy link
Contributor

jmesnil commented Dec 17, 2018

@dmlloyd I'm not sure how much you're following microprofile-config development but we are working on the next release to address some of these issues:

  • value property expansion
  • snapshot
  • caching

they are tracked by eclipse/microprofile-config#392

We do not have use case for Key filtering and transposition, could you provide some?

@dmlloyd
Copy link
Contributor Author

dmlloyd commented Dec 17, 2018

Sure. Imagine you have a platform where you might want to have one configuration file with multiple "profiles". I might have most of my keys be the same, but a small number might have some variations, for example:

app.db.url=pgsql:...some production DB...
%dev.app.db.url=h2:...something trivial...

Then I start up my app in a mode where all ConfigSource instances are wrapped such that the %dev key is consulted first if I start with a certain flag.

@dmlloyd
Copy link
Contributor Author

dmlloyd commented Dec 17, 2018

As for the other use cases, this might be a handy way to implement them. I've already got property expansion working locally (I wasn't going to bother upstreaming it because it definitely violates the current spec, but this can be revisited). Snapshot/caching aren't something I need right now but they seem like fairly obvious applications of the mechanism; good to hear these behaviors are going upstream.

@jmesnil
Copy link
Contributor

jmesnil commented Dec 17, 2018

Does the % in %dev has a special meaning or is it a convention to identify "special" prefix?

there is a proposed mechanism similar to your profile: https://github.com/eclipse/microprofile-config/pull/392/files#diff-f61262f6aeaf46e63969779a53065af8R111

It's using suffixes instead of prefixes but the idea is the same and allows to specify configuration per project stages (or envs):

app.db.url=pgsql:...some production DB...
app.db.url.dev=h2:...something trivial...

The code would have to specified these:

URL dbURL = config.access("app.db.url", URL.class)
          .addLookupSuffix(config.access("config.projectStage", String.class).build())
          .build()
          .getValue();

if config.stage prop has the dev value, the config would look at app.db.url.dev before looking at app.db.url

@dmlloyd
Copy link
Contributor Author

dmlloyd commented Dec 17, 2018

I've just copied the convention used by Play. Plain suffixes are not a good idea though because there is a grammatical ambiguity.

@dmlloyd
Copy link
Contributor Author

dmlloyd commented Dec 17, 2018

I'll comment such on the proposal.

jmesnil added a commit that referenced this issue Dec 17, 2018
[#66] Add ability to wrap configuration sources (with tests)
@dmlloyd
Copy link
Contributor Author

dmlloyd commented Dec 18, 2018

Solved by #68.

@dmlloyd dmlloyd closed this as completed Dec 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants