Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue-Fix-#2665 feat: added implementation for explicit path for readiness and liveness Probes #3036

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class SpringBootConfiguration {
private String managementContextPath;
private String actuatorBasePath;
private String actuatorDefaultBasePath;
private boolean managementHealthProbesEnabled;

public static SpringBootConfiguration from(JavaProject project) {
final Properties properties = SpringBootUtil.getSpringBootApplicationProperties(
Expand All @@ -56,6 +57,7 @@ public static SpringBootConfiguration from(JavaProject project) {
.managementPort(Optional.ofNullable(properties.getProperty("management.port")).map(Integer::parseInt).orElse(null))
.serverPort(Integer.parseInt(properties.getProperty("server.port", DEFAULT_SERVER_PORT)))
.serverKeystore(properties.getProperty("server.ssl.key-store"))
.managementHealthProbesEnabled(Boolean.parseBoolean(properties.getProperty("management.health.probes.enabled")))
.managementKeystore(properties.getProperty("management.ssl.key-store"))
.servletPath(properties.getProperty("server.servlet-path"))
.serverContextPath(properties.getProperty("server.context-path"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public class SpringBootHealthCheckEnricher extends AbstractHealthCheckEnricher {
private static final String SCHEME_HTTPS = "HTTPS";
private static final String SCHEME_HTTP = "HTTP";

private static final String LIVENESS_PROBE_SUFFIX = "/liveness";
private static final String READINESS_PROBE_SUFFIX = "/readiness";

@AllArgsConstructor
private enum Config implements Configs.Config {
READINESS_PROBE_INITIAL_DELAY_SECONDS("readinessProbeInitialDelaySeconds", "10"),
Expand Down Expand Up @@ -67,7 +70,7 @@ protected Probe getReadinessProbe() {
Integer timeout = Configs.asInteger(getConfig(Config.TIMEOUT_SECONDS));
Integer failureThreshold = Configs.asInteger(getConfig(Config.FAILURE_THRESHOLD));
Integer successThreshold = Configs.asInteger(getConfig(Config.SUCCESS_THRESHOLD));
return discoverSpringBootHealthCheck(initialDelay, period, timeout, failureThreshold, successThreshold);
return discoverSpringBootHealthCheck(initialDelay, period, timeout, failureThreshold, successThreshold, READINESS_PROBE_SUFFIX);
}

@Override
Expand All @@ -77,21 +80,21 @@ protected Probe getLivenessProbe() {
Integer timeout = Configs.asInteger(getConfig(Config.TIMEOUT_SECONDS));
Integer failureThreshold = Configs.asInteger(getConfig(Config.FAILURE_THRESHOLD));
Integer successThreshold = Configs.asInteger(getConfig(Config.SUCCESS_THRESHOLD));
return discoverSpringBootHealthCheck(initialDelay, period, timeout, failureThreshold, successThreshold);
return discoverSpringBootHealthCheck(initialDelay, period, timeout, failureThreshold, successThreshold, LIVENESS_PROBE_SUFFIX);
}

protected Probe discoverSpringBootHealthCheck(Integer initialDelay, Integer period, Integer timeout, Integer failureTh, Integer successTh) {
protected Probe discoverSpringBootHealthCheck(Integer initialDelay, Integer period, Integer timeout, Integer failureTh, Integer successTh, String suffix) {
try {
if (getContext().getProjectClassLoaders().isClassInCompileClasspath(true, REQUIRED_CLASSES)) {
return buildProbe(initialDelay, period, timeout, failureTh, successTh);
return buildProbe(initialDelay, period, timeout, failureTh, successTh, suffix);
}
} catch (Exception ex) {
log.error("Error while reading the spring-boot configuration", ex);
}
return null;
}

protected Probe buildProbe(Integer initialDelay, Integer period, Integer timeout, Integer failureTh, Integer successTh) {
protected Probe buildProbe(Integer initialDelay, Integer period, Integer timeout, Integer failureTh, Integer successTh, String suffix) {
final SpringBootConfiguration springBootConfiguration = SpringBootConfiguration.from(getContext().getProject());
Integer managementPort = springBootConfiguration.getManagementPort();
boolean usingManagementPort = managementPort != null;
Expand Down Expand Up @@ -122,9 +125,16 @@ protected Probe buildProbe(Integer initialDelay, Integer period, Integer timeout
actuatorBasePath = springBootConfiguration.getActuatorBasePath();
}

// adds suffix to probe paths when ManagementHealthProbesEnabled is true
String probePath = prefix + actuatorBasePath + Configs.asString(getConfig(Config.PATH));
if(springBootConfiguration.isManagementHealthProbesEnabled()){
probePath += suffix;
}
probePath = normalizeMultipleSlashes(probePath);

// lets default to adding a spring boot actuator health check
ProbeBuilder probeBuilder = new ProbeBuilder().
withNewHttpGet().withNewPort(port).withPath(normalizeMultipleSlashes(prefix + actuatorBasePath + Configs.asString(getConfig(Config.PATH)))).withScheme(scheme).endHttpGet();
withNewHttpGet().withNewPort(port).withPath(probePath).withScheme(scheme).endHttpGet();

if (initialDelay != null) {
probeBuilder = probeBuilder.withInitialDelaySeconds(initialDelay);
Expand Down
Loading