Skip to content

Commit

Permalink
fix(monitored deploy): add monitored deploy to same checks as RRB
Browse files Browse the repository at this point in the history
* add monitored deploy to checks where we check for RRB (since, semantically, they are same)
* make some better summary messages
  • Loading branch information
marchello2000 committed Sep 24, 2019
1 parent 10396bd commit 859b967
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ class AwsDeployStagePreProcessor implements DeployStagePreProcessor {
@Override
List<StepDefinition> additionalSteps(Stage stage) {
def stageData = stage.mapTo(StageData)
if (Strategy.fromStrategyKey(stageData.strategy) == Strategy.ROLLING_RED_BLACK) {
Strategy strategy = Strategy.fromStrategyKey(stageData.strategy)

if ((strategy == Strategy.ROLLING_RED_BLACK) || (strategy == Strategy.MONITORED)) {
// rolling red/black has no need to snapshot capacities
return []
}
Expand Down Expand Up @@ -114,7 +116,9 @@ class AwsDeployStagePreProcessor implements DeployStagePreProcessor {
List<StageDefinition> afterStageDefinitions(Stage stage) {
def stageData = stage.mapTo(StageData)
def stageDefinitions = []
if (Strategy.fromStrategyKey(stageData.strategy) != Strategy.ROLLING_RED_BLACK) {
Strategy strategy = Strategy.fromStrategyKey(stageData.strategy)

if ((strategy != Strategy.ROLLING_RED_BLACK) && (strategy != Strategy.MONITORED)) {
// rolling red/black has no need to apply a snapshotted capacity (on the newly created server group)
stageDefinitions << new StageDefinition(
name: "restoreMinCapacityFromSnapshot",
Expand Down Expand Up @@ -156,8 +160,11 @@ class AwsDeployStagePreProcessor implements DeployStagePreProcessor {
}

private static boolean shouldCheckServerGroupsPreconditions(StageData stageData) {
// TODO(dreynaud): enabling cautiously for RRB only for testing, but we would ideally roll this out to other strategies
return (Strategy.fromStrategyKey(stageData.strategy) == Strategy.ROLLING_RED_BLACK) && (stageData.maxInitialAsgs != -1)
// TODO(dreynaud): enabling cautiously for RRB/MD only for testing, but we would ideally roll this out to other strategies
Strategy strategy = Strategy.fromStrategyKey(stageData.strategy)

return (((strategy == Strategy.ROLLING_RED_BLACK) || (strategy == Strategy.MONITORED))
&& (stageData.maxInitialAsgs != -1))
}

private Optional<Map<String, Object>> getResizeContext(StageData stageData) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ class TitusDeployStagePreProcessor implements DeployStagePreProcessor {
@Override
List<StepDefinition> additionalSteps(Stage stage) {
def stageData = stage.mapTo(StageData)
if (Strategy.fromStrategyKey(stageData.strategy) == Strategy.ROLLING_RED_BLACK) {
Strategy strategy = Strategy.fromStrategyKey(stageData.strategy)

if ((strategy == Strategy.ROLLING_RED_BLACK) || (strategy == Strategy.MONITORED)) {
// rolling red/black has no need to snapshot capacities
return []
}
Expand All @@ -57,7 +59,9 @@ class TitusDeployStagePreProcessor implements DeployStagePreProcessor {
List<StageDefinition> afterStageDefinitions(Stage stage) {
def stageData = stage.mapTo(StageData)
def stageDefinitions = []
if (Strategy.fromStrategyKey(stageData.strategy) != Strategy.ROLLING_RED_BLACK) {
Strategy strategy = Strategy.fromStrategyKey(stageData.strategy)

if ((strategy != Strategy.ROLLING_RED_BLACK) && (strategy != Strategy.MONITORED)) {
// rolling red/black has no need to apply a snapshotted capacity (on the newly created server group)
stageDefinitions << new StageDefinition(
name: "restoreMinCapacityFromSnapshot",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class CreateServerGroupStage extends AbstractDeployStrategyStage {
def additionalRollbackContext = [:]

def strategy = Strategy.fromStrategyKey(stageData.strategy)
if (strategy == Strategy.ROLLING_RED_BLACK) {
if ((strategy == Strategy.ROLLING_RED_BLACK) || (strategy == Strategy.MONITORED)) {
// rollback is always supported regardless of where the failure occurred
strategySupportsRollback = true
additionalRollbackContext.enableAndDisableOnly = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package com.netflix.spinnaker.orca.clouddriver.pipeline.servergroup

import com.netflix.spinnaker.orca.clouddriver.pipeline.servergroup.support.TargetServerGroupLinearStageSupport
import com.netflix.spinnaker.orca.clouddriver.tasks.DetermineHealthProvidersTask
import com.netflix.spinnaker.orca.clouddriver.tasks.MonitorKatoTask
import com.netflix.spinnaker.orca.clouddriver.tasks.servergroup.ResizeServerGroupTask
import com.netflix.spinnaker.orca.clouddriver.tasks.servergroup.ServerGroupCacheForceRefreshTask
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
Expand All @@ -50,11 +48,28 @@ public class MonitoredDeployBaseTask implements RetryableTask {
protected final Logger log = LoggerFactory.getLogger(getClass());
protected Registry registry;
private DeploymentMonitorServiceProvider deploymentMonitorServiceProvider;
private final Map<EvaluateHealthResponse.NextStepDirective, String> summaryMapping =
new HashMap<>();

MonitoredDeployBaseTask(
DeploymentMonitorServiceProvider deploymentMonitorServiceProvider, Registry registry) {
this.deploymentMonitorServiceProvider = deploymentMonitorServiceProvider;
this.registry = registry;

// This could be in deck, but for now, I think it's valuable to have this show up in the JSON
// for easier debugging
summaryMapping.put(
EvaluateHealthResponse.NextStepDirective.WAIT,
"Waiting for deployment monitor to evaluate health of deployed instances");
summaryMapping.put(
EvaluateHealthResponse.NextStepDirective.ABORT,
"Deployment monitor deemed the deployed instances unhealthy, aborting deployment");
summaryMapping.put(
EvaluateHealthResponse.NextStepDirective.CONTINUE,
"Deployment monitor deemed the instances healthy, proceeding with deploy");
summaryMapping.put(
EvaluateHealthResponse.NextStepDirective.COMPLETE,
"Deployment monitor deemed the instances healthy and requested to complete the deployment early");
}

@Override
Expand Down Expand Up @@ -206,13 +221,16 @@ TaskResult buildTaskResult(
List<StatusReason> statusReasons =
Optional.ofNullable(response.getStatusReasons()).orElse(Collections.emptyList());

String summary = "Deployment monitor requested to: " + response.getNextStep().getDirective();
String summary =
summaryMapping.getOrDefault(
response.getNextStep().getDirective(), "Health evaluation results are unknown");
StatusExplanation explanation = new StatusExplanation(summary, statusReasons);

return taskResultBuilder.context("deploymentMonitorReasons", explanation).build();
}

TaskResult buildTaskResult(TaskResult.TaskResultBuilder taskResultBuilder, String summary) {
private TaskResult buildTaskResult(
TaskResult.TaskResultBuilder taskResultBuilder, String summary) {
StatusExplanation explanation = new StatusExplanation(summary);

return taskResultBuilder.context("deploymentMonitorReasons", explanation).build();
Expand Down

0 comments on commit 859b967

Please sign in to comment.