Skip to content

Comparion of solutions to resolve conflicting keys in multiple sources (provide ordering for sources)

Ondrej Mihályi edited this page Mar 2, 2017 · 1 revision

Prblems that we want to solve

  • Prevent accidental overwrites
  • Enable intentional overwrites of configuration keys defined by the app or its dependencies

More thorough summary here.

Problem 1: Prevent accidental overwrites

We generally agree that this it makes sense and would be enough to define namespace conventions to prevent accidental overwrites among config sources. The conventions haven't been discussed yet.

Problem 2: Enable intentional overwrites

Couple of solutions were discussed (see the summary linked above). The below solutions have been demonstrated by code examples:

Solution 2.1: Ordinals defined by sources

Short description

Each custom config source defines a method to return its ordinal (a number). The higher the more important. If a property is specified in multiple config sources, the value in the config source with the highest ordinal will be used. Default config sources have predefined ordinals (System properties: 400, Environment properties: 300, files in META-INF: 100)

The code example in microprofile-config repository (in master branch).

Pros

  • supports auto-discovery out of the box, new sources can be ordered automatically (source)

Cons

  • if dynamically auto-discovered config sources are discouraged from clashing (e.g. by namespaces), then no need to order auto-discovered sources. Known sources (static or statically discovered) can be sorted by config.xml if referenced by name (source
  • hard to find the proper ordinal value if a new source needs to go between 2 other sources (source)
  • if ordinals have the same value, no deterministic way to sort sources (source)
  • ordinals are inflexible and implicitly define the ordering being a concern of the ConfigSource, instead of the component managing the config sources (source)

Comments

  • Not clear how to overwrite the default ordinal specified by a config source (if config source contained in a library or provided by a container)
    • Maybe define a property that, if defined within the config source keys, would overwrite its ordinal? (source)
    • Not so simple with some config sources (source)

Authors

@struberg

Solution 2.2: Sources ordered by a comparator

Short description

TODO