-
Notifications
You must be signed in to change notification settings - Fork 42
Add health checks again #1685
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
Add health checks again #1685
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,36 +3,41 @@ | |
| import org.cloudfoundry.client.v3.applications.GetApplicationProcessStatisticsResponse; | ||
| import org.cloudfoundry.client.v3.processes.ProcessState; | ||
| import org.cloudfoundry.client.v3.processes.ProcessStatisticsResource; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import org.cloudfoundry.multiapps.controller.client.facade.domain.ImmutableInstanceInfo; | ||
| import org.cloudfoundry.multiapps.controller.client.facade.domain.ImmutableInstancesInfo; | ||
| import org.cloudfoundry.multiapps.controller.client.facade.domain.InstanceState; | ||
| import org.cloudfoundry.multiapps.controller.client.facade.domain.InstancesInfo; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| class RawInstancesInfoTest { | ||
|
|
||
| @Test | ||
| void testDerive() { | ||
| RawCloudEntityTest.testDerive(buildExpectedInstancesInfo(), buildActualInstancesInfo()); | ||
| void testDeriveWithTrueRoutable() { | ||
| RawCloudEntityTest.testDerive(buildExpectedInstancesInfo(true), buildActualInstancesInfo("true")); | ||
| } | ||
|
|
||
| @Test | ||
| void testDeriveWithFalseRoutable() { | ||
| RawCloudEntityTest.testDerive(buildExpectedInstancesInfo(false), buildActualInstancesInfo("false")); | ||
| } | ||
|
|
||
| private InstancesInfo buildExpectedInstancesInfo() { | ||
| private InstancesInfo buildExpectedInstancesInfo(boolean expectedRoutable) { | ||
| return ImmutableInstancesInfo.builder() | ||
| .addInstance(ImmutableInstanceInfo.builder() | ||
| .index(0) | ||
| .state(InstanceState.RUNNING) | ||
| .isRoutable(expectedRoutable) | ||
| .build()) | ||
| .build(); | ||
| } | ||
|
|
||
| private RawInstancesInfo buildActualInstancesInfo() { | ||
| private RawInstancesInfo buildActualInstancesInfo(String routable) { | ||
| return ImmutableRawInstancesInfo.builder() | ||
| .processStatisticsResponse(getApplicationProcessStatisticsResponse()) | ||
| .processStatisticsResponse(getApplicationProcessStatisticsResponse(routable)) | ||
| .build(); | ||
| } | ||
|
|
||
| private GetApplicationProcessStatisticsResponse getApplicationProcessStatisticsResponse() { | ||
| private GetApplicationProcessStatisticsResponse getApplicationProcessStatisticsResponse(String routable) { | ||
| return GetApplicationProcessStatisticsResponse.builder() | ||
| .resource(ProcessStatisticsResource.builder() | ||
| .index(0) | ||
|
|
@@ -43,6 +48,7 @@ private GetApplicationProcessStatisticsResponse getApplicationProcessStatisticsR | |
| .type("web") | ||
| .uptime(9042L) | ||
| .fileDescriptorQuota(1024L) | ||
| .routable(routable) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why value is not boolean?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because in the ProcessStatisticsResource class the routable variable is String |
||
| .host("10.244.16.10") | ||
| .build()) | ||
| .build(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ | |
| import org.cloudfoundry.multiapps.controller.client.facade.domain.CloudRoute; | ||
| import org.cloudfoundry.multiapps.controller.client.facade.domain.InstanceInfo; | ||
| import org.cloudfoundry.multiapps.controller.client.facade.domain.InstanceState; | ||
| import org.cloudfoundry.multiapps.controller.client.lib.domain.CloudApplicationExtended; | ||
| import org.cloudfoundry.multiapps.controller.core.cf.CloudControllerClientFactory; | ||
| import org.cloudfoundry.multiapps.controller.core.security.token.TokenService; | ||
| import org.cloudfoundry.multiapps.controller.core.util.UriUtil; | ||
|
|
@@ -79,14 +80,13 @@ private StartupStatus getStartupStatus(ProcessContext context, String appName, L | |
| long downInstances = getInstanceCount(appInstances, InstanceState.DOWN); | ||
| long crashedInstances = getInstanceCount(appInstances, InstanceState.CRASHED); | ||
| long startingInstances = getInstanceCount(appInstances, InstanceState.STARTING); | ||
|
|
||
| String states = composeStatesMessage(appInstances); | ||
|
|
||
| context.getStepLogger() | ||
| .debug(Messages.APPLICATION_0_X_OF_Y_INSTANCES_RUNNING, appName, runningInstances, expectedInstances, states); | ||
|
|
||
| if (runningInstances == expectedInstances) { | ||
| return StartupStatus.STARTED; | ||
| return checkIfAppHasStarted(context, appInstances); | ||
| } | ||
| if (startingInstances > 0) { | ||
| return StartupStatus.STARTING; | ||
|
|
@@ -100,6 +100,28 @@ private StartupStatus getStartupStatus(ProcessContext context, String appName, L | |
| return StartupStatus.STARTING; | ||
| } | ||
|
|
||
| private StartupStatus checkIfAppHasStarted(ProcessContext context, List<InstanceInfo> appInstances) { | ||
| if (shouldWaitForAppToBecomeRoutable(context)) { | ||
| if (isThereAtLeastOneRoutedInstance(appInstances)) { | ||
| return StartupStatus.STARTED; | ||
| } | ||
| return StartupStatus.STARTING; | ||
| } | ||
| return StartupStatus.STARTED; | ||
| } | ||
|
|
||
| private boolean shouldWaitForAppToBecomeRoutable(ProcessContext context) { | ||
| CloudApplicationExtended appToProcess = context.getVariable(Variables.APP_TO_PROCESS); | ||
|
|
||
| return appToProcess.getStaging() | ||
| .getReadinessHealthCheckType() != null; | ||
| } | ||
|
|
||
| private boolean isThereAtLeastOneRoutedInstance(List<InstanceInfo> instanceInfos) { | ||
| return instanceInfos.stream() | ||
| .anyMatch(InstanceInfo::isRoutable); | ||
| } | ||
|
Comment on lines
+120
to
+123
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We will be checking if there is at least one routeable instance? Compared to current approach with the started state, we wait for all instances. This is inconsistency, is it deliberately this way?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, if there is defined readiness health check type, we will wait for one instance to be routable instead of all of them. If there isn't readiness health check type defined, we will work like we do now |
||
|
|
||
| private AsyncExecutionState checkStartupStatus(ProcessContext context, CloudApplication app, StartupStatus status) { | ||
| if (status == StartupStatus.CRASHED) { | ||
| onError(context, Messages.ERROR_STARTING_APP_0_DESCRIPTION_1, app.getName(), Messages.SOME_INSTANCES_HAVE_CRASHED); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can readinessHealthCheckType be null and throw npe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the type can't be null because it has default value. In the documentation is said that the default value is process