Skip to content

Commit

Permalink
perf(echo): don't send task events
Browse files Browse the repository at this point in the history
To reduce load on echo and the downstream consumers of echo events when task event information is not needed. Configurable by setting echo.events.ignoreTaskEvents=true.
  • Loading branch information
Richard Timpson authored and dbyron-sf committed Jan 20, 2025
1 parent 93f27cc commit 3b913b8
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import static com.netflix.spinnaker.orca.api.pipeline.models.ExecutionType.ORCHE
@Slf4j
class EchoNotifyingStageListener implements StageListener {
public static final String INCLUDE_FULL_EXECUTION_PROPERTY = "echo.events.includeFullExecution"
public static final String IGNORE_TASK_EVENTS_PROPERTY = "echo.events.ignoreTaskEvents"
private final EchoService echoService
private final ContextParameterProcessor contextParameterProcessor
private final DynamicConfigService dynamicConfigService
Expand All @@ -56,7 +57,9 @@ class EchoNotifyingStageListener implements StageListener {

@Override
void beforeTask(StageExecution stage, TaskExecution task) {
recordEvent('task', 'starting', stage, task)
if (!dynamicConfigService.getConfig(Boolean, IGNORE_TASK_EVENTS_PROPERTY, false)) {
recordEvent('task', 'starting', stage, task)
}
}

@Override
Expand All @@ -69,7 +72,7 @@ class EchoNotifyingStageListener implements StageListener {
void afterTask(StageExecution stage,
TaskExecution task) {
ExecutionStatus status = task.getStatus()
if (status == RUNNING) {
if (dynamicConfigService.getConfig(Boolean, IGNORE_TASK_EVENTS_PROPERTY, false) || status == RUNNING) {
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ package com.netflix.spinnaker.orca.echo.spring

import com.netflix.spinnaker.kork.dynamicconfig.DynamicConfigService
import com.netflix.spinnaker.orca.echo.EchoService
import com.netflix.spinnaker.orca.listeners.Persister
import com.netflix.spinnaker.orca.pipeline.model.PipelineExecutionImpl
import com.netflix.spinnaker.orca.pipeline.model.StageExecutionImpl
import com.netflix.spinnaker.orca.pipeline.model.TaskExecutionImpl
import com.netflix.spinnaker.orca.pipeline.persistence.ExecutionRepository
import com.netflix.spinnaker.orca.pipeline.util.ContextParameterProcessor
import spock.lang.Shared
import spock.lang.Specification
import spock.lang.Subject
import spock.lang.Unroll
import static com.netflix.spinnaker.orca.api.pipeline.models.ExecutionStatus.*
import static com.netflix.spinnaker.orca.echo.spring.EchoNotifyingStageListener.INCLUDE_FULL_EXECUTION_PROPERTY
import static com.netflix.spinnaker.orca.echo.spring.EchoNotifyingStageListener.IGNORE_TASK_EVENTS_PROPERTY


class EchoNotifyingStageListenerSpec extends Specification {

Expand All @@ -30,6 +30,7 @@ class EchoNotifyingStageListenerSpec extends Specification {
@Shared
def orchestrationStage = new StageExecutionImpl(PipelineExecutionImpl.newOrchestration("orca"), "test")

@Unroll
def "triggers an event when a task step starts"() {
given:
def task = new TaskExecutionImpl(status: NOT_STARTED)
Expand All @@ -38,7 +39,12 @@ class EchoNotifyingStageListenerSpec extends Specification {
echoListener.beforeTask(pipelineStage, task)

then:
1 * echoService.recordEvent({ event -> event.details.type == "orca:task:starting" })
1 * dynamicConfigService.getConfig(Boolean, IGNORE_TASK_EVENTS_PROPERTY, false) >> ignoreTaskEvents
if (!ignoreTaskEvents) 1 * echoService.recordEvent({ event -> event.details.type == "orca:task:starting" })
else 0 * echoService.recordEvent(_)

where:
ignoreTaskEvents << [true, false]
}

def "triggers an event when a stage starts"() {
Expand All @@ -49,20 +55,25 @@ class EchoNotifyingStageListenerSpec extends Specification {
1 * echoService.recordEvent({ event -> event.details.type == "orca:stage:starting" })
}

@Unroll
def "triggers an event when a task starts"() {
given:
def task = new TaskExecutionImpl(stageStart: false)

and:
def events = []
echoService.recordEvent(_) >> { events << it[0]; null }

when:
echoListener.beforeTask(pipelineStage, task)

then:
events.size() == 1
events.details.type == ["orca:task:starting"]
1 * dynamicConfigService.getConfig(Boolean, IGNORE_TASK_EVENTS_PROPERTY, false) >> ignoreTaskEvents
if (!ignoreTaskEvents) {
def events = []
1 * echoService.recordEvent(_) >> { events << it[0]; null }
events.size() == 1
events.details.type == ["orca:task:starting"]
} else 0 * echoService.recordEvent(_)

where:
ignoreTaskEvents << [true, false]
}

@Unroll
Expand All @@ -75,17 +86,25 @@ class EchoNotifyingStageListenerSpec extends Specification {
echoListener.afterTask(stage, task)

then:
1 * dynamicConfigService.getConfig(Boolean, IGNORE_TASK_EVENTS_PROPERTY, false) >> ignoreTaskEvents
invocations * echoService.recordEvent(_)

where:
invocations | stage | executionStatus | isEnd
0 | orchestrationStage | RUNNING | false
1 | orchestrationStage | STOPPED | false
1 | orchestrationStage | SUCCEEDED | false
1 | pipelineStage | SUCCEEDED | false
1 | pipelineStage | SUCCEEDED | true
1 | pipelineStage | TERMINAL | false
1 | orchestrationStage | SUCCEEDED | true
invocations | stage | executionStatus | isEnd | ignoreTaskEvents
0 | orchestrationStage | RUNNING | false | false
1 | orchestrationStage | STOPPED | false | false
1 | orchestrationStage | SUCCEEDED | false | false
1 | pipelineStage | SUCCEEDED | false | false
1 | pipelineStage | SUCCEEDED | true | false
1 | pipelineStage | TERMINAL | false | false
1 | orchestrationStage | SUCCEEDED | true | false
0 | orchestrationStage | RUNNING | false | true
0 | orchestrationStage | STOPPED | false | true
0 | orchestrationStage | SUCCEEDED | false | true
0 | pipelineStage | SUCCEEDED | false | true
0 | pipelineStage | SUCCEEDED | true | true
0 | pipelineStage | TERMINAL | false | true
0 | orchestrationStage | SUCCEEDED | true | true

taskName = "xxx"
}
Expand Down Expand Up @@ -121,6 +140,7 @@ class EchoNotifyingStageListenerSpec extends Specification {
echoListener.afterTask(stage, task)

then:
1 * dynamicConfigService.getConfig(Boolean, IGNORE_TASK_EVENTS_PROPERTY, false) >> false
1 * dynamicConfigService.getConfig(Boolean, INCLUDE_FULL_EXECUTION_PROPERTY, _) >> fullExecutionToggle
message.details.source == "orca"
message.details.application == pipelineStage.execution.application
Expand Down

0 comments on commit 3b913b8

Please sign in to comment.