use of com.hubspot.singularity.SingularityRequestHistory in project Singularity by HubSpot.
the class SingularitySchedulerTest method testCleanerFindsTasksWithSkippedHealthchecks.
@Test
public void testCleanerFindsTasksWithSkippedHealthchecks() {
initRequest();
// set up agents so scale validate will pass
resourceOffers(2);
SingularityRequest request = requestResource.getRequest(requestId, singularityUser).getRequest();
long now = System.currentTimeMillis();
requestManager.saveHistory(new SingularityRequestHistory(now, Optional.<String>empty(), RequestHistoryType.UPDATED, request.toBuilder().setSkipHealthchecks(Optional.of(true)).setInstances(Optional.of(2)).build(), Optional.<String>empty()));
firstDeploy = initDeploy(new SingularityDeployBuilder(request.getId(), firstDeployId).setCommand(Optional.of("sleep 100")).setHealthcheckUri(Optional.of("http://uri")), System.currentTimeMillis());
SingularityTask taskOne = launchTask(request, firstDeploy, now + 1000, now + 2000, 1, TaskState.TASK_RUNNING);
finishDeploy(new SingularityDeployMarker(requestId, firstDeployId, now + 2000, Optional.<String>empty(), Optional.<String>empty()), firstDeploy);
SingularityRequest updatedRequest = request.toBuilder().setSkipHealthchecks(Optional.<Boolean>empty()).setInstances(Optional.of(2)).build();
requestManager.saveHistory(new SingularityRequestHistory(now + 3000, Optional.<String>empty(), RequestHistoryType.UPDATED, updatedRequest, Optional.<String>empty()));
SingularityTask newTaskTwoWithCheck = prepTask(updatedRequest, firstDeploy, now + 4000, 2);
taskManager.createTaskAndDeletePendingTask(newTaskTwoWithCheck);
statusUpdate(newTaskTwoWithCheck, TaskState.TASK_RUNNING, Optional.of(now + 5000));
taskManager.saveHealthcheckResult(new SingularityTaskHealthcheckResult(Optional.of(200), Optional.of(1000L), now + 6000, Optional.<String>empty(), Optional.<String>empty(), newTaskTwoWithCheck.getTaskId(), Optional.<Boolean>empty()));
SingularityTask unhealthyTaskThree = prepTask(updatedRequest, firstDeploy, now + 4000, 3);
taskManager.createTaskAndDeletePendingTask(unhealthyTaskThree);
statusUpdate(unhealthyTaskThree, TaskState.TASK_RUNNING, Optional.of(now + 5000));
List<SingularityTaskId> activeTaskIds = taskManager.getActiveTaskIdsForRequest(requestId);
List<SingularityTaskId> healthyTaskIds = deployHealthHelper.getHealthyTasks(updatedRequest, firstDeploy, activeTaskIds, false);
Assertions.assertTrue(!healthyTaskIds.contains(unhealthyTaskThree.getTaskId()));
// Healthchecked and skip-healthchecked tasks should both be here
Assertions.assertEquals(2, healthyTaskIds.size());
Assertions.assertEquals(DeployHealth.WAITING, deployHealthHelper.getDeployHealth(updatedRequest, firstDeploy, activeTaskIds, false));
taskManager.saveHealthcheckResult(new SingularityTaskHealthcheckResult(Optional.of(200), Optional.of(1000L), now + 6000, Optional.<String>empty(), Optional.<String>empty(), unhealthyTaskThree.getTaskId(), Optional.<Boolean>empty()));
Assertions.assertEquals(DeployHealth.HEALTHY, deployHealthHelper.getDeployHealth(updatedRequest, firstDeploy, activeTaskIds, false));
}
use of com.hubspot.singularity.SingularityRequestHistory in project Singularity by HubSpot.
the class S3LogResource method getS3PrefixesForRequest.
private Collection<String> getS3PrefixesForRequest(S3Configuration s3Configuration, String requestId, Optional<Long> startArg, Optional<Long> endArg, String group) {
Optional<SingularityRequestHistory> firstHistory = requestHistoryHelper.getFirstHistory(requestId);
if (!startArg.isPresent()) {
checkBadRequest(firstHistory.isPresent(), "No request history found for %s. A start time must be specified.", requestId);
}
long start = Math.max(startArg.orElse(0L), firstHistory.get().getCreatedAt());
Optional<SingularityRequestHistory> lastHistory = requestHistoryHelper.getLastHistory(requestId);
long end = System.currentTimeMillis();
if (lastHistory.isPresent() && (lastHistory.get().getEventType() == RequestHistoryType.DELETED || lastHistory.get().getEventType() == RequestHistoryType.PAUSED)) {
end = lastHistory.get().getCreatedAt() + TimeUnit.DAYS.toMillis(1);
}
if (endArg.isPresent()) {
end = Math.min(endArg.get(), end);
}
Collection<String> prefixes = SingularityS3FormatHelper.getS3KeyPrefixes(s3Configuration.getS3KeyFormat(), requestId, start, end, group);
for (SingularityS3UploaderFile additionalFile : s3Configuration.getS3UploaderAdditionalFiles()) {
if (additionalFile.getS3UploaderKeyPattern().isPresent() && !additionalFile.getS3UploaderKeyPattern().get().equals(s3Configuration.getS3KeyFormat())) {
prefixes.addAll(SingularityS3FormatHelper.getS3KeyPrefixes(additionalFile.getS3UploaderKeyPattern().get(), requestId, start, end, group));
}
}
LOG.trace("Request {} got S3 prefixes {} for start {}, end {}", requestId, prefixes, start, end);
return prefixes;
}
use of com.hubspot.singularity.SingularityRequestHistory in project Singularity by HubSpot.
the class SingularityDeployHealthHelper method getHealthcheckedHealthyTasks.
private List<SingularityTaskId> getHealthcheckedHealthyTasks(final SingularityDeploy deploy, final Collection<SingularityTaskId> matchingActiveTasks, final boolean isDeployPending) {
final Map<SingularityTaskId, SingularityTaskHealthcheckResult> healthcheckResults = taskManager.getLastHealthcheck(matchingActiveTasks);
final List<SingularityTaskId> healthyTaskIds = Lists.newArrayListWithCapacity(matchingActiveTasks.size());
List<SingularityRequestHistory> requestHistories = requestManager.getRequestHistory(deploy.getRequestId());
for (SingularityTaskId taskId : matchingActiveTasks) {
DeployHealth individualTaskHealth;
if (healthchecksSkipped(taskId, requestHistories, deploy)) {
LOG.trace("Detected skipped healthchecks for {}", taskId);
individualTaskHealth = DeployHealth.HEALTHY;
} else {
individualTaskHealth = getTaskHealth(deploy, isDeployPending, Optional.ofNullable(healthcheckResults.get(taskId)), taskId);
}
if (individualTaskHealth == DeployHealth.HEALTHY) {
healthyTaskIds.add(taskId);
}
}
return healthyTaskIds;
}
use of com.hubspot.singularity.SingularityRequestHistory in project Singularity by HubSpot.
the class SnsWebhookRetryer method checkWebhooks.
public void checkWebhooks() {
for (SingularityTaskHistoryUpdate taskHistoryUpdate : webhookManager.getTaskUpdatesToRetry()) {
Optional<SingularityTask> task = taskHistoryHelper.getTask(taskHistoryUpdate.getTaskId());
if (task.isPresent()) {
snsWebhookManager.taskWebhook(new SingularityTaskWebhook(task.get(), taskHistoryUpdate));
}
webhookManager.deleteTaskUpdateForRetry(taskHistoryUpdate);
}
for (SingularityDeployUpdate deployUpdate : webhookManager.getDeployUpdatesToRetry()) {
snsWebhookManager.deployHistoryEvent(deployUpdate);
webhookManager.deleteDeployUpdateForRetry(deployUpdate);
}
for (SingularityRequestHistory requestHistory : webhookManager.getRequestUpdatesToRetry()) {
snsWebhookManager.requestHistoryEvent(requestHistory);
webhookManager.deleteRequestUpdateForRetry(requestHistory);
}
for (CrashLoopInfo crashLoopUpdate : webhookManager.getCrashLoopUpdatesToRetry()) {
snsWebhookManager.crashLoopEvent(crashLoopUpdate);
webhookManager.deleteCrashLoopUpdateForRetry(crashLoopUpdate);
}
}
use of com.hubspot.singularity.SingularityRequestHistory in project Singularity by HubSpot.
the class BlendedHistoryTest method testBlendedRequestHistory.
// DESCENDING
@Test
public void testBlendedRequestHistory() {
HistoryManager hm = mock(HistoryManager.class);
String rid = "rid";
SingularityRequestHistoryQuery requestHistoryQuery = new SingularityRequestHistoryQuery(rid, Optional.empty(), Optional.empty(), Optional.empty());
request = new SingularityRequestBuilder(rid, RequestType.WORKER).build();
RequestHistoryHelper rhh = new RequestHistoryHelper(requestManager, hm, new SingularityConfiguration());
mockRequestHistory(hm, Collections.<SingularityRequestHistory>emptyList());
Assertions.assertTrue(rhh.getBlendedHistory(requestHistoryQuery, 0, 100).isEmpty());
Assertions.assertTrue(!rhh.getFirstHistory(rid).isPresent());
Assertions.assertTrue(!rhh.getLastHistory(rid).isPresent());
mockRequestHistory(hm, Arrays.asList(makeHistory(52, RequestHistoryType.EXITED_COOLDOWN), makeHistory(51, RequestHistoryType.ENTERED_COOLDOWN), makeHistory(50, RequestHistoryType.CREATED)));
List<SingularityRequestHistory> history = rhh.getBlendedHistory(requestHistoryQuery, 0, 5);
Assertions.assertTrue(history.size() == 3);
saveHistory(100, RequestHistoryType.DELETED);
saveHistory(120, RequestHistoryType.CREATED);
history = rhh.getBlendedHistory(requestHistoryQuery, 0, 5);
Assertions.assertTrue(history.size() == 5);
Assertions.assertTrue(history.get(0).getCreatedAt() == 120);
Assertions.assertTrue(history.get(4).getCreatedAt() == 50);
history = rhh.getBlendedHistory(requestHistoryQuery, 1, 5);
Assertions.assertTrue(history.size() == 4);
Assertions.assertTrue(history.get(0).getCreatedAt() == 100);
Assertions.assertTrue(history.get(3).getCreatedAt() == 50);
history = rhh.getBlendedHistory(requestHistoryQuery, 2, 5);
Assertions.assertTrue(history.size() == 3);
Assertions.assertTrue(history.get(0).getCreatedAt() == 52);
Assertions.assertTrue(history.get(2).getCreatedAt() == 50);
mockRequestHistory(hm, Collections.<SingularityRequestHistory>emptyList());
history = rhh.getBlendedHistory(requestHistoryQuery, 3, 5);
Assertions.assertTrue(history.isEmpty());
history = rhh.getBlendedHistory(requestHistoryQuery, 1, 5);
Assertions.assertTrue(history.size() == 1);
Assertions.assertTrue(history.get(0).getCreatedAt() == 100);
Assertions.assertTrue(rhh.getFirstHistory(rid).get().getCreatedAt() == 100);
Assertions.assertTrue(rhh.getLastHistory(rid).get().getCreatedAt() == 120);
mockRequestHistory(hm, Arrays.asList(makeHistory(1, RequestHistoryType.EXITED_COOLDOWN)));
Assertions.assertTrue(rhh.getFirstHistory(rid).get().getCreatedAt() == 1);
Assertions.assertTrue(rhh.getLastHistory(rid).get().getCreatedAt() == 120);
}
Aggregations