Skip to content

Commit

Permalink
ryanjbaxter
Browse files Browse the repository at this point in the history
Add back missing logging.  Fixes 1679
  • Loading branch information
wind57 committed Jul 25, 2024
1 parent ad1917a commit e4982f8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import org.springframework.cloud.client.ServiceInstance;
import org.springframework.core.log.LogAccessor;
import org.springframework.util.StringUtils;

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

logWarnings();
logServiceSpecificWarning(serviceMetadata.name(), primaryPortName);
logGenericWarning();
Map.Entry<String, Integer> first = existingPorts.entrySet().iterator().next();
return new ServicePortNameAndNumber(first.getValue(), first.getKey());

Expand Down Expand Up @@ -223,11 +225,21 @@ private static Optional<ServicePortNameAndNumber> fromMap(Map<String, Integer> e
}
}

private static void logWarnings() {
private static void logServiceSpecificWarning(String serviceName, String primaryPortName) {
if (StringUtils.hasText(primaryPortName)) {
LOG.warn(() -> "Could not find a port named '" + primaryPortName + "', 'https', or 'http' for service '"
+ serviceName + "'.");
}
else {
LOG.warn(() -> "Could not find a port named 'https' or 'http' for service '" + serviceName + "'.");
}
}

private static void logGenericWarning() {
LOG.warn(() -> """
Make sure that either the primary-port-name label has been added to the service,
or spring.cloud.kubernetes.discovery.primary-port-name has been configured.
Alternatively name the primary port 'https' or 'http'
Alternatively name the primary port 'https' or 'http'.
An incorrect configuration may result in non-deterministic behaviour.""");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -526,10 +526,12 @@ void testEndpointsPortNullPrimaryPortName(CapturedOutput output) {
.contains("not found primary-port-name (with value: 'null') via properties or service labels"));
Assertions.assertTrue(output.getOut().contains("not found primary-port-name via 'https' to match port"));
Assertions.assertTrue(output.getOut().contains("not found primary-port-name via 'http' to match port"));
Assertions.assertTrue(
output.getOut().contains("Could not find a port named 'https' or 'http' for service 'spring-k8s'."));
Assertions.assertTrue(output.getOut().contains("""
Make sure that either the primary-port-name label has been added to the service,
or spring.cloud.kubernetes.discovery.primary-port-name has been configured.
Alternatively name the primary port 'https' or 'http'
Alternatively name the primary port 'https' or 'http'.
An incorrect configuration may result in non-deterministic behaviour."""));
}

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

Expand Down

0 comments on commit e4982f8

Please sign in to comment.