Skip to content

Commit

Permalink
Improve logging of Spring Cloud Config extension
Browse files Browse the repository at this point in the history
Relates to: #38445
  • Loading branch information
geoand committed Jan 29, 2024
1 parent 391ca5a commit 598f4d1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ public Iterable<ConfigSource> getConfigSources(final ConfigSourceContext context
VertxSpringCloudConfigGateway client = new VertxSpringCloudConfigGateway(config);
try {
List<Response> responses = new ArrayList<>();
for (String profile : determineProfiles(context, config)) {
List<String> profiles = determineProfiles(context, config);
log.debug("The following profiles will be used to look up properties: " + profiles);
for (String profile : profiles) {
Response response;
if (connectionTimeoutIsGreaterThanZero || readTimeoutIsGreaterThanZero) {
response = client.exchange(applicationName.getValue(), profile).await()
Expand All @@ -64,9 +66,13 @@ public Iterable<ConfigSource> getConfigSources(final ConfigSourceContext context

if (response.getProfiles().contains(profile)) {
responses.add(response);
} else {
log.debug("Response did not contain profile " + profile);
}
}

log.debug("Obtained " + responses.size() + " from the config server");

int ordinal = 450;
// Profiles are looked from the highest ordinal to lowest, so we reverse the collection to build the source list
Collections.reverse(responses);
Expand All @@ -76,7 +82,14 @@ public Iterable<ConfigSource> getConfigSources(final ConfigSourceContext context
Collections.reverse(propertySources);

for (PropertySource propertySource : propertySources) {
sources.add(SpringCloudPropertySource.from(propertySource, response.getProfiles(), ordinal++));
int ord = ordinal++;
if (log.isDebugEnabled()) {
log.debug("Adding PropertySource named '" + propertySource.getName() + "', with and ordinal of '" + ord
+ "' that contains the following keys: "
+ String.join(",", propertySource.getSource().keySet()));
}

sources.add(SpringCloudPropertySource.from(propertySource, response.getProfiles(), ord));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ public Uni<Response> exchange(String applicationName, String profile) {
}
log.debug("Attempting to read configuration from '" + finalURI + "'.");
return request.send().map(r -> {
log.debug("Received HTTP response code '" + r.statusCode() + "'");
if (r.statusCode() != 200) {
throw new RuntimeException("Got unexpected HTTP response code " + r.statusCode()
+ " from " + finalURI);
Expand All @@ -214,6 +215,7 @@ public Uni<Response> exchange(String applicationName, String profile) {
throw new RuntimeException("Got empty HTTP response body " + finalURI);
}
try {
log.debug("Attempting to deserialize response");
return OBJECT_MAPPER.readValue(bodyAsString, Response.class);
} catch (JsonProcessingException e) {
throw new RuntimeException("Got unexpected error " + e.getOriginalMessage());
Expand Down

0 comments on commit 598f4d1

Please sign in to comment.