From 598f4d1242b6712358e565d11d533893feb0c5a8 Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Mon, 29 Jan 2024 16:31:35 +0200 Subject: [PATCH] Improve logging of Spring Cloud Config extension Relates to: #38445 --- ...ingCloudConfigClientConfigSourceFactory.java | 17 +++++++++++++++-- .../runtime/VertxSpringCloudConfigGateway.java | 2 ++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/extensions/spring-cloud-config-client/runtime/src/main/java/io/quarkus/spring/cloud/config/client/runtime/SpringCloudConfigClientConfigSourceFactory.java b/extensions/spring-cloud-config-client/runtime/src/main/java/io/quarkus/spring/cloud/config/client/runtime/SpringCloudConfigClientConfigSourceFactory.java index 85b8068d808c4..1684d1d170c39 100644 --- a/extensions/spring-cloud-config-client/runtime/src/main/java/io/quarkus/spring/cloud/config/client/runtime/SpringCloudConfigClientConfigSourceFactory.java +++ b/extensions/spring-cloud-config-client/runtime/src/main/java/io/quarkus/spring/cloud/config/client/runtime/SpringCloudConfigClientConfigSourceFactory.java @@ -53,7 +53,9 @@ public Iterable getConfigSources(final ConfigSourceContext context VertxSpringCloudConfigGateway client = new VertxSpringCloudConfigGateway(config); try { List responses = new ArrayList<>(); - for (String profile : determineProfiles(context, config)) { + List 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() @@ -64,9 +66,13 @@ public Iterable 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); @@ -76,7 +82,14 @@ public Iterable 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)); } } diff --git a/extensions/spring-cloud-config-client/runtime/src/main/java/io/quarkus/spring/cloud/config/client/runtime/VertxSpringCloudConfigGateway.java b/extensions/spring-cloud-config-client/runtime/src/main/java/io/quarkus/spring/cloud/config/client/runtime/VertxSpringCloudConfigGateway.java index 6c23a986f0063..6a2608d0c0b37 100644 --- a/extensions/spring-cloud-config-client/runtime/src/main/java/io/quarkus/spring/cloud/config/client/runtime/VertxSpringCloudConfigGateway.java +++ b/extensions/spring-cloud-config-client/runtime/src/main/java/io/quarkus/spring/cloud/config/client/runtime/VertxSpringCloudConfigGateway.java @@ -205,6 +205,7 @@ public Uni 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); @@ -214,6 +215,7 @@ public Uni 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());