Search in sources :

Example 6 with HealthcheckOptions

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();
    }
}
Also used : SingularityTask(com.hubspot.singularity.SingularityTask) HealthcheckOptions(com.hubspot.deploy.HealthcheckOptions) SingularityDeployBuilder(com.hubspot.singularity.SingularityDeployBuilder) Resources(com.hubspot.mesos.Resources) HealthcheckOptionsBuilder(com.hubspot.deploy.HealthcheckOptionsBuilder) SingularityTaskId(com.hubspot.singularity.SingularityTaskId) Test(org.junit.Test)

Example 7 with HealthcheckOptions

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);
        }
    }
}
Also used : HealthcheckOptions(com.hubspot.deploy.HealthcheckOptions)

Example 8 with HealthcheckOptions

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));
}
Also used : HealthcheckOptions(com.hubspot.deploy.HealthcheckOptions) HealthcheckProtocol(com.hubspot.singularity.HealthcheckProtocol)

Example 9 with HealthcheckOptions

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");
}
Also used : SingularityRequestBuilder(com.hubspot.singularity.SingularityRequestBuilder) WebApplicationException(javax.ws.rs.WebApplicationException) HealthcheckOptions(com.hubspot.deploy.HealthcheckOptions) SingularityRequest(com.hubspot.singularity.SingularityRequest) HealthcheckOptionsBuilder(com.hubspot.deploy.HealthcheckOptionsBuilder) SingularityDeploy(com.hubspot.singularity.SingularityDeploy) Test(org.junit.Test)

Example 10 with HealthcheckOptions

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");
}
Also used : SingularityRequestBuilder(com.hubspot.singularity.SingularityRequestBuilder) WebApplicationException(javax.ws.rs.WebApplicationException) HealthcheckOptions(com.hubspot.deploy.HealthcheckOptions) SingularityRequest(com.hubspot.singularity.SingularityRequest) HealthcheckOptionsBuilder(com.hubspot.deploy.HealthcheckOptionsBuilder) SingularityDeploy(com.hubspot.singularity.SingularityDeploy) Test(org.junit.Test)

Aggregations

HealthcheckOptions (com.hubspot.deploy.HealthcheckOptions)14 HealthcheckOptionsBuilder (com.hubspot.deploy.HealthcheckOptionsBuilder)11 Test (org.junit.Test)11 SingularityDeployBuilder (com.hubspot.singularity.SingularityDeployBuilder)10 SingularityDeploy (com.hubspot.singularity.SingularityDeploy)9 SingularityTask (com.hubspot.singularity.SingularityTask)9 SingularityTaskHealthcheckResult (com.hubspot.singularity.SingularityTaskHealthcheckResult)7 Resources (com.hubspot.mesos.Resources)2 SingularityRequest (com.hubspot.singularity.SingularityRequest)2 SingularityRequestBuilder (com.hubspot.singularity.SingularityRequestBuilder)2 SingularityTaskId (com.hubspot.singularity.SingularityTaskId)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 SingularityContainerInfo (com.hubspot.mesos.SingularityContainerInfo)1 SingularityMesosTaskLabel (com.hubspot.mesos.SingularityMesosTaskLabel)1 SingularityVolume (com.hubspot.mesos.SingularityVolume)1 HealthcheckProtocol (com.hubspot.singularity.HealthcheckProtocol)1 Map (java.util.Map)1