use of com.hubspot.deploy.HealthcheckOptions in project Singularity by HubSpot.
the class SingularityHealthchecksTest method testPortNumber.
@Test
public void testPortNumber() {
try {
setConfigurationForNoDelay();
initRequest();
HealthcheckOptions options = new HealthcheckOptionsBuilder("http://uri").setPortNumber(Optional.of(81L)).setStartupDelaySeconds(Optional.of(0)).build();
firstDeploy = initAndFinishDeploy(request, new SingularityDeployBuilder(request.getId(), firstDeployId).setCommand(Optional.of("sleep 100")).setResources(Optional.of(new Resources(1, 64, 3, 0))).setHealthcheck(Optional.of(options)), Optional.absent());
requestResource.postRequest(request.toBuilder().setInstances(Optional.of(2)).build(), singularityUser);
scheduler.drainPendingQueue();
String[] portRange = { "80:82" };
sms.resourceOffers(Arrays.asList(createOffer(20, 20000, 50000, "slave1", "host1", Optional.<String>absent(), Collections.<String, String>emptyMap(), portRange)));
SingularityTaskId firstTaskId = taskManager.getActiveTaskIdsForRequest(requestId).get(0);
SingularityTask firstTask = taskManager.getTask(firstTaskId).get();
statusUpdate(firstTask, TaskState.TASK_RUNNING);
newTaskChecker.enqueueNewTaskCheck(firstTask, requestManager.getRequest(requestId), healthchecker);
Awaitility.await("healthcheck present").atMost(5, TimeUnit.SECONDS).until(() -> taskManager.getLastHealthcheck(firstTask.getTaskId()).isPresent());
Assert.assertTrue(taskManager.getLastHealthcheck(firstTask.getTaskId()).get().toString().contains("host1:81"));
} finally {
unsetConfigurationForNoDelay();
}
}
use of com.hubspot.deploy.HealthcheckOptions in project Singularity by HubSpot.
the class SingularityHealthchecker method enqueueHealthcheck.
public void enqueueHealthcheck(SingularityTask task, boolean ignoreExisting, boolean inStartup, boolean isFirstCheck) {
HealthcheckOptions options = task.getTaskRequest().getDeploy().getHealthcheck().get();
final Optional<Integer> healthcheckMaxRetries = options.getMaxRetries().or(configuration.getHealthcheckMaxRetries());
Optional<Long> maybeRunningAt = getRunningAt(taskManager.getTaskHistoryUpdates(task.getTaskId()));
if (maybeRunningAt.isPresent()) {
final long durationSinceRunning = System.currentTimeMillis() - maybeRunningAt.get();
final int startupTimeout = options.getStartupTimeoutSeconds().or(configuration.getStartupTimeoutSeconds());
if (inStartup && durationSinceRunning > TimeUnit.SECONDS.toMillis(startupTimeout)) {
LOG.debug("{} since running", durationSinceRunning);
LOG.info("Not enqueuing new healthcheck for {}, has not responded to healthchecks before startup timeout of {}s", task.getTaskId(), startupTimeout);
return;
}
}
if (healthcheckMaxRetries.isPresent() && taskManager.getNumNonstartupHealthchecks(task.getTaskId()) > healthcheckMaxRetries.get()) {
LOG.info("Not enqueuing new healthcheck for {}, it has already attempted {} times", task.getTaskId(), healthcheckMaxRetries.get());
return;
}
ScheduledFuture<?> future = enqueueHealthcheckWithDelay(task, getDelaySeconds(task.getTaskId(), options, inStartup, isFirstCheck), inStartup);
ScheduledFuture<?> existing = taskIdToHealthcheck.put(task.getTaskId().getId(), future);
if (existing != null) {
boolean canceledExisting = existing.cancel(false);
if (!ignoreExisting) {
LOG.warn("Found existing overlapping healthcheck for task {} - cancel success: {}", task.getTaskId(), canceledExisting);
}
}
}
use of com.hubspot.deploy.HealthcheckOptions in project Singularity by HubSpot.
the class SingularityHealthchecker method getHealthcheckUri.
private Optional<String> getHealthcheckUri(SingularityTask task) {
if (!task.getTaskRequest().getDeploy().getHealthcheck().isPresent()) {
return Optional.absent();
}
HealthcheckOptions options = task.getTaskRequest().getDeploy().getHealthcheck().get();
final String hostname = task.getHostname();
Optional<Long> healthcheckPort = options.getPortNumber().or(MesosUtils.getPortByIndex(mesosProtosUtils.toResourceList(task.getMesosTask().getResources()), options.getPortIndex().or(0)));
if (!healthcheckPort.isPresent() || healthcheckPort.get() < 1L) {
LOG.warn("Couldn't find a port for health check for task {}", task);
return Optional.absent();
}
String uri = task.getTaskRequest().getDeploy().getHealthcheck().get().getUri();
if (uri.startsWith("/")) {
uri = uri.substring(1);
}
HealthcheckProtocol protocol = options.getProtocol().or(DEFAULT_HEALTH_CHECK_SCHEME);
return Optional.of(String.format("%s://%s:%d/%s", protocol.getProtocol(), hostname, healthcheckPort.get(), uri));
}
use of com.hubspot.deploy.HealthcheckOptions in project Singularity by HubSpot.
the class ValidatorTest method itForbidsHealthCheckStartupDelaysLongerThanKillWait.
@Test
public void itForbidsHealthCheckStartupDelaysLongerThanKillWait() {
// Default kill wait time is 10 minutes (600 seconds)
HealthcheckOptions healthCheck = new HealthcheckOptionsBuilder("/").setPortNumber(Optional.of(8080L)).setStartupDelaySeconds(Optional.of(10000)).build();
SingularityDeploy deploy = SingularityDeploy.newBuilder("1234567", "1234567").setHealthcheck(Optional.of(healthCheck)).build();
SingularityRequest request = new SingularityRequestBuilder("1234567", RequestType.SERVICE).build();
WebApplicationException exn = (WebApplicationException) catchThrowable(() -> validator.checkDeploy(request, deploy, Collections.emptyList(), Collections.emptyList()));
assertThat((String) exn.getResponse().getEntity()).contains("Health check startup delay");
}
use of com.hubspot.deploy.HealthcheckOptions in project Singularity by HubSpot.
the class ValidatorTest method itForbidsHealthCheckGreaterThanMaxTotalHealthCheck.
@Test
public void itForbidsHealthCheckGreaterThanMaxTotalHealthCheck() {
singularityConfiguration.setHealthcheckMaxTotalTimeoutSeconds(Optional.of(100));
createValidator();
// Total wait time on this request is (startup time) + ((interval) + (http timeout)) * (1 + retries)
// = 50 + (5 + 5) * (9 + 1)
// = 150
HealthcheckOptions healthCheck = new HealthcheckOptionsBuilder("/").setPortNumber(Optional.of(8080L)).setStartupTimeoutSeconds(Optional.of(50)).setIntervalSeconds(Optional.of(5)).setResponseTimeoutSeconds(Optional.of(5)).setMaxRetries(Optional.of(9)).build();
SingularityDeploy deploy = SingularityDeploy.newBuilder("1234567", "1234567").setHealthcheck(Optional.of(healthCheck)).setCommand(Optional.of("sleep 100;")).build();
SingularityRequest request = new SingularityRequestBuilder("1234567", RequestType.SERVICE).build();
WebApplicationException exn = (WebApplicationException) catchThrowable(() -> validator.checkDeploy(request, deploy, Collections.emptyList(), Collections.emptyList()));
assertThat((String) exn.getResponse().getEntity()).contains("Max healthcheck time");
}
Aggregations