Skip to content
Closed
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 @@ -23,11 +23,13 @@ public CloudProcess derive() {
Integer healthCheckTimeout = null;
String healthCheckHttpEndpoint = null;
Integer healthCheckInvocationTimeout = null;
Integer healthCheckInterval = null;
if (healthCheck.getData() != null) {
Data healthCheckData = healthCheck.getData();
healthCheckTimeout = healthCheckData.getTimeout();
healthCheckInvocationTimeout = healthCheckData.getInvocationTimeout();
healthCheckHttpEndpoint = healthCheckData.getEndpoint();
healthCheckInterval = healthCheckData.getInterval();
}
Integer readinessHealthCheckInvocationTimeout = null;
String readinessHealthCheckHttpEndpoint = null;
Expand All @@ -49,6 +51,7 @@ public CloudProcess derive() {
.healthCheckHttpEndpoint(healthCheckHttpEndpoint)
.healthCheckTimeout(healthCheckTimeout)
.healthCheckInvocationTimeout(healthCheckInvocationTimeout)
.healthCheckInterval(healthCheckInterval)
.readinessHealthCheckType(readinessHealthCheckType.getType()
.getValue())
.readinessHealthCheckHttpEndpoint(readinessHealthCheckHttpEndpoint)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public abstract class CloudProcess extends CloudEntity implements Derivable<Clou
@Nullable
public abstract Integer getHealthCheckTimeout();

@Nullable
public abstract Integer getHealthCheckInterval();

@Nullable
public abstract Integer getReadinessHealthCheckInterval();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ public interface Staging {
@Nullable
String getHealthCheckHttpEndpoint();

/**
* @return health check interval
*/
@Nullable
Integer getHealthCheckInterval();

/**
* @return readiness health check interval
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ private HealthCheck buildHealthCheck(Staging staging) {
.endpoint(staging.getHealthCheckHttpEndpoint())
.timeout(staging.getHealthCheckTimeout())
.invocationTimeout(staging.getInvocationTimeout())
.interval(staging.getHealthCheckInterval())
.build())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
package org.cloudfoundry.multiapps.controller.client.facade.adapters;

import org.cloudfoundry.client.v3.processes.Data;
import org.cloudfoundry.client.v3.processes.HealthCheck;
import org.cloudfoundry.client.v3.processes.HealthCheckType;
import org.cloudfoundry.client.v3.processes.Process;
import org.cloudfoundry.client.v3.processes.ReadinessHealthCheck;
import org.cloudfoundry.client.v3.processes.ReadinessHealthCheckType;
import org.cloudfoundry.multiapps.controller.client.facade.domain.CloudProcess;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

class RawCloudProcessTest {

private static final Integer HEALTH_CHECK_TIMEOUT = 60;
private static final Integer HEALTH_CHECK_INVOCATION_TIMEOUT = 5;
private static final Integer HEALTH_CHECK_INTERVAL = 15;
private static final String HEALTH_CHECK_HTTP_ENDPOINT = "/health";
private static final Integer READINESS_HEALTH_CHECK_INVOCATION_TIMEOUT = 4;
private static final Integer READINESS_HEALTH_CHECK_INTERVAL = 30;
private static final String READINESS_HEALTH_CHECK_HTTP_ENDPOINT = "/ready";
private static final Integer INSTANCES = 2;
private static final Integer MEMORY_IN_MB = 256;
private static final Integer DISK_IN_MB = 512;
private static final String COMMAND = "start.sh";

@Test
void testDeriveRoundTripsHealthCheckInterval() {
Process process = buildProcess(buildHealthCheckWithInterval(HEALTH_CHECK_INTERVAL),
buildReadinessHealthCheckWithInterval(READINESS_HEALTH_CHECK_INTERVAL));

CloudProcess cloudProcess = ImmutableRawCloudProcess.of(process)
.derive();

assertEquals(HEALTH_CHECK_INTERVAL, cloudProcess.getHealthCheckInterval());
}

@Test
void testDeriveHealthCheckIntervalIsNullWhenHealthCheckDataIsNull() {
Process process = buildProcess(buildHealthCheckWithoutData(),
buildReadinessHealthCheckWithInterval(READINESS_HEALTH_CHECK_INTERVAL));

CloudProcess cloudProcess = ImmutableRawCloudProcess.of(process)
.derive();

assertNull(cloudProcess.getHealthCheckInterval());
}

@Test
void testDeriveHealthCheckIntervalIsNullWhenIntervalNotSetOnData() {
Process process = buildProcess(buildHealthCheckWithInterval(null),
buildReadinessHealthCheckWithInterval(READINESS_HEALTH_CHECK_INTERVAL));

CloudProcess cloudProcess = ImmutableRawCloudProcess.of(process)
.derive();

assertNull(cloudProcess.getHealthCheckInterval());
}

@Test
void testDeriveHealthCheckIntervalDoesNotCollideWithReadinessInterval() {
Process process = buildProcess(buildHealthCheckWithInterval(HEALTH_CHECK_INTERVAL),
buildReadinessHealthCheckWithInterval(READINESS_HEALTH_CHECK_INTERVAL));

CloudProcess cloudProcess = ImmutableRawCloudProcess.of(process)
.derive();

assertEquals(HEALTH_CHECK_INTERVAL, cloudProcess.getHealthCheckInterval());
assertEquals(READINESS_HEALTH_CHECK_INTERVAL, cloudProcess.getReadinessHealthCheckInterval());
}

private static Process buildProcess(HealthCheck healthCheck, ReadinessHealthCheck readinessHealthCheck) {
Process process = Mockito.mock(Process.class);
Mockito.when(process.getHealthCheck())
.thenReturn(healthCheck);
Mockito.when(process.getReadinessHealthCheck())
.thenReturn(readinessHealthCheck);
Mockito.when(process.getCommand())
.thenReturn(COMMAND);
Mockito.when(process.getInstances())
.thenReturn(INSTANCES);
Mockito.when(process.getMemoryInMb())
.thenReturn(MEMORY_IN_MB);
Mockito.when(process.getDiskInMb())
.thenReturn(DISK_IN_MB);
return process;
}

private static HealthCheck buildHealthCheckWithInterval(Integer interval) {
return HealthCheck.builder()
.type(HealthCheckType.HTTP)
.data(Data.builder()
.endpoint(HEALTH_CHECK_HTTP_ENDPOINT)
.timeout(HEALTH_CHECK_TIMEOUT)
.invocationTimeout(HEALTH_CHECK_INVOCATION_TIMEOUT)
.interval(interval)
.build())
.build();
}

private static HealthCheck buildHealthCheckWithoutData() {
return HealthCheck.builder()
.type(HealthCheckType.PROCESS)
.build();
}

private static ReadinessHealthCheck buildReadinessHealthCheckWithInterval(Integer interval) {
return ReadinessHealthCheck.builder()
.type(ReadinessHealthCheckType.HTTP)
.data(Data.builder()
.endpoint(READINESS_HEALTH_CHECK_HTTP_ENDPOINT)
.invocationTimeout(READINESS_HEALTH_CHECK_INVOCATION_TIMEOUT)
.interval(interval)
.build())
.build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public class SupportedParameters {
public static final String HEALTH_CHECK_TIMEOUT = "health-check-timeout";
public static final String HEALTH_CHECK_TYPE = "health-check-type";
public static final String HEALTH_CHECK_HTTP_ENDPOINT = "health-check-http-endpoint";
public static final String HEALTH_CHECK_INTERVAL = "health-check-interval";
public static final String READINESS_HEALTH_CHECK_TYPE = "readiness-health-check-type";
public static final String READINESS_HEALTH_CHECK_HTTP_ENDPOINT = "readiness-health-check-http-endpoint";
public static final String READINESS_HEALTH_CHECK_INVOCATION_TIMEOUT = "readiness-health-check-invocation-timeout";
Expand Down Expand Up @@ -190,6 +191,7 @@ public class SupportedParameters {
DEPENDENCY_TYPE, DISK_QUOTA, DOCKER, DOMAIN, DOMAINS, DEFAULT_DOMAIN,
ENABLE_SSH, ENABLE_PARALLEL_SERVICE_BINDINGS, HEALTH_CHECK_HTTP_ENDPOINT,
HEALTH_CHECK_TIMEOUT, HEALTH_CHECK_INVOCATION_TIMEOUT, HEALTH_CHECK_TYPE,
HEALTH_CHECK_INTERVAL,
HOST, HOSTS, IDLE_DOMAIN, IDLE_DOMAINS, IDLE_HOST, IDLE_HOSTS, IDLE_ROUTES,
INSTANCES, KEEP_EXISTING_APPLICATION_ATTRIBUTES_UPDATE_STRATEGY,
KEEP_EXISTING_ROUTES, MEMORY, NO_ROUTE, NO_START, RESTART_ON_ENV_CHANGE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public Staging parse(List<Map<String, Object>> parametersList) {
String healthCheckHttpEndpoint = (String) PropertiesUtil.getPropertyValue(parametersList,
SupportedParameters.HEALTH_CHECK_HTTP_ENDPOINT,
getDefaultHealthCheckHttpEndpoint(healthCheckType));
Integer healthCheckInterval = (Integer) PropertiesUtil.getPropertyValue(parametersList, SupportedParameters.HEALTH_CHECK_INTERVAL,
null);
String readinessHealthCheckType = (String) PropertiesUtil.getPropertyValue(parametersList,
SupportedParameters.READINESS_HEALTH_CHECK_TYPE, null);
String readinessHealthCheckHttpEndpoint = (String) PropertiesUtil.getPropertyValue(parametersList,
Expand Down Expand Up @@ -69,6 +71,7 @@ public Staging parse(List<Map<String, Object>> parametersList) {
.invocationTimeout(healthCheckInvocationTimeout)
.healthCheckType(healthCheckType)
.healthCheckHttpEndpoint(healthCheckHttpEndpoint)
.healthCheckInterval(healthCheckInterval)
.readinessHealthCheckType(readinessHealthCheckType)
.readinessHealthCheckHttpEndpoint(readinessHealthCheckHttpEndpoint)
.readinessHealthCheckInvocationTimeout(readinessHealthCheckInvocationTimeout)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,36 @@ void testValidateWithAllParametersMissing() {
assertNull(staging.getDockerInfo());
}

@Test
void testParseHealthCheckIntervalWhenSet() {
parametersList.add(mapOf("health-check-interval", 15));

Staging staging = parser.parse(parametersList);

assertNotNull(staging);
assertEquals(Integer.valueOf(15), staging.getHealthCheckInterval());
}

@Test
void testParseHealthCheckIntervalDefaultsToNullWhenAbsent() {
Staging staging = parser.parse(parametersList);

assertNotNull(staging);
assertNull(staging.getHealthCheckInterval());
}

@Test
void testParseHealthCheckIntervalIsIndependentOfReadinessHealthCheckInterval() {
parametersList.add(mapOf("health-check-interval", 10));
parametersList.add(mapOf("readiness-health-check-interval", 30));

Staging staging = parser.parse(parametersList);

assertNotNull(staging);
assertEquals(Integer.valueOf(10), staging.getHealthCheckInterval());
assertEquals(Integer.valueOf(30), staging.getReadinessHealthCheckInterval());
}

private static Map<String, Object> mapOf(String key, Object value) {
return Collections.singletonMap(key, value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,8 @@ public class Messages {
public static final String IGNORING_NOT_FOUND_OPTIONAL_SERVICE = "Service {0} not found but is optional";
public static final String IGNORING_NOT_FOUND_INACTIVE_SERVICE = "Service {0} not found but is inactive";

public static final String MTA_USES_HEALTH_CHECK_INTERVAL_PARAMETER = "MTA with ID \"{0}\" associated with operation ID \"{1}\" uses health check interval parameter: interval=\"{2}\", buildpacks=\"{3}\", moduleType=\"{4}\"";

// Not log messages
public static final String SERVICE_TYPE = "{0}/{1}";
public static final String PARSE_NULL_STRING_ERROR = "Cannot parse null string";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.List;

import org.cloudfoundry.multiapps.controller.core.model.SupportedParameters;
import org.cloudfoundry.multiapps.controller.process.Messages;
import org.cloudfoundry.multiapps.controller.process.steps.ProcessContext;
import org.cloudfoundry.multiapps.controller.process.variables.Variables;
import org.cloudfoundry.multiapps.mta.model.Module;
Expand Down Expand Up @@ -33,13 +34,19 @@ public void reportUsageOfAdditionalParameters(Module module) {
.get(SupportedParameters.READINESS_HEALTH_CHECK_INVOCATION_TIMEOUT);
Integer readinessHealthCheckInterval = (Integer) module.getParameters()
.get(SupportedParameters.READINESS_HEALTH_CHECK_INTERVAL);
Integer healthCheckInterval = (Integer) module.getParameters()
.get(SupportedParameters.HEALTH_CHECK_INTERVAL);
List<String> buildpacks = PropertiesUtil.getPluralOrSingular(List.of(module.getParameters()), SupportedParameters.BUILDPACKS,
SupportedParameters.BUILDPACK);
if (readinessHealthCheckType != null) {
reportUsageOfReadinessHealthCheckParameters(mtaId, correlationId, readinessHealthCheckType, readinessHealthCheckHttpEndpoint,
readinessHealthCheckInvocationTimeout, readinessHealthCheckInterval,
buildpacks.toString(), module.getType());
}
if (healthCheckInterval != null) {
reportUsageOfLivenessHealthCheckIntervalParameter(mtaId, correlationId, healthCheckInterval, buildpacks.toString(),
module.getType());
}
}

// this method is being observed by Dynatrace, be careful if you change it
Expand All @@ -51,4 +58,11 @@ private void reportUsageOfReadinessHealthCheckParameters(String mtaId, String co
mtaId, correlationId, readinessHealthCheckType, readinessHealthCheckHttpEndpoint,
readinessHealthCheckInvocationTimeout, readinessHealthCheckInterval, buildpacks, moduleType));
}

// this method is being observed by Dynatrace, be careful if you change it
private void reportUsageOfLivenessHealthCheckIntervalParameter(String mtaId, String correlationId, Integer healthCheckInterval,
String buildpacks, String moduleType) {
LOGGER.info(MessageFormat.format(Messages.MTA_USES_HEALTH_CHECK_INTERVAL_PARAMETER, mtaId, correlationId, healthCheckInterval,
buildpacks, moduleType));
}
}
Loading
Loading