Skip to content

Commit e4982f8

Browse files
authored
ryanjbaxter
Add back missing logging. Fixes 1679
1 parent ad1917a commit e4982f8

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/DiscoveryClientUtils.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import org.springframework.cloud.client.ServiceInstance;
3030
import org.springframework.core.log.LogAccessor;
31+
import org.springframework.util.StringUtils;
3132

3233
import static org.springframework.cloud.kubernetes.commons.config.ConfigUtils.keysWithPrefix;
3334
import static org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryConstants.EXTERNAL_NAME;
@@ -126,7 +127,8 @@ public static ServicePortNameAndNumber endpointsPort(Map<String, Integer> existi
126127
return portData.get();
127128
}
128129

129-
logWarnings();
130+
logServiceSpecificWarning(serviceMetadata.name(), primaryPortName);
131+
logGenericWarning();
130132
Map.Entry<String, Integer> first = existingPorts.entrySet().iterator().next();
131133
return new ServicePortNameAndNumber(first.getValue(), first.getKey());
132134

@@ -223,11 +225,21 @@ private static Optional<ServicePortNameAndNumber> fromMap(Map<String, Integer> e
223225
}
224226
}
225227

226-
private static void logWarnings() {
228+
private static void logServiceSpecificWarning(String serviceName, String primaryPortName) {
229+
if (StringUtils.hasText(primaryPortName)) {
230+
LOG.warn(() -> "Could not find a port named '" + primaryPortName + "', 'https', or 'http' for service '"
231+
+ serviceName + "'.");
232+
}
233+
else {
234+
LOG.warn(() -> "Could not find a port named 'https' or 'http' for service '" + serviceName + "'.");
235+
}
236+
}
237+
238+
private static void logGenericWarning() {
227239
LOG.warn(() -> """
228240
Make sure that either the primary-port-name label has been added to the service,
229241
or spring.cloud.kubernetes.discovery.primary-port-name has been configured.
230-
Alternatively name the primary port 'https' or 'http'
242+
Alternatively name the primary port 'https' or 'http'.
231243
An incorrect configuration may result in non-deterministic behaviour.""");
232244
}
233245

spring-cloud-kubernetes-commons/src/test/java/org/springframework/cloud/kubernetes/commons/discovery/DiscoveryClientUtilsTests.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,10 +526,12 @@ void testEndpointsPortNullPrimaryPortName(CapturedOutput output) {
526526
.contains("not found primary-port-name (with value: 'null') via properties or service labels"));
527527
Assertions.assertTrue(output.getOut().contains("not found primary-port-name via 'https' to match port"));
528528
Assertions.assertTrue(output.getOut().contains("not found primary-port-name via 'http' to match port"));
529+
Assertions.assertTrue(
530+
output.getOut().contains("Could not find a port named 'https' or 'http' for service 'spring-k8s'."));
529531
Assertions.assertTrue(output.getOut().contains("""
530532
Make sure that either the primary-port-name label has been added to the service,
531533
or spring.cloud.kubernetes.discovery.primary-port-name has been configured.
532-
Alternatively name the primary port 'https' or 'http'
534+
Alternatively name the primary port 'https' or 'http'.
533535
An incorrect configuration may result in non-deterministic behaviour."""));
534536
}
535537

@@ -562,10 +564,12 @@ void testEndpointsPortPrimaryPortNameIsPresentButNotFound(CapturedOutput output)
562564
.contains("not found primary-port-name (with value: 'three') via properties or service labels"));
563565
Assertions.assertTrue(output.getOut().contains("not found primary-port-name via 'https' to match port"));
564566
Assertions.assertTrue(output.getOut().contains("not found primary-port-name via 'http' to match port"));
567+
Assertions.assertTrue(output.getOut()
568+
.contains("Could not find a port named 'three', 'https', or 'http' for service 'spring-k8s'."));
565569
Assertions.assertTrue(output.getOut().contains("""
566570
Make sure that either the primary-port-name label has been added to the service,
567571
or spring.cloud.kubernetes.discovery.primary-port-name has been configured.
568-
Alternatively name the primary port 'https' or 'http'
572+
Alternatively name the primary port 'https' or 'http'.
569573
An incorrect configuration may result in non-deterministic behaviour."""));
570574
}
571575

0 commit comments

Comments
 (0)