Skip to content

Commit

Permalink
Suppress echo notifications for SKIPPED and CANCELED statuses
Browse files Browse the repository at this point in the history
- If this becomes problematic, we could consider sending a different phase to echo and filtering on that side
  • Loading branch information
ajordens committed May 25, 2016
1 parent 7aa629b commit d2fba0f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ import org.springframework.beans.factory.annotation.Autowired
@CompileStatic
@Slf4j
class EchoNotifyingStageExecutionListener extends StageExecutionListener {
public static final Set<ExecutionStatus> SUPPRESSED_EXECUTION_STATUSES = [
ExecutionStatus.CANCELED,
ExecutionStatus.SKIPPED
] as Set<ExecutionStatus>

private final EchoService echoService

Expand All @@ -37,7 +41,7 @@ class EchoNotifyingStageExecutionListener extends StageExecutionListener {
}

void afterTask(Stage stage, StepExecution stepExecution) {
if (stepExecution.status.running) {
if (!shouldRecordEvent(stepExecution)) {
return
}
recordEvent('task', (wasSuccessful(stepExecution) ? "complete" : "failed"), stage, stepExecution)
Expand Down Expand Up @@ -86,4 +90,16 @@ class EchoNotifyingStageExecutionListener extends StageExecutionListener {
ExecutionStatus orcaTaskStatus = (ExecutionStatus) stepExecution.executionContext.get("orcaTaskStatus")
stepExecution.exitStatus.exitCode == ExitStatus.COMPLETED.exitCode || orcaTaskStatus?.isSuccessful()
}

/**
* Determines if an event should be recorded for this execution.
*/
private static boolean shouldRecordEvent(StepExecution stepExecution) {
if (stepExecution.status.running) {
return false
}

ExecutionStatus orcaTaskStatus = (ExecutionStatus) stepExecution.executionContext.get("orcaTaskStatus")
return (!SUPPRESSED_EXECUTION_STATUSES.contains(orcaTaskStatus))
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.netflix.spinnaker.orca.echo.spring

import com.netflix.spinnaker.orca.ExecutionStatus
import com.netflix.spinnaker.orca.echo.EchoService
import com.netflix.spinnaker.orca.pipeline.model.Orchestration
import com.netflix.spinnaker.orca.pipeline.model.OrchestrationStage
Expand All @@ -9,6 +10,7 @@ import com.netflix.spinnaker.orca.pipeline.persistence.ExecutionRepository
import org.springframework.batch.core.BatchStatus
import org.springframework.batch.core.ExitStatus
import org.springframework.batch.core.StepExecution
import org.springframework.batch.item.ExecutionContext
import spock.lang.Shared
import spock.lang.Specification
import spock.lang.Subject
Expand Down Expand Up @@ -83,6 +85,26 @@ class EchoNotifyingStepExecutionListenerSpec extends Specification {
BatchStatus.STARTING | _
}

@Unroll
def "does #action an event for #executionStatus"() {
given:
def stepExecution = Stub(StepExecution) {
getStatus() >> BatchStatus.COMPLETED
getExecutionContext() >> new ExecutionContext([orcaTaskStatus: executionStatus])
}

when:
echoListener.afterTask(new OrchestrationStage(new Orchestration(), ""), stepExecution)

then:
invocationCount * echoService._

where:
executionStatus << ExecutionStatus.values()
invocationCount = EchoNotifyingStageExecutionListener.SUPPRESSED_EXECUTION_STATUSES.contains(executionStatus) ? 0 : 1
action = invocationCount ? "trigger" : "not trigger"
}

@Unroll
def "sends the correct data to echo when the step completes with #batchStatus / #exitStatus.exitCode"() {
given:
Expand Down

0 comments on commit d2fba0f

Please sign in to comment.