ryanjbaxter

Add back missing logging.  Fixes 1679
This commit is contained in:
erabii
2024-07-25 15:16:00 +03:00
committed by GitHub
parent ad1917ad95
commit e4982f888d
2 changed files with 21 additions and 5 deletions

View File

@@ -28,6 +28,7 @@ import org.apache.commons.logging.LogFactory;
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;
@@ -126,7 +127,8 @@ public final class DiscoveryClientUtils {
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());
@@ -223,11 +225,21 @@ public final class DiscoveryClientUtils {
}
}
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.""");
}

View File

@@ -526,10 +526,12 @@ class DiscoveryClientUtilsTests {
.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."""));
}
@@ -562,10 +564,12 @@ class DiscoveryClientUtilsTests {
.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."""));
}