Skip to content

Commit

Permalink
fix(monitored deploy): add monitored deploy to same checks as RRB (#3190
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 25, 2019
1 parent 9aa603a commit 74e65d9
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ import static com.netflix.spinnaker.orca.kato.pipeline.support.ResizeStrategySup

@Component
class AwsDeployStagePreProcessor implements DeployStagePreProcessor {
private static final List<Strategy> rollingStrategies = [Strategy.ROLLING_RED_BLACK, Strategy.MONITORED]

@Autowired
ApplySourceServerGroupCapacityStage applySourceServerGroupSnapshotStage

Expand All @@ -51,7 +53,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 (rollingStrategies.contains(strategy)) {
// rolling red/black has no need to snapshot capacities
return []
}
Expand Down Expand Up @@ -114,8 +118,10 @@ 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) {
// rolling red/black has no need to apply a snapshotted capacity (on the newly created server group)
Strategy strategy = Strategy.fromStrategyKey(stageData.strategy)

if (!rollingStrategies.contains(strategy)) {
// rolling strategies have no need to apply a snapshotted capacity (on the newly created server group)
stageDefinitions << new StageDefinition(
name: "restoreMinCapacityFromSnapshot",
stageDefinitionBuilder: applySourceServerGroupSnapshotStage,
Expand Down Expand Up @@ -152,12 +158,14 @@ class AwsDeployStagePreProcessor implements DeployStagePreProcessor {

private static boolean shouldPinSourceServerGroup(String strategy) {
// TODO-AJ consciously only enabling for rolling red/black -- will add support for other strategies after it's working
return (Strategy.fromStrategyKey(strategy) == Strategy.ROLLING_RED_BLACK)
return (rollingStrategies.contains(Strategy.fromStrategyKey(strategy)))
}

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 (rollingStrategies.contains(strategy) && (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 @@ -28,13 +28,17 @@ import org.springframework.stereotype.Component

@Component
class TitusDeployStagePreProcessor implements DeployStagePreProcessor {
private static final List<Strategy> rollingStrategies = [Strategy.ROLLING_RED_BLACK, Strategy.MONITORED]

@Autowired
ApplySourceServerGroupCapacityStage applySourceServerGroupSnapshotStage

@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 (rollingStrategies.contains(strategy)) {
// rolling red/black has no need to snapshot capacities
return []
}
Expand All @@ -57,8 +61,10 @@ 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) {
// rolling red/black has no need to apply a snapshotted capacity (on the newly created server group)
Strategy strategy = Strategy.fromStrategyKey(stageData.strategy)

if (!rollingStrategies.contains(strategy)) {
// rolling strategies have no need to apply a snapshotted capacity (on the newly created server group)
stageDefinitions << new StageDefinition(
name: "restoreMinCapacityFromSnapshot",
stageDefinitionBuilder: applySourceServerGroupSnapshotStage,
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 74e65d9

Please sign in to comment.