spring-projects / spring-projects/spring-boot

No logs during Spring Boot config import

Open
#28,678 6 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

As of Spring Boot 2.4, the default (preferred) way to import additional configuration is using spring.config.import property. However, I have noticed some logging issues since then.

The configuration is loaded before the environment is set up, and that incudes logging properties. Although ConfigDataLocationResolver and ConfigDataLoader classes accept a DeferredLog instance in their constructors, this logger can only be used by the config import "plugin" itself, and not so easily when this plugin uses third-party libraries to achieve the task.

For example, spring-cloud-zookeeper-config uses Zookeeper client to retrieve configuration. This library uses log4j, and cannot be replaced by Apache Commons Log. Even if using SLF4J bridge, that is not yet configured by the time the import is taking place. The consequence is that we do not have logs related to Zookeeper (which can make troubleshooting more difficult). If the connection string is not correct or the server is down, the import phase will happily last until some timeout expires, with no logs in the meantime. You can try that out specifying an invalid port:

spring.config.import: zookeeper:localhost:8888

The application startup hangs for 1 minute, and then fails:

********************* 2021-11-15T09:28:48.483Z:  org.springframework.boot.context.event.ApplicationStartingEvent
********************* 2021-11-15T09:29:35.471Z: org.springframework.boot.context.event.ApplicationFailedEvent
10:29:35.519 [main] DEBUG org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter - Application failed to start due to an exception
org.springframework.boot.context.config.ConfigDataResourceNotFoundException: Config data resource '[ZookeeperConfigDataResource@28d18df5 context = 'config/srv-nuc-jee-Bank-v4,dev', optional = false, profile = 'dev']' via location 'zookeeper:localhost:8888' cannot be found
	at org.springframework.boot.context.config.ConfigDataResourceNotFoundException.withLocation(ConfigDataResourceNotFoundException.java:97)
	at org.springframework.boot.context.config.ConfigDataImporter.handle(ConfigDataImporter.java:145)
...
Caused by: org.apache.zookeeper.KeeperException$ConnectionLossException: KeeperErrorCode = ConnectionLoss for /config/srv-nuc-jee-Bank-v4,dev
	at org.apache.zookeeper.KeeperException.create(KeeperException.java:102)
	at org.apache.zookeeper.KeeperException.create(KeeperException.java:54)

Note that this problem is not specific to this Zookeeper loader; it will affect to any loader using third-party libraries.

As an enhancement, please consider enabling some initial logging config during the bootstrap phase. That config could then be overriden by the properties imported from the remote source.

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.

Research direction

Start with ConfigDataLocationResolver, ConfigDataLoader, DeferredLog, and ConfigDataImporter, then reproduce the issue with spring.config.import set to zookeeper:localhost:8888. Trace how logging behaves before the environment is set up and review the reported third-party-library constraint. Done means bootstrap configuration provides useful import-phase logs while allowing imported properties to override it.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring-boot
Domain
backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.