Search in sources :

Example 1 with SingularityTaskReconciliationStatistics

use of com.hubspot.singularity.SingularityTaskReconciliationStatistics in project Singularity by HubSpot.

the class SingularityClient method getTaskReconciliationStatistics.

public Optional<SingularityTaskReconciliationStatistics> getTaskReconciliationStatistics() {
    final Function<String, String> uri = (host) -> String.format(TASK_RECONCILIATION_FORMAT, getApiBase(host));
    LOG.info("Fetch task reconciliation statistics from {}", uri);
    final long start = System.currentTimeMillis();
    HttpResponse response = executeRequest(uri, Method.GET, Optional.absent(), Collections.emptyMap());
    if (response.getStatusCode() == 404) {
        return Optional.absent();
    }
    checkResponse("task reconciliation statistics", response);
    LOG.info("Got task reconciliation statistics in {}ms", System.currentTimeMillis() - start);
    return Optional.of(response.getAs(SingularityTaskReconciliationStatistics.class));
}
Also used : SingularityTask(com.hubspot.singularity.SingularityTask) Arrays(java.util.Arrays) Method(com.hubspot.horizon.HttpRequest.Method) ExtendedTaskState(com.hubspot.singularity.ExtendedTaskState) SingularityTaskCleanupResult(com.hubspot.singularity.SingularityTaskCleanupResult) SingularityPaginatedResponse(com.hubspot.singularity.SingularityPaginatedResponse) SingularityWebhook(com.hubspot.singularity.SingularityWebhook) Provider(javax.inject.Provider) Retryer(com.github.rholder.retry.Retryer) RetryerBuilder(com.github.rholder.retry.RetryerBuilder) SingularityDeployRequest(com.hubspot.singularity.api.SingularityDeployRequest) RetryException(com.github.rholder.retry.RetryException) Inject(com.google.inject.Inject) SingularityRequestCleanup(com.hubspot.singularity.SingularityRequestCleanup) SingularityState(com.hubspot.singularity.SingularityState) LoggerFactory(org.slf4j.LoggerFactory) Random(java.util.Random) SingularityTaskReconciliationStatistics(com.hubspot.singularity.SingularityTaskReconciliationStatistics) SingularityRequestGroup(com.hubspot.singularity.SingularityRequestGroup) SingularityDisasterType(com.hubspot.singularity.SingularityDisasterType) SingularityBounceRequest(com.hubspot.singularity.api.SingularityBounceRequest) SingularityPauseRequest(com.hubspot.singularity.api.SingularityPauseRequest) SingularityUpdateGroupsRequest(com.hubspot.singularity.api.SingularityUpdateGroupsRequest) Optional(com.google.common.base.Optional) Map(java.util.Map) HttpRequest(com.hubspot.horizon.HttpRequest) HttpClient(com.hubspot.horizon.HttpClient) TypeReference(com.fasterxml.jackson.core.type.TypeReference) SingularityPriorityFreeze(com.hubspot.singularity.api.SingularityPriorityFreeze) SingularityDisabledAction(com.hubspot.singularity.SingularityDisabledAction) SingularityPendingTaskId(com.hubspot.singularity.SingularityPendingTaskId) SingularityTaskId(com.hubspot.singularity.SingularityTaskId) SingularityUnpauseRequest(com.hubspot.singularity.api.SingularityUnpauseRequest) SingularityMachineChangeRequest(com.hubspot.singularity.api.SingularityMachineChangeRequest) SingularityDisastersData(com.hubspot.singularity.SingularityDisastersData) ImmutableMap(com.google.common.collect.ImmutableMap) SingularityPriorityFreezeParent(com.hubspot.singularity.SingularityPriorityFreezeParent) Predicate(java.util.function.Predicate) Collection(java.util.Collection) SingularityUpdatePendingDeployRequest(com.hubspot.singularity.SingularityUpdatePendingDeployRequest) List(java.util.List) SingularityTaskShellCommandRequest(com.hubspot.singularity.SingularityTaskShellCommandRequest) SingularityTaskShellCommandUpdate(com.hubspot.singularity.SingularityTaskShellCommandUpdate) StopStrategies(com.github.rholder.retry.StopStrategies) SingularityClusterUtilization(com.hubspot.singularity.SingularityClusterUtilization) OrderDirection(com.hubspot.singularity.OrderDirection) SingularityAuthorizationScope(com.hubspot.singularity.SingularityAuthorizationScope) Entry(java.util.Map.Entry) SingularitySandbox(com.hubspot.singularity.SingularitySandbox) SingularityS3Log(com.hubspot.singularity.SingularityS3Log) SingularityDisabledActionRequest(com.hubspot.singularity.api.SingularityDisabledActionRequest) SingularityCreateResult(com.hubspot.singularity.SingularityCreateResult) SingularityRequest(com.hubspot.singularity.SingularityRequest) SingularityTaskHistoryUpdate(com.hubspot.singularity.SingularityTaskHistoryUpdate) SingularityShellCommand(com.hubspot.singularity.SingularityShellCommand) SingularityRequestHistory(com.hubspot.singularity.SingularityRequestHistory) SingularityTaskIdHistory(com.hubspot.singularity.SingularityTaskIdHistory) SingularityPendingRequest(com.hubspot.singularity.SingularityPendingRequest) SingularityTaskShellCommandHistory(com.hubspot.singularity.SingularityTaskShellCommandHistory) HashMap(java.util.HashMap) SingularityClientCredentials(com.hubspot.singularity.SingularityClientCredentials) SingularityDeployUpdate(com.hubspot.singularity.SingularityDeployUpdate) Function(java.util.function.Function) SingularityTaskIdsByStatus(com.hubspot.singularity.SingularityTaskIdsByStatus) SingularityTaskState(com.hubspot.singularity.SingularityTaskState) SingularityExitCooldownRequest(com.hubspot.singularity.api.SingularityExitCooldownRequest) ArrayList(java.util.ArrayList) Builder(com.google.common.collect.ImmutableMap.Builder) ImmutableList(com.google.common.collect.ImmutableList) SingularitySlave(com.hubspot.singularity.SingularitySlave) SingularityDeleteResult(com.hubspot.singularity.SingularityDeleteResult) SingularityDeployKey(com.hubspot.singularity.SingularityDeployKey) RetryStrategy(com.hubspot.horizon.RetryStrategy) HttpResponse(com.hubspot.horizon.HttpResponse) SingularityPendingRequestParent(com.hubspot.singularity.SingularityPendingRequestParent) WaitStrategies(com.github.rholder.retry.WaitStrategies) SingularityAction(com.hubspot.singularity.SingularityAction) SingularityDeployHistory(com.hubspot.singularity.SingularityDeployHistory) Logger(org.slf4j.Logger) SingularityTaskHistory(com.hubspot.singularity.SingularityTaskHistory) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) SingularityDeploy(com.hubspot.singularity.SingularityDeploy) SingularityRack(com.hubspot.singularity.SingularityRack) ExecutionException(java.util.concurrent.ExecutionException) SingularityKillTaskRequest(com.hubspot.singularity.api.SingularityKillTaskRequest) SingularityTaskRequest(com.hubspot.singularity.SingularityTaskRequest) MachineState(com.hubspot.singularity.MachineState) SingularityRequestParent(com.hubspot.singularity.SingularityRequestParent) SingularityDeleteRequestRequest(com.hubspot.singularity.api.SingularityDeleteRequestRequest) SingularityRunNowRequest(com.hubspot.singularity.api.SingularityRunNowRequest) Named(com.google.inject.name.Named) SingularityScaleRequest(com.hubspot.singularity.api.SingularityScaleRequest) MesosFileChunkObject(com.hubspot.mesos.json.MesosFileChunkObject) Collections(java.util.Collections) HttpResponse(com.hubspot.horizon.HttpResponse) SingularityTaskReconciliationStatistics(com.hubspot.singularity.SingularityTaskReconciliationStatistics)

Example 2 with SingularityTaskReconciliationStatistics

use of com.hubspot.singularity.SingularityTaskReconciliationStatistics in project Singularity by HubSpot.

the class SingularityTaskReconciliation method checkReconciliation.

private void checkReconciliation(final long reconciliationStart, final Collection<SingularityTaskId> remainingTaskIds, final int numTimes, final Histogram histogram) {
    final List<SingularityTaskStatusHolder> taskStatusHolders = taskManager.getLastActiveTaskStatusesFor(remainingTaskIds);
    final List<MesosTaskStatusObject> taskStatuses = Lists.newArrayListWithCapacity(taskStatusHolders.size());
    for (SingularityTaskStatusHolder taskStatusHolder : taskStatusHolders) {
        if (taskStatusHolder.getServerId().equals(serverId) && taskStatusHolder.getServerTimestamp() > reconciliationStart) {
            histogram.update(taskStatusHolder.getServerTimestamp() - reconciliationStart);
            continue;
        }
        if (taskStatusHolder.getTaskStatus().isPresent()) {
            LOG.debug("Re-requesting task status for {}", taskStatusHolder.getTaskId());
            taskStatuses.add(taskStatusHolder.getTaskStatus().get());
        } else {
            TaskStatus.Builder fakeTaskStatusBuilder = TaskStatus.newBuilder().setTaskId(TaskID.newBuilder().setValue(taskStatusHolder.getTaskId().getId())).setState(TaskState.TASK_STARTING);
            if (taskStatusHolder.getSlaveId().isPresent()) {
                fakeTaskStatusBuilder.setAgentId(AgentID.newBuilder().setValue(taskStatusHolder.getSlaveId().get()));
            }
            LOG.info("Task {} didn't have a TaskStatus yet, submitting fake status", taskStatusHolder.getTaskId());
            taskStatuses.add(mesosProtosUtils.taskStatusFromProtos(fakeTaskStatusBuilder.build()));
        }
    }
    if (taskStatuses.isEmpty()) {
        LOG.info("Task reconciliation ended after {} checks and {}", numTimes, JavaUtils.duration(reconciliationStart));
        final Snapshot snapshot = histogram.getSnapshot();
        stateManager.saveTaskReconciliationStatistics(new SingularityTaskReconciliationStatistics(reconciliationStart, System.currentTimeMillis() - reconciliationStart, numTimes, histogram.getCount(), snapshot.getMax(), snapshot.getMean(), snapshot.getMin(), snapshot.getMedian(), snapshot.get75thPercentile(), snapshot.get95thPercentile(), snapshot.get98thPercentile(), snapshot.get99thPercentile(), snapshot.get999thPercentile(), snapshot.getStdDev()));
        isRunningReconciliation.set(false);
        return;
    }
    LOG.info("Requesting reconciliation of {} taskStatuses, task reconciliation has been running for {}", taskStatuses.size(), JavaUtils.duration(reconciliationStart));
    schedulerClient.reconcile(taskStatuses.stream().map((t) -> Task.newBuilder().setTaskId(MesosProtosUtils.toTaskId(t.getTaskId())).setAgentId(MesosProtosUtils.toAgentId(t.getAgentId())).build()).collect(Collectors.toList()));
    scheduleReconciliationCheck(reconciliationStart, remainingTaskIds, numTimes, histogram);
}
Also used : MesosTaskStatusObject(com.hubspot.mesos.protos.MesosTaskStatusObject) Snapshot(com.codahale.metrics.Snapshot) SingularityTaskStatusHolder(com.hubspot.singularity.SingularityTaskStatusHolder) TaskStatus(org.apache.mesos.v1.Protos.TaskStatus) SingularityTaskReconciliationStatistics(com.hubspot.singularity.SingularityTaskReconciliationStatistics)

Aggregations

Snapshot (com.codahale.metrics.Snapshot)1 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 RetryException (com.github.rholder.retry.RetryException)1 Retryer (com.github.rholder.retry.Retryer)1 RetryerBuilder (com.github.rholder.retry.RetryerBuilder)1 StopStrategies (com.github.rholder.retry.StopStrategies)1 WaitStrategies (com.github.rholder.retry.WaitStrategies)1 Optional (com.google.common.base.Optional)1 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Builder (com.google.common.collect.ImmutableMap.Builder)1 Inject (com.google.inject.Inject)1 Named (com.google.inject.name.Named)1 HttpClient (com.hubspot.horizon.HttpClient)1 HttpRequest (com.hubspot.horizon.HttpRequest)1 Method (com.hubspot.horizon.HttpRequest.Method)1 HttpResponse (com.hubspot.horizon.HttpResponse)1 RetryStrategy (com.hubspot.horizon.RetryStrategy)1 MesosFileChunkObject (com.hubspot.mesos.json.MesosFileChunkObject)1