spring-projects / spring-projects/spring-boot

Include list of effective properties in environment endpoint's response

Open
#19,505 2 comments 0 reactions 1 assignee View on GitHub

@philwebb is already working on this.

Since Jul 19, 2021.

type: enhancement
Dominant language
Java
Stars
81.5k
Forks
42.7k
Avg merge
2d 4h
Merged PRs (30d)
65

Description

Currently, EnvironmentEndpoint shows where all of PropertySources are coming from including duplicated keys(overrides) if they are from different sources. (e.g.: one from application.yaml and same key from application-<profile>.yaml)

Usually, while troubleshooting or debugging, what people want to find out is the final value resolved by the Environment.(actual value resolved by @Value("x.y.z") etc.)
Current /env can serve the purpose, but may need to go through several hoops to get the correct answer if there are overrides.

Having final property key-values as part of EnvironmentEndpoint would give clear answer what key-values are used in application.

Such property sources considering override can be obtained like this:

Map<String, Object> map = new HashMap<>();
for (PropertySource<?> propertySource : ((ConfigurableEnvironment) this.environment).getPropertySources()) {
    if (propertySource instanceof EnumerablePropertySource) {
        for (String key : ((EnumerablePropertySource<?>) propertySource).getPropertyNames()) {
            map.putIfAbsent(key, propertySource.getProperty(key));
        }
    }
}
// may sort the map with key...

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.